[vlc-devel] commit: Qt4: use the display we've opened ( Rémi Denis-Courmont )

git version control git at videolan.org
Mon Feb 2 22:16:28 CET 2009


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Mon Feb  2 23:14:52 2009 +0200| [19e0e15f383978e93d719ce241b9199eca3b5501] | committer: Rémi Denis-Courmont 

Qt4: use the display we've opened

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=19e0e15f383978e93d719ce241b9199eca3b5501
---

 modules/gui/qt4/qt4.cpp          |   33 +++++++++++++++++++++------------
 modules/gui/qt4/qt4.hpp          |    3 +++
 modules/gui/qt4/util/qvlcapp.hpp |   10 ++++++++--
 3 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 816076a..6c55915 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -259,7 +259,7 @@ static int Open( vlc_object_t *p_this )
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
     intf_sys_t *p_sys;
 
-#if defined Q_WS_X11 && defined HAVE_X11_XLIB_H
+#ifdef Q_WS_X11
     /* Thanks for libqt4 calling exit() in QApplication::QApplication()
      * instead of returning an error, we have to check the X11 display */
     Display *p_display = XOpenDisplay( NULL );
@@ -268,7 +268,6 @@ static int Open( vlc_object_t *p_this )
         msg_Err( p_intf, "Could not connect to X server" );
         return VLC_EGENERIC;
     }
-    XCloseDisplay( p_display );
 #endif
 
     /* Allocations */
@@ -277,6 +276,9 @@ static int Open( vlc_object_t *p_this )
     p_sys->p_popup_menu = NULL; /* ??? */
     p_sys->p_playlist = pl_Hold( p_intf );
     p_sys->p_mi = NULL;
+#ifdef Q_WS_X11
+    p_sys->display = p_display;
+#endif
 
     if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
     {
@@ -318,6 +320,9 @@ static void Close( vlc_object_t *p_this )
     QApplication::quit();
 
     vlc_join (p_sys->thread, NULL);
+#ifdef Q_WS_X11
+    XCloseDisplay ((Display *)p_sys->display);
+#endif
     pl_Release (p_this);
     delete p_sys;
 }
@@ -349,8 +354,12 @@ static void *Thread( void *obj )
 #endif
 
     /* Start the QApplication here */
-    QVLCApp *app = new QVLCApp( argc, argv , true );
-    p_intf->p_sys->p_app = app;
+#ifdef Q_WS_X11
+    QVLCApp app( (Display *)p_intf->p_sys->display, argc, argv );
+#else
+    QVLCApp app( argc, argv );
+#endif
+    p_intf->p_sys->p_app = &app;
 
     p_intf->p_sys->mainSettings = new QSettings(
 #ifdef WIN32
@@ -362,16 +371,16 @@ static void *Thread( void *obj )
 
     /* Icon setting */
     if( QDate::currentDate().dayOfYear() >= 354 )
-        app->setWindowIcon( QIcon( QPixmap(vlc_christmas_xpm) ) );
+        app.setWindowIcon( QIcon( QPixmap(vlc_christmas_xpm) ) );
     else
-        app->setWindowIcon( QIcon( QPixmap(vlc_xpm) ) );
+        app.setWindowIcon( QIcon( QPixmap(vlc_xpm) ) );
 
     /* Initialize timers and the Dialog Provider */
     DialogsProvider::getInstance( p_intf );
 
     /* Detect screensize for small screens like TV or EEEpc*/
     p_intf->p_sys->i_screenHeight =
-        app->QApplication::desktop()->availableGeometry().height();
+        app.QApplication::desktop()->availableGeometry().height();
 
 #ifdef UPDATE_CHECK
     /* Checking for VLC updates */
@@ -429,11 +438,11 @@ static void *Thread( void *obj )
     bool b_loaded = qtTranslator.load( path + "qt_" + lang );
     if (!b_loaded)
         msg_Dbg( p_intf, "Error while initializing qt-specific localization" );
-    app->installTranslator( &qtTranslator );
+    app.installTranslator( &qtTranslator );
 #endif  //ENABLE_NLS
 
     /* Last settings */
-    app->setQuitOnLastWindowClosed( false );
+    app.setQuitOnLastWindowClosed( false );
 
     /* Retrieve last known path used in file browsing */
     char *psz_path = config_GetPsz( p_intf, "qt-filedialog-path" );
@@ -441,7 +450,7 @@ static void *Thread( void *obj )
                                                         : psz_path;
 
     /* Launch */
-    app->exec();
+    app.exec();
 
     /* And quit */
     msg_Dbg( p_intf, "Quitting the Qt4 Interface" );
@@ -475,12 +484,12 @@ static void *Thread( void *obj )
     /* Destroy the MainInputManager */
     MainInputManager::killInstance();
 
-    /* Delete the application */
-    delete app;
 
     /* Save the path */
     config_PutPsz( p_intf, "qt-filedialog-path", p_intf->p_sys->psz_filepath );
     free( psz_path );
+
+    /* Delete the application automatically */
     return NULL;
 }
 
diff --git a/modules/gui/qt4/qt4.hpp b/modules/gui/qt4/qt4.hpp
index a39b978..bfd8416 100644
--- a/modules/gui/qt4/qt4.hpp
+++ b/modules/gui/qt4/qt4.hpp
@@ -75,6 +75,9 @@ struct intf_sys_t
     const char *psz_filepath; /* Last path used in dialogs */
 
     QMenu * p_popup_menu;    /* The right click menu */
+#ifdef Q_WS_X11 /* WTH is this included in ALL files? :( */
+    void *display;
+#endif
 };
 
 #define THEPL p_intf->p_sys->p_playlist
diff --git a/modules/gui/qt4/util/qvlcapp.hpp b/modules/gui/qt4/util/qvlcapp.hpp
index a6e8db4..b2a2ad6 100644
--- a/modules/gui/qt4/util/qvlcapp.hpp
+++ b/modules/gui/qt4/util/qvlcapp.hpp
@@ -31,8 +31,14 @@
 class QVLCApp : public QApplication
 {
 public:
-    QVLCApp( int & argc, char ** argv, bool GUIenabled ) : QApplication( argc,
-            argv, GUIenabled ) {}
+    QVLCApp( int & argc, char ** argv ) : QApplication( argc, argv, true ) { }
+
+#if defined (Q_WS_X11)
+     QVLCApp( Display *dp, int & argc, char ** argv )
+         : QApplication( dp, argc, argv )
+     {
+     }
+#endif
 
 #if defined(Q_WS_WIN)
 protected:




More information about the vlc-devel mailing list