1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_run.cpp,v 1.17 2003/06/07 12:19:23 asmax Exp $
7 * Authors: Cyril Deguet <asmax@videolan.org>
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.
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.
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,
23 *****************************************************************************/
27 //--- X11 -------------------------------------------------------------------
30 //--- VLC -------------------------------------------------------------------
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"
47 //---------------------------------------------------------------------------
49 //---------------------------------------------------------------------------
50 bool IsVLCEvent( unsigned int msg );
51 int SkinManage( intf_thread_t *p_intf );
53 //---------------------------------------------------------------------------
54 // X11 event processing
55 //---------------------------------------------------------------------------
56 int ProcessEvent( intf_thread_t *p_intf, VlcProc *proc, XEvent *event )
59 list<SkinWindow *>::const_iterator win;
63 Window wnd = ((XAnyEvent *)event)->window;
65 // Create event to dispatch in windows
67 if( event->type == ClientMessage )
69 msg = ( (XClientMessageEvent *)event )->data.l[0];
70 evt = (Event *)new OSEvent( p_intf,
71 ((XAnyEvent *)event)->window, msg,
72 ( (XClientMessageEvent *)event )->data.l[1],
73 ( (XClientMessageEvent *)event )->data.l[2] );
79 evt = (Event *)new OSEvent( p_intf,
80 ((XAnyEvent *)event)->window, msg, 0, (long)event );
83 // Process keyboard shortcuts
88 if( ((XKeyEvent *)event)->state & Mod1Mask )
93 else if( ((XKeyEvent *)event)->state & ControlMask )
97 // Take the second keysym = upper case character
98 int key = XLookupKeysym( (XKeyEvent *)event, 1 );
100 p_intf->p_sys->p_theme->EvtBank->TestShortcut( key , KeyModifier );
104 else if( IsVLCEvent( msg ) )
106 if( !proc->EventProc( evt ) )
108 return 1; // Exit VLC !
111 else if( wnd == p_intf->p_sys->mainWin )
114 for( win = p_intf->p_sys->p_theme->WindowList.begin();
115 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
117 (*win)->ProcessEvent( evt );
122 // Find window matching with gwnd
123 for( win = p_intf->p_sys->p_theme->WindowList.begin();
124 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
126 // If it is the correct window
127 if( wnd == ( (X11Window *)(*win) )->GetHandle() )
129 // Send event and check if processed
130 if( (*win)->ProcessEvent( evt ) )
132 delete (OSEvent *)evt;
143 evt->DestructParameters();
144 delete (OSEvent *)evt;
146 // Check if vlc is closing
153 bool RefreshCallback( void *data )
155 SkinManage( (intf_thread_t*)data );
160 //---------------------------------------------------------------------------
162 //---------------------------------------------------------------------------
163 void OSRun( intf_thread_t *p_intf )
165 VlcProc *proc = new VlcProc( p_intf );
167 Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
170 // Timer for SkinManage
171 X11Timer *refreshTimer = new X11Timer( p_intf, 100000, RefreshCallback,
173 X11TimerManager *timerManager = X11TimerManager::Instance( p_intf );
174 timerManager->addTimer( refreshTimer );
183 nPending = XPending( display );
185 while( !close && nPending > 0 )
188 XNextEvent( display, &event );
190 close = ProcessEvent( p_intf, proc, &event );
192 nPending = XPending( display );
198 timerManager->Destroy();
202 //---------------------------------------------------------------------------
203 bool IsVLCEvent( unsigned int msg )
205 return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
207 //---------------------------------------------------------------------------