1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_run.cpp,v 1.21 2003/06/09 12:33:16 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 &&
68 ((XClientMessageEvent*)event)->message_type == 0 )
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] );
80 evt = (Event *)new OSEvent( p_intf,
81 ((XAnyEvent *)event)->window, msg, 0, (long)event );
84 // Process keyboard shortcuts
89 if( ((XKeyEvent *)event)->state & Mod1Mask )
94 else if( ((XKeyEvent *)event)->state & ControlMask )
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 );
105 else if( IsVLCEvent( msg ) )
107 if( !proc->EventProc( evt ) )
109 delete (OSEvent *)evt;
110 return 1; // Exit VLC !
113 else if( wnd == p_intf->p_sys->mainWin )
116 for( win = p_intf->p_sys->p_theme->WindowList.begin();
117 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
119 (*win)->ProcessEvent( evt );
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++ )
128 // If it is the correct window
129 if( wnd == ( (X11Window *)(*win) )->GetHandle() )
131 // Send event and check if processed
132 if( (*win)->ProcessEvent( evt ) )
134 delete (OSEvent *)evt;
145 evt->DestructParameters();
146 delete (OSEvent *)evt;
148 // Check if vlc is closing
155 bool RefreshCallback( void *data )
157 SkinManage( (intf_thread_t*)data );
162 //---------------------------------------------------------------------------
164 //---------------------------------------------------------------------------
165 void OSRun( intf_thread_t *p_intf )
167 VlcProc *proc = new VlcProc( p_intf );
169 Display *display = ((OSTheme *)p_intf->p_sys->p_theme)->GetDisplay();
172 // Timer for SkinManage
173 X11Timer *refreshTimer = new X11Timer( p_intf, 100000, RefreshCallback,
175 X11TimerManager *timerManager = X11TimerManager::Instance( p_intf );
176 timerManager->addTimer( refreshTimer );
185 nPending = XPending( display );
187 while( !close && nPending > 0 )
190 XNextEvent( display, &event );
192 close = ProcessEvent( p_intf, proc, &event );
194 nPending = XPending( display );
200 timerManager->Destroy();
204 //---------------------------------------------------------------------------
205 bool IsVLCEvent( unsigned int msg )
207 return( msg > VLC_MESSAGE && msg < VLC_WINDOW );
209 //---------------------------------------------------------------------------