]> git.sesse.net Git - vlc/blob - modules/gui/skins/x11/x11_run.cpp
616d2ae2e54562063e693f8af13410cb97424f30
[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.20 2003/06/08 18:17:50 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             return 1;      // Exit VLC !
110         }
111     }
112     else if( wnd == p_intf->p_sys->mainWin )
113     {
114         // Broadcast event
115         for( win = p_intf->p_sys->p_theme->WindowList.begin();
116              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
117         {
118             (*win)->ProcessEvent( evt );
119         }
120     }
121     else
122     {
123         // Find window matching with gwnd
124         for( win = p_intf->p_sys->p_theme->WindowList.begin();
125              win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
126         {
127             // If it is the correct window
128             if( wnd == ( (X11Window *)(*win) )->GetHandle() )
129             {
130                 // Send event and check if processed
131                 if( (*win)->ProcessEvent( evt ) )
132                 {
133                     delete (OSEvent *)evt;
134                     return 0;
135                 }
136                 else
137                 {
138                     break;
139                 }
140             }
141         }
142     }
143
144     evt->DestructParameters();
145     delete (OSEvent *)evt;
146
147     // Check if vlc is closing
148     proc->IsClosing();
149     
150     return 0;
151 }
152
153
154 bool RefreshCallback( void *data )
155 {
156     SkinManage( (intf_thread_t*)data );
157     return True;
158 }
159
160
161 //---------------------------------------------------------------------------
162 // X11 interface
163 //---------------------------------------------------------------------------
164 void OSRun( intf_thread_t *p_intf )
165 {
166     VlcProc *proc = new VlcProc( p_intf );
167
168     Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
169
170
171     // Timer for SkinManage
172     X11Timer *refreshTimer = new X11Timer( p_intf, 100000, RefreshCallback,
173                                            (void*)p_intf );
174     X11TimerManager *timerManager = X11TimerManager::Instance( p_intf );
175     timerManager->addTimer( refreshTimer );
176
177     // Main event loop
178     int close = 0;
179     while( !close )
180     {
181         XEvent event;
182         int nPending;
183         XLOCK;
184         nPending = XPending( display );
185         XUNLOCK;
186         while( !close && nPending > 0 )
187         {
188             XLOCK;
189             XNextEvent( display, &event );
190             XUNLOCK;
191             close = ProcessEvent( p_intf, proc, &event );
192             XLOCK;
193             nPending = XPending( display );
194             XUNLOCK;
195         }
196         msleep( 1000 );
197     }
198
199     timerManager->Destroy();
200     delete refreshTimer;
201     
202 }
203 //---------------------------------------------------------------------------
204 bool IsVLCEvent( unsigned int msg )
205 {
206     return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
207 }
208 //---------------------------------------------------------------------------
209
210 #endif