[vlc-devel] [PATCH] qt: Use native events to notify of a video widget resize

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Apr 27 15:59:28 CEST 2017


This method can't be used for Wayland as Qt won't invoke
QWidget::nativeEvent when Wayland is used.
Fix #18211
---
 modules/gui/qt/Makefile.am                      |  3 +++
 modules/gui/qt/components/interface_widgets.cpp | 28 +++++++++++++++++++++++++
 modules/gui/qt/components/interface_widgets.hpp | 10 +++++++++
 3 files changed, 41 insertions(+)

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index a5a428d36c..22e2b54697 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -25,6 +25,9 @@ if HAVE_QT5_X11
 libqt_plugin_la_CXXFLAGS += $(QT5_X11_CFLAGS) -DQT5_HAS_X11
 libqt_plugin_la_LIBADD += $(QT5_X11_LIBS) $(X_LIBS) $(X_PRE_LIB) -lX11
 endif
+if HAVE_XCB
+libqt_plugin_la_CXXFLAGS += -DQT5_HAS_XCB
+endif
 if HAVE_WAYLAND
 libqt_plugin_la_CPPFLAGS += -DQT5_HAS_WAYLAND \
 	-DQPNI_HEADER=\<$(QT_VERSION)/QtGui/qpa/qplatformnativeinterface.h\>
diff --git a/modules/gui/qt/components/interface_widgets.cpp b/modules/gui/qt/components/interface_widgets.cpp
index 081985dc2c..a8f996eb94 100644
--- a/modules/gui/qt/components/interface_widgets.cpp
+++ b/modules/gui/qt/components/interface_widgets.cpp
@@ -53,6 +53,9 @@
 #if defined (QT5_HAS_X11)
 # include <X11/Xlib.h>
 # include <QX11Info>
+# if defined(QT5_HAS_XCB)
+#  include <xcb/xproto.h>
+# endif
 #endif
 #ifdef QT5_HAS_WAYLAND
 # include QPNI_HEADER
@@ -257,12 +260,37 @@ void VideoWidget::setSize( unsigned int w, unsigned int h )
     sync();
 }
 
+#if RESIZE_FROM_NATIVE_EVENTS
+bool VideoWidget::nativeEvent( const QByteArray& eventType, void* message, long* )
+{
+#if defined(QT5_HAS_XCB)
+    if ( eventType == "xcb_generic_event_t" )
+    {
+        const xcb_generic_event_t* xev = reinterpret_cast<const xcb_generic_event_t*>( message );
+
+        if ( xev->response_type == XCB_CONFIGURE_NOTIFY )
+            reportSize();
+    }
+#endif
+#ifdef _WIN32
+    if ( eventType == "windows_generic_MSG" )
+    {
+        MSG* msg = static_cast<MSG*>( message );
+        if ( msg->message == WM_SIZE )
+            reportSize();
+    }
+#endif
+    // Let Qt handle that event in any case
+    return false;
+}
+#else
 void VideoWidget::resizeEvent( QResizeEvent *event )
 {
     QWidget::resizeEvent( event );
 
     reportSize();
 }
+#endif
 
 int VideoWidget::qtMouseButton2VLC( Qt::MouseButton qtButton )
 {
diff --git a/modules/gui/qt/components/interface_widgets.hpp b/modules/gui/qt/components/interface_widgets.hpp
index ca2926c49c..a17a2134af 100644
--- a/modules/gui/qt/components/interface_widgets.hpp
+++ b/modules/gui/qt/components/interface_widgets.hpp
@@ -45,6 +45,12 @@
 #include <QPropertyAnimation>
 #include <QLinkedList>
 
+#if HAS_QT5
+#if defined(QT5_HAS_XCB) || defined(_WIN32)
+# define RESIZE_FROM_NATIVE_EVENTS 1
+#endif
+#endif
+
 class QMenu;
 class QSlider;
 class QWidgetAction;
@@ -69,7 +75,11 @@ protected:
         return NULL;
     }
 
+#if RESIZE_FROM_NATIVE_EVENTS
+    bool nativeEvent(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE;
+#else
     virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
+#endif
     void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
     void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
     void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
-- 
2.11.0



More information about the vlc-devel mailing list