]> git.sesse.net Git - vlc/commitdiff
* x11/x11_timer.* : classes to implement platform-independant timers
authorCyril Deguet <asmax@videolan.org>
Thu, 5 Jun 2003 22:16:15 +0000 (22:16 +0000)
committerCyril Deguet <asmax@videolan.org>
Thu, 5 Jun 2003 22:16:15 +0000 (22:16 +0000)
* controls/text.cpp : text scrolling works ! (at least in the main window)

modules/gui/skins/Modules.am
modules/gui/skins/controls/text.cpp
modules/gui/skins/x11/x11_run.cpp
modules/gui/skins/x11/x11_timer.cpp [new file with mode: 0644]
modules/gui/skins/x11/x11_timer.h [new file with mode: 0644]

index 6faba4158dce3c437ed81aa49392c6e5131c2320..2b784a3152898320af22896e59f127ae648ea1e2 100644 (file)
@@ -106,6 +106,8 @@ COMMON_skins = \
        modules/gui/skins/x11/x11_run.cpp \
        modules/gui/skins/x11/x11_theme.cpp \
        modules/gui/skins/x11/x11_theme.h \
+       modules/gui/skins/x11/x11_timer.cpp \
+       modules/gui/skins/x11/x11_timer.h \
        modules/gui/skins/x11/x11_window.cpp \
        modules/gui/skins/x11/x11_window.h
 
index 16e71313827f79c8ff8e6f36c982cf76cf450128..676975e72c1fc52debaeb4b2d80e4ebb192abc28 100644 (file)
@@ -2,10 +2,11 @@
  * text.cpp: Text control
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: text.cpp,v 1.9 2003/04/28 14:12:32 asmax Exp $
+ * $Id: text.cpp,v 1.10 2003/06/05 22:16:15 asmax Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
+ *          Cyril Deguet     <asmax@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include "../os_window.h"
 #include "../src/skin_common.h"
 
+#ifdef X11_SKINS
+#include "../x11/x11_timer.h"
+extern intf_thread_t *g_pIntf;
+#endif
+
 
 
 //---------------------------------------------------------------------------
 
     //-----------------------------------------------------------------------
     // X11 methods
-    //-----------------------------------------------------------------------
+    //----------------------------------------------------------------------- 
+    void ScrollingTextTimer( void *data )
+    { 
+        if( (ControlText *)data != NULL
+            && !( (ControlText *)data )->GetSelected() )
+        {
+            ( (ControlText *)data )->DoScroll();
+        }
+    }
+
     //-----------------------------------------------------------------------
     void ControlText::StartScrolling()
     {
+        X11Timer *timer = new X11Timer( g_pIntf, 100000, ScrollingTextTimer, 
+                                        (void*)this );
+        X11TimerManager *timerManager = X11TimerManager::Instance( g_pIntf );
+        timerManager->addTimer( timer );
     }
     //-----------------------------------------------------------------------
     void ControlText::StopScrolling()
index 8a1c9097f80dd144db8de3e5604b1d31d35c7ee4..c92565245b76ee8ae46e14dfc547b8818a281dbf 100644 (file)
@@ -2,7 +2,7 @@
  * x11_run.cpp:
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: x11_run.cpp,v 1.14 2003/06/03 22:18:58 gbazin Exp $
+ * $Id: x11_run.cpp,v 1.15 2003/06/05 22:16:15 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@videolan.org>
  *
@@ -41,6 +41,8 @@
 #include "../os_theme.h"
 #include "../src/skin_common.h"
 #include "../src/vlcproc.h"
+#include "x11_timer.h"
+
 
 //---------------------------------------------------------------------------
 // Specific method
@@ -151,6 +153,13 @@ int ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
     return 0;
 }
 
+
+void RefreshCallback( void *data )
+{
+    SkinManage( (intf_thread_t*)data );
+}
+
+
 //---------------------------------------------------------------------------
 // X11 interface
 //---------------------------------------------------------------------------
@@ -160,9 +169,15 @@ void OSRun( intf_thread_t *p_intf )
 
     Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
 
+
+    // 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
     int close = 0;
-    int count = 0;
     while( !close )
     {
         XEvent event;
@@ -180,14 +195,12 @@ void OSRun( intf_thread_t *p_intf )
             nPending = XPending( display );
             XUNLOCK;
         }
-        
         msleep( 1000 );
-        if( ++count == 100 )
-        {
-            count = 0;
-            SkinManage( p_intf );    // Call every 100 ms
-        }
     }
+
+    timerManager->Destroy();
+    delete refreshTimer;
+    
 }
 //---------------------------------------------------------------------------
 bool IsVLCEvent( unsigned int msg )
diff --git a/modules/gui/skins/x11/x11_timer.cpp b/modules/gui/skins/x11/x11_timer.cpp
new file mode 100644 (file)
index 0000000..71e7461
--- /dev/null
@@ -0,0 +1,129 @@
+/*****************************************************************************
+ * x11_timer.cpp: helper class to implement timers
+ *****************************************************************************
+ * Copyright (C) 2003 VideoLAN
+ * $Id: x11_timer.cpp,v 1.1 2003/06/05 22:16:15 asmax Exp $
+ *
+ * Authors: Cyril Deguet     <asmax@videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
+ * USA.
+ *****************************************************************************/
+
+#ifdef X11_SKINS
+
+//--- VLC -------------------------------------------------------------------
+#include <vlc/intf.h>
+#include <mtime.h>
+
+//--- SKIN ------------------------------------------------------------------
+#include "x11_timer.h"
+
+
+//---------------------------------------------------------------------------
+
+X11Timer::X11Timer( intf_thread_t *p_intf, mtime_t interval, callback_t func,
+                    void *data )
+{
+    _p_intf = p_intf;
+    _interval = interval;
+    _callback = func;
+    _data = data;
+}
+
+
+X11Timer::~X11Timer()
+{
+}
+
+
+mtime_t X11Timer::getNextDate( mtime_t current )
+{
+    return (current / _interval + 1) * _interval;
+}
+
+
+void X11Timer::Execute()
+{
+    (*_callback)( _data );
+}
+
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+
+X11TimerManager *X11TimerManager::_instance = NULL;
+
+
+X11TimerManager::X11TimerManager( intf_thread_t *p_intf )
+{
+    _p_intf = p_intf;
+    
+    // Create the timer thread
+    _p_timer = (timer_thread_t*)vlc_object_create( _p_intf,
+                                                   sizeof( timer_thread_t ) );
+    _p_timer->die = 0;
+}
+
+
+X11TimerManager::~X11TimerManager()
+{
+    _p_timer->die = 1;
+    vlc_thread_join( _p_timer );
+}
+
+
+// Return the instance of X11TimerManager (design pattern singleton)
+X11TimerManager *X11TimerManager::Instance( intf_thread_t *p_intf )
+{
+    if( _instance == NULL )
+    {
+        _instance = new X11TimerManager( p_intf );
+        // Run the timer thread
+        vlc_thread_create( _instance->_p_timer, "Skins timer thread", 
+                           &Thread, 0, VLC_TRUE );
+    }
+    return _instance;
+}
+
+
+// Destroy the instance, if any
+void X11TimerManager::Destroy()
+{
+    if( _instance != NULL )
+    {
+        delete _instance;
+    }
+}
+
+// Main timer loop
+void *X11TimerManager::Thread( void *p_timer )
+{
+    vlc_thread_ready( (vlc_object_t*) p_timer );
+    while( !((timer_thread_t*)p_timer)->die )
+    {
+        list<X11Timer*>::iterator timer;
+        // FIXME temporary
+        for( timer = _instance->_timers.begin(); 
+             timer != _instance->_timers.end(); timer++ )
+        {
+            (*timer)->Execute();
+        }
+        msleep( 100000 );
+    }
+    
+}
+
+#endif
diff --git a/modules/gui/skins/x11/x11_timer.h b/modules/gui/skins/x11/x11_timer.h
new file mode 100644 (file)
index 0000000..788a905
--- /dev/null
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * x11_timer.h: helper class to implement timers
+ *****************************************************************************
+ * Copyright (C) 2003 VideoLAN
+ * $Id: x11_timer.h,v 1.1 2003/06/05 22:16:15 asmax Exp $
+ *
+ * Authors: Cyril Deguet     <asmax@videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
+ * USA.
+ *****************************************************************************/
+
+
+#ifndef VLC_SKIN_X11_TIMER
+#define VLC_SKIN_X11_TIMER
+
+#include <list.h>
+
+typedef struct
+{
+    VLC_COMMON_MEMBERS
+    int die;
+} timer_thread_t;
+
+class X11Timer;  // forward declaration
+
+typedef void(*callback_t)( void* );
+
+//---------------------------------------------------------------------------
+class X11Timer
+{
+    private:
+        intf_thread_t *_p_intf;
+        mtime_t _interval;       
+        callback_t _callback;
+        void *_data;
+
+    public:
+        X11Timer( intf_thread_t *p_intf, mtime_t interval, callback_t func, 
+                  void *data );
+        ~X11Timer();
+
+        mtime_t getNextDate( mtime_t current );
+        void Execute();
+};
+//---------------------------------------------------------------------------
+class X11TimerManager
+{
+    private:
+        static X11TimerManager *_instance;
+        intf_thread_t *_p_intf;
+        timer_thread_t *_p_timer;
+        list<X11Timer*> _timers;
+        
+        X11TimerManager( intf_thread_t *p_intf );
+        ~X11TimerManager();
+
+        static void *Thread( void *p_timer );
+
+    public:
+        static X11TimerManager *Instance( intf_thread_t *p_intf );
+        void Destroy();
+
+        void addTimer( X11Timer *timer ) { _timers.push_back( timer ); }
+
+};
+//---------------------------------------------------------------------------
+#endif