]> git.sesse.net Git - vlc/commitdiff
Qt4: use the display we've opened
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Mon, 2 Feb 2009 21:14:52 +0000 (23:14 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Mon, 2 Feb 2009 21:14:52 +0000 (23:14 +0200)
modules/gui/qt4/qt4.cpp
modules/gui/qt4/qt4.hpp
modules/gui/qt4/util/qvlcapp.hpp

index 816076a6bfb1e64af76ef944df83299d860ae319..6c55915d7b9de360265d49bb1648f0a158d98320 100644 (file)
@@ -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;
 }
 
index a39b978c16c53f663b393f47d16e54a3dca2e898..bfd84166481191513454e20573431b13c09f0908 100644 (file)
@@ -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
index a6e8db42bbee4643883ab24d0e3adcb241178f12..b2a2ad61a55dfd2466e3bf872383b6e5d5d4b0aa 100644 (file)
 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: