[vlc-devel] Qt5 for X11

Francois Cartegnie fcvlcdev at free.fr
Fri Apr 4 15:51:23 CEST 2014


Le 11/03/2014 23:00, Felix Paul Kühne a écrit :

>> - OSX (who's still working on it?)
> 
> IMO, this is not a priority these days. The native Mac UI works well and is maintained (mostly by David these days), so we don't really need to have Qt5 support on that platform.
> 

Anyone tried to fix X11 VideoWidget ?

As Q_WS_X11 is no longer defined, neither QX11Info, the widget window id
is no longer grabbed.

As Qt now abstracts an XCB backend, it only provides a "native"
interface to access native resources.

I've tried to map our xlib calls back:

- On the XSync part, something seems wrong with the returned display,
and then segfaults.

- On the window events, unsure what's wrong, either a different Id or a
QApplication still registered for events. (explaints the
nativeeventfilter interface).


Francois


>From 020eb2a9e5df024ace312c8f90f480443f997871 Mon Sep 17 00:00:00 2001
From: Francois Cartegnie <fcvlcdev at free.fr>
Date: Fri, 4 Apr 2014 13:41:31 +0200
Subject: [PATCH] x11qt5

---
 doc/libvlc/QtPlayer/main.cpp                     |  4 +--
 modules/gui/qt4/components/interface_widgets.cpp | 40
+++++++++++++++++++-----
 modules/gui/qt4/qt4.cpp                          |  8 ++---
 modules/gui/qt4/qt4.hpp                          |  4 +++
 4 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/doc/libvlc/QtPlayer/main.cpp b/doc/libvlc/QtPlayer/main.cpp
index 4ebf3f9..a519bcb 100644
--- a/doc/libvlc/QtPlayer/main.cpp
+++ b/doc/libvlc/QtPlayer/main.cpp
@@ -8,12 +8,12 @@
 #include <QApplication>
 #include "player.h"

-#ifdef Q_WS_X11
+#ifdef HAVE_X11_XLIB_H
     #include <X11/Xlib.h>
 #endif

 int main(int argc, char *argv[]) {
-#ifdef Q_WS_X11
+#ifdef HAVE_X11_XLIB_H
     XInitThreads();
 #endif

diff --git a/modules/gui/qt4/components/interface_widgets.cpp
b/modules/gui/qt4/components/interface_widgets.cpp
index 263c72d..ed4e2b9 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -52,9 +52,19 @@
 #include <QBitmap>
 #include <QUrl>

-#ifdef Q_WS_X11
-#   include <X11/Xlib.h>
-#   include <qx11info_x11.h>
+#if QT_VERSION >= 0x050000
+#include <QGuiApplication>
+#include <QtGui/QPlatformNativeInterface>
+#include <QAbstractNativeEventFilter>
+#endif
+
+#ifdef QT_HAS_X11
+#   if QT_VERSION < 0x050000
+#       include <X11/Xlib.h>
+#       include <qx11info_x11.h>
+#    else
+#       include <X11/Xlib-xcb.h>
+#   endif
 #endif

 #include <math.h>
@@ -85,11 +95,18 @@ VideoWidget::~VideoWidget()

 void VideoWidget::sync( void )
 {
-#ifdef Q_WS_X11
+#ifdef QT_HAS_X11
     /* Make sure the X server has processed all requests.
      * This protects other threads using distinct connections from getting
      * the video widget window in an inconsistent states. */
-    XSync( QX11Info::display(), False );
+    Display *display;
+#if QT_VERSION < 0x050000
+    display = QX11Info::display();
+#else
+    QPlatformNativeInterface *native =
QGuiApplication::platformNativeInterface();
+    display =
static_cast<Display*>(native->nativeResourceForWidget(QByteArray("display"),
this));
+#endif
+    XSync( display, False );
 #endif
 }

@@ -128,23 +145,32 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
        management */
     /* This is currently disabled on X11 as it does not seem to improve
      * performance, but causes the video widget to be transparent... */
-#if !defined (Q_WS_X11) && !defined (Q_WS_QPA)
+#if !defined (QT_HAS_X11) && !defined (Q_WS_QPA)
     stable->setAttribute( Qt::WA_PaintOnScreen, true );
 #endif

     layout->addWidget( stable );

-#ifdef Q_WS_X11
+#ifdef QT_HAS_X11
     /* HACK: Only one X11 client can subscribe to mouse button press
events.
      * VLC currently handles those in the video display.
      * Force Qt4 to unsubscribe from mouse press and release events. */
+#if QT_VERSION < 0x050000
     Display *dpy = QX11Info::display();
+
     Window w = stable->winId();
     XWindowAttributes attr;

     XGetWindowAttributes( dpy, w, &attr );
     attr.your_event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
     XSelectInput( dpy, w, attr.your_event_mask );
+#else
+    QPlatformNativeInterface *native =
QGuiApplication::platformNativeInterface();
+    xcb_connection_t *xcb_conn =
static_cast<xcb_connection_t*>(native->nativeResourceForWidget(QByteArray("connection"),
this));
+    const uint32_t mask_values[] = { XCB_EVENT_MASK_BUTTON_PRESS |
XCB_EVENT_MASK_BUTTON_RELEASE };
+    xcb_change_window_attributes( xcb_conn, stable->winId(),
XCB_CW_EVENT_MASK, mask_values );
+#endif
+
 #endif
     sync();
     return stable->winId();
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index b27bb81..ef5a048 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -42,7 +42,7 @@
 #include "util/qvlcapp.hpp"     /* QVLCApplication definition */
 #include "components/playlist/playlist_model.hpp" /* for ~PLModel() */

-#ifdef Q_WS_X11
+#ifdef QT_HAS_X11
  #include <vlc_xlib.h>
 #endif

@@ -298,7 +298,7 @@ vlc_module_begin ()

         set_callbacks( OpenDialogs, Close )

-#if defined (Q_WS_X11) || (defined (Q_WS_QPA) && defined (__unix__))
+#if defined (QT_HAS_X11) || (defined (Q_WS_QPA) && defined (__unix__))
     add_submodule ()
         set_capability( "vout window xid", 0 )
         set_callbacks( WindowOpen, WindowClose )
@@ -352,7 +352,7 @@ static int Open( vlc_object_t *p_this, bool
isDialogProvider )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;

-#ifdef Q_WS_X11
+#ifdef QT_HAS_X11
     if( !vlc_xlib_init( p_this ) )
         return VLC_EGENERIC;

@@ -530,7 +530,7 @@ static void *Thread( void *obj )
         p_intf->p_sys->voutWindowType = VOUT_WINDOW_TYPE_XID;
     else
         msg_Err( p_intf, "unknown Qt platform: %s", qtu(platform) );
-#elif defined (Q_WS_X11)
+#elif defined (QT_HAS_X11)
     p_intf->p_sys->voutWindowType = VOUT_WINDOW_TYPE_XID;
 #elif defined (Q_WS_WIN) || defined (Q_WS_PM)
     p_intf->p_sys->voutWindowType = VOUT_WINDOW_TYPE_HWND;
diff --git a/modules/gui/qt4/qt4.hpp b/modules/gui/qt4/qt4.hpp
index 5b27768..e6faa0b 100644
--- a/modules/gui/qt4/qt4.hpp
+++ b/modules/gui/qt4/qt4.hpp
@@ -42,6 +42,10 @@

 #define HAS_QT47 ( QT_VERSION >= 0x040700 )

+#if defined(Q_WS_X11) || (QT_VERSION >= 0x050000 &&
defined(HAVE_X11_XLIB_H))
+ #define QT_HAS_X11
+#endif
+
 enum {
     DialogEventTypeOffset = 0,
     IMEventTypeOffset     = 100,
-- 
1.9.0





More information about the vlc-devel mailing list