]> git.sesse.net Git - vlc/blob - modules/gui/skins/x11/x11_run.cpp
* repaired basic_skins
[vlc] / modules / gui / skins / x11 / x11_run.cpp
1 /*****************************************************************************
2  * x11_run.cpp:
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: x11_run.cpp,v 1.21 2003/06/09 12:33:16 asmax Exp $
6  *
7  * Authors: Cyril Deguet     <asmax@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
22  * USA.
23  *****************************************************************************/
24
25 #ifdef X11_SKINS
26
27 //--- X11 -------------------------------------------------------------------
28 #include <X11/Xlib.h>
29
30 //--- VLC -------------------------------------------------------------------
31 #include <vlc/intf.h>
32
33 //--- SKIN ------------------------------------------------------------------
34 #include "../os_api.h"
35 #include "../src/event.h"
36 #include "../os_event.h"
37 #include "../src/banks.h"
38 #include "../src/window.h"
39 #include "../os_window.h"
40 #include "../src/theme.h"
41 #include "../os_theme.h"
42 #include "../src/skin_common.h"
43 #include "../src/vlcproc.h"
44 #include "x11_timer.h"
45
46
47 //---------------------------------------------------------------------------
48 // Specific method
49 //---------------------------------------------------------------------------
50 bool IsVLCEvent( unsigned int msg );
51 int  SkinManage( intf_thread_t *p_intf );
52
53 //---------------------------------------------------------------------------
54 // X11 event processing
55 //---------------------------------------------------------------------------
56 int ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
57 {
58     // Variables
59     list<SkinWindow *>::const_iterator win;
60     unsigned int msg;
61     Event *evt;
62
63     Window wnd = ((XAnyEvent *)event)->window;
64     
65     // Create event to dispatch in windows
66     // Skin event
67     if( event->type == ClientMessage && 
68         ((XClientMessageEvent*)event)->message_type == 0 )
69     {
70         msg = ( (XClientMessageEvent *)event )->data.l[0];
71         evt = (Event *)new OSEvent( p_intf, 
72             ((XAnyEvent *)event)->window, msg,
73             ( (XClientMessageEvent *)event )->data.l[1],
74             ( (XClientMessageEvent *)event )->data.l[2] );
75     }
76     // System event
77     else
78     {
79         msg = event->type;
80         evt = (Event *)new OSEvent( p_intf,
81             ((XAnyEvent *)event)->window, msg, 0, (long)event );
82     }
83
84     // Process keyboard shortcuts
85     if( msg == KeyPress )
86     {
87         int KeyModifier = 0;
88         // If key is ALT
89         if( ((XKeyEvent *)event)->state & Mod1Mask )
90         {
91             KeyModifier = 1;
92         }
93         // If key is CTRL
94         else if( ((XKeyEvent *)event)->state & ControlMask )
95         {
96             KeyModifier = 2;
97         }
98         // Take the second keysym = upper case character
99         int key = XLookupKeysym( (XKeyEvent *)event, 1 );
100         if( KeyModifier > 0 )
101             p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );
102     }
103
104     // Send event
105     else if( IsVLCEvent( msg ) )
106     {
107         if( !proc->EventProc( evt ) )
108         {
109             delete (OSEvent *)evt;
110             return 1;      // Exit VLC !
111         }
112     }
113     else if( wnd == p_intf->p_sys->mainWin )
114     {
115         // Broadcast event
116         for( win = p_intf->p_sys->p_theme->WindowList.begin();
117              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
118         {
119             (*win)->ProcessEvent( evt );
120         }
121     }
122     else
123     {
124         // Find window matching with gwnd
125         for( win = p_intf->p_sys->p_theme->WindowList.begin();
126              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
127         {
128             // If it is the correct window
129             if( wnd == ( (X11Window *)(*win) )->GetHandle() )
130             {
131                 // Send event and check if processed
132                 if( (*win)->ProcessEvent( evt ) )
133                 {
134                     delete (OSEvent *)evt;
135                     return 0;
136                 }
137                 else
138                 {
139                     break;
140                 }
141             }
142         }
143     }
144
145     evt->DestructParameters();
146     delete (OSEvent *)evt;
147
148     // Check if vlc is closing
149     proc->IsClosing();
150     
151     return 0;
152 }
153
154
155 bool RefreshCallback( void *data )
156 {
157     SkinManage( (intf_thread_t*)data );
158     return True;
159 }
160
161
162 //---------------------------------------------------------------------------
163 // X11 interface
164 //---------------------------------------------------------------------------
165 void OSRun( intf_thread_t *p_intf )
166 {
167     VlcProc *proc = new VlcProc( p_intf );
168
169     Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
170
171
172     // Timer for SkinManage
173     X11Timer *refreshTimer = new X11Timer( p_intf, 100000, RefreshCallback,
174                                            (void*)p_intf );
175     X11TimerManager *timerManager = X11TimerManager::Instance( p_intf );
176     timerManager->addTimer( refreshTimer );
177
178     // Main event loop
179     int close = 0;
180     while( !close )
181     {
182         XEvent event;
183         int nPending;
184         XLOCK;
185         nPending = XPending( display );
186         XUNLOCK;
187         while( !close && nPending > 0 )
188         {
189             XLOCK;
190             XNextEvent( display, &event );
191             XUNLOCK;
192             close = ProcessEvent( p_intf, proc, &event );
193             XLOCK;
194             nPending = XPending( display );
195             XUNLOCK;
196         }
197         msleep( 1000 );
198     }
199
200     timerManager->Destroy();
201     delete refreshTimer;
202     delete proc;
203 }
204 //---------------------------------------------------------------------------
205 bool IsVLCEvent( unsigned int msg )
206 {
207     return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
208 }
209 //---------------------------------------------------------------------------
210
211 #endif