]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins/x11/x11_run.cpp
* modules/gui/skins/win32/win32_run.cpp: don't forget to delete VlcProc
[vlc] / modules / gui / skins / x11 / x11_run.cpp
index 0711387aec7bb3be892e50e44cc149866bb6f356..13e7ae46de63b5b9e78c702b3869933d8aaa4a11 100644 (file)
@@ -2,7 +2,7 @@
  * x11_run.cpp:
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: x11_run.cpp,v 1.4 2003/05/18 11:25:00 asmax Exp $
+ * $Id: x11_run.cpp,v 1.24 2003/07/25 22:50:12 gbazin Exp $
  *
  * Authors: Cyril Deguet     <asmax@videolan.org>
  *
 //--- X11 -------------------------------------------------------------------
 #include <X11/Xlib.h>
 
-//--- WWWINDOWS -------------------------------------------------------------
-#ifndef BASIC_SKINS
-#include <wx/wx.h>
-#endif
-
 //--- VLC -------------------------------------------------------------------
 #include <vlc/intf.h>
 
 #include "../os_theme.h"
 #include "../src/skin_common.h"
 #include "../src/vlcproc.h"
-#ifndef BASIC_SKINS
-#include "../../wxwindows/wxwindows.h"
-#endif
-
-// include the icon graphic
-#include "share/vlc32x32.xpm"
+#include "x11_timer.h"
 
 
 //---------------------------------------------------------------------------
 bool IsVLCEvent( unsigned int msg );
 int  SkinManage( intf_thread_t *p_intf );
 
-
-//---------------------------------------------------------------------------
-// Local classes declarations.
-//---------------------------------------------------------------------------
-#ifndef BASIC_SKINS
-class Instance: public wxApp
-{
-public:
-    Instance();
-    Instance( intf_thread_t *_p_intf );
-
-    bool OnInit();
-    OpenDialog *open;
-
-private:
-    intf_thread_t *p_intf;
-};
-#endif
-
-
-//---------------------------------------------------------------------------
-// GTK2 interface
-//---------------------------------------------------------------------------
-/*void GTK2Proc( GdkEvent *event, gpointer data )
-{
-    // Get objects from data
-    CallBackObjects *obj = (CallBackObjects *)data;
-    VlcProc *proc        = obj->Proc;
-
-    // Get pointer to thread info
-    intf_thread_t *p_intf = proc->GetpIntf();
-
-    // Variables
-    unsigned int msg;
-    Event *evt;
-    list<SkinWindow *>::const_iterator win;
-    GdkWindow *gwnd = ((GdkEventAny *)event)->window;
-
-    // Create event to dispatch in windows
-    // Skin event
-    if( event->type == GDK_CLIENT_EVENT )
-    {
-        msg = ( (GdkEventClient *)event )->data.l[0];
-        evt = (Event *)new OSEvent( p_intf, 
-            ((GdkEventAny *)event)->window,
-            msg,
-            ( (GdkEventClient *)event )->data.l[1],
-            ( (GdkEventClient *)event )->data.l[2] );
-    }
-    // System event
-    else
-    {
-        msg = event->type;
-        evt = (Event *)new OSEvent( p_intf,
-            ((GdkEventAny *)event)->window, msg, 0, (long)event );
-    }
-
-    // Process keyboard shortcuts
-    if( msg == GDK_KEY_PRESS )
-    {
-        int KeyModifier = 0;
-        // If key is ALT
-        if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
-        {
-            KeyModifier = 1;
-        }
-        // If key is CTRL
-        else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
-        {
-            KeyModifier = 2;
-        }
-        int key = ((GdkEventKey *)event)->keyval;
-        // Translate into lower case
-        if( key >= 'a' && key <= 'z' )
-        {
-            key -= ('a' - 'A');
-        }
-        if( KeyModifier > 0 )
-            p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );
-    }
-
-    // Send event
-    else if( IsVLCEvent( msg ) )
-    {
-        if( !proc->EventProc( evt ) )
-        {
-            wxExit();
-            return;      // Exit VLC !
-        }
-    }
-    else if( gwnd == NULL )
-    {
-        for( win = p_intf->p_sys->p_theme->WindowList.begin();
-             win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
-        {
-            (*win)->ProcessEvent( evt );
-        }
-    }
-    else
-    {
-        // Find window matching with gwnd
-        for( win = p_intf->p_sys->p_theme->WindowList.begin();
-             win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
-        {
-            // If it is the correct window
-            if( gwnd == ( (GTK2Window *)(*win) )->GetHandle() )
-            {
-                // Send event and check if processed
-                if( (*win)->ProcessEvent( evt ) )
-                {
-                    delete (OSEvent *)evt;
-                    return;
-                }
-                else
-                {
-                    break;
-                }
-            }
-        }
-    }
-
-    evt->DestructParameters();
-    delete (OSEvent *)evt;
-
-    // Check if vlc is closing
-    proc->IsClosing();
-
-    gtk_main_do_event( event )
-}*/
-//---------------------------------------------------------------------------
-
-//---------------------------------------------------------------------------
-// REFRESH TIMER CALLBACK
-//---------------------------------------------------------------------------
-/*gboolean RefreshTimer( gpointer data )
-{
-    intf_thread_t *p_intf = (intf_thread_t *)data;
-    SkinManage( p_intf );
-    return true;
-}*/
-//---------------------------------------------------------------------------
-
-
-//---------------------------------------------------------------------------
-// Implementation of Instance class
-//---------------------------------------------------------------------------
-#ifndef BASIC_SKINS
-Instance::Instance( )
-{
-}
-
-Instance::Instance( intf_thread_t *_p_intf )
-{
-    // Initialization
-    p_intf = _p_intf;
-}
-
-IMPLEMENT_APP_NO_MAIN(Instance)
-
-bool Instance::OnInit()
-{
-    // Set event callback. Yes, it's a big hack ;)
-//    gdk_event_handler_set( GTK2Proc, (gpointer)callbackobj, NULL );
-
-    p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
-    p_intf->p_sys->OpenDlg = new OpenDialog( p_intf, NULL, FILE_ACCESS );
-    p_intf->p_sys->MessagesDlg = new Messages( p_intf, NULL );
-    p_intf->p_sys->SoutDlg = new SoutDialog( p_intf, NULL );
-    p_intf->p_sys->PrefsDlg = new PrefsDialog( p_intf, NULL );
-    p_intf->p_sys->InfoDlg = new FileInfo( p_intf, NULL );
-    
-    // Add timer
-//    g_timeout_add( 200, (GSourceFunc)RefreshTimer, (gpointer)p_intf );
-
-    return TRUE;
-}
-#endif
-
-
 //---------------------------------------------------------------------------
 // X11 event processing
 //---------------------------------------------------------------------------
-void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
+int ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
 {
     // Variables
     list<SkinWindow *>::const_iterator win;
@@ -251,18 +62,16 @@ void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
 
     Window wnd = ((XAnyEvent *)event)->window;
     
-//    fprintf(stderr,"event %d %x\n", event->type, wnd);
-
     // Create event to dispatch in windows
     // Skin event
-    if( event->type == ClientMessage )
+    if( event->type == ClientMessage && 
+        ((XClientMessageEvent*)event)->message_type == 0 )
     {
-/*        msg = ( (GdkEventClient *)event )->data.l[0];
+        msg = ( (XClientMessageEvent *)event )->data.l[0];
         evt = (Event *)new OSEvent( p_intf, 
-            ((GdkEventAny *)event)->window,
-            msg,
-            ( (GdkEventClient *)event )->data.l[1],
-            ( (GdkEventClient *)event )->data.l[2] );*/
+            ((XAnyEvent *)event)->window, msg,
+            ( (XClientMessageEvent *)event )->data.l[1],
+            ( (XClientMessageEvent *)event )->data.l[2] );
     }
     // System event
     else
@@ -275,25 +84,21 @@ void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
     // Process keyboard shortcuts
     if( msg == KeyPress )
     {
-/*        int KeyModifier = 0;
+        int KeyModifier = 0;
         // If key is ALT
-        if( ((GdkEventKey *)event)->state & GDK_MOD1_MASK )
+        if( ((XKeyEvent *)event)->state & Mod1Mask )
         {
             KeyModifier = 1;
         }
         // If key is CTRL
-        else if( ((GdkEventKey *)event)->state & GDK_CONTROL_MASK )
+        else if( ((XKeyEvent *)event)->state & ControlMask )
         {
             KeyModifier = 2;
         }
-        int key = ((GdkEventKey *)event)->keyval;
-        // Translate into lower case
-        if( key >= 'a' && key <= 'z' )
-        {
-            key -= ('a' - 'A');
-        }
+        // Take the second keysym = upper case character
+        int key = XLookupKeysym( (XKeyEvent *)event, 1 );
         if( KeyModifier > 0 )
-            p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );*/
+            p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );
     }
 
     // Send event
@@ -301,12 +106,13 @@ void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
     {
         if( !proc->EventProc( evt ) )
         {
-//            wxExit();
-            return;      // Exit VLC !
+            delete (OSEvent *)evt;
+            return 1;      // Exit VLC !
         }
     }
-    else if( wnd == NULL )
+    else if( wnd == p_intf->p_sys->mainWin )
     {
+        // Broadcast event
         for( win = p_intf->p_sys->p_theme->WindowList.begin();
              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
         {
@@ -326,7 +132,7 @@ void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
                 if( (*win)->ProcessEvent( evt ) )
                 {
                     delete (OSEvent *)evt;
-                    return;
+                    return 0;
                 }
                 else
                 {
@@ -339,9 +145,17 @@ void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
     evt->DestructParameters();
     delete (OSEvent *)evt;
 
-// Check if vlc is closing
+    // Check if vlc is closing
     proc->IsClosing();
+    
+    return 0;
+}
+
 
+bool RefreshCallback( void *data )
+{
+    SkinManage( (intf_thread_t*)data );
+    return True;
 }
 
 
@@ -350,27 +164,43 @@ void ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
 //---------------------------------------------------------------------------
 void OSRun( intf_thread_t *p_intf )
 {
-    static char  *p_args[] = { "" };
-
     VlcProc *proc = new VlcProc( p_intf );
-    
-/*    wxTheApp = new Instance( p_intf, callbackobj );
-    wxEntry( 1, p_args );*/
 
     Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
-    
+
+    X11TimerManager::Initialize();
+
+    // Timer for SkinManage
+    X11Timer *refreshTimer = new X11Timer( p_intf, 100000, RefreshCallback,
+                                           (void*)p_intf );
+    X11TimerManager *timerManager = X11TimerManager::Instance( p_intf );
+    timerManager->addTimer( refreshTimer );
+
     // Main event loop
-    while( 1 )
+    int close = 0;
+    while( !close )
     {
-        XEvent *event;
-        XNextEvent( display, event );
-        
-        ProcessEvent( p_intf, proc, event );
-
-// kludge: add timer
-        SkinManage( p_intf );
+        XEvent event;
+        int nPending;
+        XLOCK;
+        nPending = XPending( display );
+        XUNLOCK;
+        while( !close && nPending > 0 )
+        {
+            XLOCK;
+            XNextEvent( display, &event );
+            XUNLOCK;
+            close = ProcessEvent( p_intf, proc, &event );
+            XLOCK;
+            nPending = XPending( display );
+            XUNLOCK;
+        }
+        msleep( 1000 );
     }
-    
+
+    timerManager->Destroy();
+    delete refreshTimer;
+    delete proc;
 }
 //---------------------------------------------------------------------------
 bool IsVLCEvent( unsigned int msg )