]> git.sesse.net Git - vlc/blob - plugins/gnome/intf_gnome.c
0ed936a98435e60d199329ccbef62e7f3f7107b7
[vlc] / plugins / gnome / intf_gnome.c
1 /*****************************************************************************
2  * intf_gnome.c: Gnome interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <stdlib.h>                                                /* free() */
30 #include <string.h>                                            /* strerror() */
31 #include <sys/types.h>                        /* on BSD, uio.h needs types.h */
32 #include <sys/uio.h>                                          /* for input.h */
33
34 #include <X11/Xlib.h>
35 #include <X11/Xutil.h>
36 #include <X11/keysym.h>
37
38 #include "config.h"
39 #include "common.h"
40 #include "threads.h"
41 #include "mtime.h"
42 #include "plugins.h"
43
44 #include "input.h"
45 #include "video.h"
46 #include "video_output.h"
47
48 #include "audio_output.h" /* needed for mute */
49
50 #include "intf_msg.h"
51 #include "interface.h"
52
53 #include "main.h"
54
55 #include <stdio.h>
56
57 #include <gnome.h>
58
59 #include "intf_gnome_thread.h"
60 #include "intf_gnome.h"
61 #include "intf_gnome_interface.h"
62 #include "intf_gnome_support.h"
63
64 /*****************************************************************************
65  * intf_SysCreate: initialize and create window
66  *****************************************************************************/
67 int intf_SysCreate( intf_thread_t *p_intf )
68 {
69     char       *psz_display;
70
71     /* Allocate instance and initialize some members */
72     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
73     if( p_intf->p_sys == NULL )
74     {
75         intf_ErrMsg("error: %s\n", strerror(ENOMEM));
76         return( 1 );
77     }
78
79     p_intf->p_sys->p_gnome = malloc( sizeof( gnome_thread_t ) );
80     if( p_intf->p_sys->p_gnome == NULL )
81     {
82         intf_ErrMsg("error: %s\n", strerror(ENOMEM));
83         free( p_intf->p_sys );
84         return( 1 );
85     }
86
87     /* Open display, unsing 'vlc_display' or DISPLAY environment variable */
88     psz_display = XDisplayName( main_GetPszVariable( VOUT_DISPLAY_VAR, NULL ) );
89     p_intf->p_sys->p_display = XOpenDisplay( psz_display );
90     if( !p_intf->p_sys->p_display )                                 /* error */
91     {
92         intf_ErrMsg("error: can't open display %s\n", psz_display );
93         free( p_intf->p_sys->p_gnome );
94         free( p_intf->p_sys );
95         return( 1 );
96     }
97     p_intf->p_sys->i_screen = DefaultScreen( p_intf->p_sys->p_display );
98
99     /* Spawn base window - this window will include the video output window */
100     if( GnomeCreateWindow( p_intf ) )
101     {
102         intf_ErrMsg( "error: can't create output window\n" );
103         XCloseDisplay( p_intf->p_sys->p_display );
104         free( p_intf->p_sys->p_gnome );
105         free( p_intf->p_sys );
106         return( 1 );
107     }
108
109     /* Spawn video output thread */
110     if( p_main->b_video )
111     {
112         p_intf->p_vout = vout_CreateThread( psz_display, p_intf->p_sys->window,
113                                             p_intf->p_sys->i_width,
114                                             p_intf->p_sys->i_height, NULL, 0,
115                                             (void *)&p_intf->p_sys->colormap );
116
117         if( p_intf->p_vout == NULL )                                /* error */
118         {
119             intf_ErrMsg("error: can't create video output thread\n" );
120             GnomeDestroyWindow( p_intf );
121             XCloseDisplay( p_intf->p_sys->p_display );
122             free( p_intf->p_sys->p_gnome );
123             free( p_intf->p_sys );
124             return( 1 );
125         }
126     }
127
128     /* Spawn Gnome thread */
129     p_intf->p_sys->p_gnome->b_die = 0;
130     p_intf->p_sys->p_gnome->b_error = 0;
131     
132     p_intf->p_sys->p_gnome->b_popup_changed = 0;
133     p_intf->p_sys->p_gnome->b_window_changed = 0;
134     p_intf->p_sys->p_gnome->b_playlist_changed = 0;
135
136     vlc_thread_create( &p_intf->p_sys->p_gnome->thread_id, "gnome",
137                        (void *)GnomeThread, p_intf->p_sys->p_gnome );
138
139     /* Disable screen saver and return */
140     p_intf->p_sys->i_ss_count = 1;
141     GnomeDisableScreenSaver( p_intf );
142     return( 0 );
143 }
144
145 /*****************************************************************************
146  * intf_SysDestroy: destroy interface window
147  *****************************************************************************/
148 void intf_SysDestroy( intf_thread_t *p_intf )
149 {
150     /* Enable screen saver */
151     GnomeEnableScreenSaver( p_intf );
152
153     /* Close input thread, if any (blocking) */
154     if( p_intf->p_input )
155     {
156         input_DestroyThread( p_intf->p_input, NULL );
157     }
158
159     /* Close video output thread, if any (blocking) */
160     if( p_intf->p_vout )
161     {
162         vout_DestroyThread( p_intf->p_vout, NULL );
163     }
164
165     /* Close gnome thread, if any (blocking) */
166     if( p_intf->p_sys->p_gnome->thread_id )
167     {
168         p_intf->p_sys->p_gnome->b_die = 1;
169         intf_Msg( "waiting for Gnome thread to terminate\n" );
170         vlc_thread_join( p_intf->p_sys->p_gnome->thread_id );
171         intf_Msg( "Gnome thread terminated\n" );
172     }
173
174     /* Close main window and display */
175     GnomeDestroyWindow( p_intf );
176     XCloseDisplay( p_intf->p_sys->p_display );
177
178     /* Destroy structures */
179     free( p_intf->p_sys->p_gnome );
180     free( p_intf->p_sys );
181 }
182
183 /*****************************************************************************
184  * intf_SysManage: event loop
185  *****************************************************************************/
186 void intf_SysManage( intf_thread_t *p_intf )
187 {
188     /* Manage main window */
189     GnomeManageWindow( p_intf );
190
191     /* Manage messages from the Gnome interface */
192     GnomeManageInterface( p_intf );
193 }
194
195 /* following functions are local */
196
197 /*****************************************************************************
198  * GnomeCreateWindow: open and set-up X11 main window
199  *****************************************************************************/
200 static int GnomeCreateWindow( intf_thread_t *p_intf )
201 {
202     XSizeHints              xsize_hints;
203     XSetWindowAttributes    xwindow_attributes;
204     XGCValues               xgcvalues;
205     XEvent                  xevent;
206     boolean_t               b_expose;
207     boolean_t               b_configure_notify;
208     boolean_t               b_map_notify;
209
210     /* Set main window's size */
211     p_intf->p_sys->i_width =  main_GetIntVariable( VOUT_WIDTH_VAR,
212                                                    VOUT_WIDTH_DEFAULT );
213     p_intf->p_sys->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
214                                                    VOUT_HEIGHT_DEFAULT );
215
216     /* Prepare window manager hints and properties */
217     xsize_hints.base_width =            p_intf->p_sys->i_width;
218     xsize_hints.base_height =           p_intf->p_sys->i_height;
219     xsize_hints.flags =                 PSize;
220     p_intf->p_sys->wm_protocols =       XInternAtom( p_intf->p_sys->p_display,
221                                                      "WM_PROTOCOLS", True );
222     p_intf->p_sys->wm_delete_window =   XInternAtom( p_intf->p_sys->p_display,
223                                                      "WM_DELETE_WINDOW", True );
224
225     /* Prepare window attributes */
226     xwindow_attributes.backing_store = Always;       /* save the hidden part */
227     xwindow_attributes.background_pixel = WhitePixel( p_intf->p_sys->p_display,
228                                                       p_intf->p_sys->i_screen );
229
230     xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
231
232     /* Create the window and set hints - the window must receive ConfigureNotify
233      * events, and, until it is displayed, Expose and MapNotify events. */
234     p_intf->p_sys->window =
235             XCreateWindow( p_intf->p_sys->p_display,
236                            DefaultRootWindow( p_intf->p_sys->p_display ),
237                            0, 0,
238                            p_intf->p_sys->i_width, p_intf->p_sys->i_height, 1,
239                            0, InputOutput, 0,
240                            CWBackingStore | CWBackPixel | CWEventMask,
241                            &xwindow_attributes );
242
243     /* Set window manager hints and properties: size hints, command,
244      * window's name, and accepted protocols */
245     XSetWMNormalHints( p_intf->p_sys->p_display, p_intf->p_sys->window,
246                        &xsize_hints );
247     XSetCommand( p_intf->p_sys->p_display, p_intf->p_sys->window,
248                  p_main->ppsz_argv, p_main->i_argc );
249     XStoreName( p_intf->p_sys->p_display, p_intf->p_sys->window, VOUT_TITLE );
250     if( (p_intf->p_sys->wm_protocols == None)        /* use WM_DELETE_WINDOW */
251         || (p_intf->p_sys->wm_delete_window == None)
252         || !XSetWMProtocols( p_intf->p_sys->p_display, p_intf->p_sys->window,
253                              &p_intf->p_sys->wm_delete_window, 1 ) )
254     {
255         /* WM_DELETE_WINDOW is not supported by window manager */
256         intf_Msg("error: missing or bad window manager - please exit program kindly.\n");
257     }
258
259     /* Creation of a graphic context that doesn't generate a GraphicsExpose
260      * event when using functions like XCopyArea */
261     xgcvalues.graphics_exposures = False;
262     p_intf->p_sys->gc =  XCreateGC( p_intf->p_sys->p_display, p_intf->p_sys->window,
263                                     GCGraphicsExposures, &xgcvalues);
264
265     /* Send orders to server, and wait until window is displayed - three
266      * events must be received: a MapNotify event, an Expose event allowing
267      * drawing in the window, and a ConfigureNotify to get the window
268      * dimensions. Once those events have been received, only ConfigureNotify
269      * events need to be received. */
270     b_expose = 0;
271     b_configure_notify = 0;
272     b_map_notify = 0;
273     XMapWindow( p_intf->p_sys->p_display, p_intf->p_sys->window);
274     do
275     {
276         XNextEvent( p_intf->p_sys->p_display, &xevent);
277         if( (xevent.type == Expose)
278             && (xevent.xexpose.window == p_intf->p_sys->window) )
279         {
280             b_expose = 1;
281         }
282         else if( (xevent.type == MapNotify)
283                  && (xevent.xmap.window == p_intf->p_sys->window) )
284         {
285             b_map_notify = 1;
286         }
287         else if( (xevent.type == ConfigureNotify)
288                  && (xevent.xconfigure.window == p_intf->p_sys->window) )
289         {
290             b_configure_notify = 1;
291             p_intf->p_sys->i_width = xevent.xconfigure.width;
292             p_intf->p_sys->i_height = xevent.xconfigure.height;
293         }
294     } while( !( b_expose && b_configure_notify && b_map_notify ) );
295
296     XSelectInput( p_intf->p_sys->p_display, p_intf->p_sys->window,
297                   StructureNotifyMask | KeyPressMask | ButtonPressMask );
298
299     if( XDefaultDepth(p_intf->p_sys->p_display, p_intf->p_sys->i_screen) == 8 )
300     {
301         /* Allocate a new palette */
302         p_intf->p_sys->colormap = XCreateColormap( p_intf->p_sys->p_display,
303                               DefaultRootWindow( p_intf->p_sys->p_display ),
304                               DefaultVisual( p_intf->p_sys->p_display,
305                                              p_intf->p_sys->i_screen ),
306                               AllocAll );
307
308         xwindow_attributes.colormap = p_intf->p_sys->colormap;
309         XChangeWindowAttributes( p_intf->p_sys->p_display,
310                                  p_intf->p_sys->window,
311                                  CWColormap, &xwindow_attributes );
312     }
313
314     /* At this stage, the window is open, displayed, and ready to receive data */
315     return( 0 );
316 }
317
318 /*****************************************************************************
319  * GnomeDestroyWindow: destroy X11 main window
320  *****************************************************************************/
321 static void GnomeDestroyWindow( intf_thread_t *p_intf )
322 {
323     XUnmapWindow( p_intf->p_sys->p_display, p_intf->p_sys->window );
324     XFreeGC( p_intf->p_sys->p_display, p_intf->p_sys->gc );
325     XDestroyWindow( p_intf->p_sys->p_display, p_intf->p_sys->window );
326 }
327
328 /*****************************************************************************
329  * GnomeManageWindow: manage X11 main window
330  *****************************************************************************/
331 static void GnomeManageWindow( intf_thread_t *p_intf )
332 {
333     XEvent      xevent;                                         /* X11 event */
334     boolean_t   b_resized;                        /* window has been resized */
335     char        i_key;                                    /* ISO Latin-1 key */
336
337     /* Handle X11 events: ConfigureNotify events are parsed to know if the
338      * output window's size changed, MapNotify and UnmapNotify to know if the
339      * window is mapped (and if the display is useful), and ClientMessages
340      * to intercept window destruction requests */
341     b_resized = 0;
342     while( XCheckWindowEvent( p_intf->p_sys->p_display, p_intf->p_sys->window,
343                               StructureNotifyMask | KeyPressMask |
344                               ButtonPressMask, &xevent ) == True )
345     {
346         /* ConfigureNotify event: prepare  */
347         if( (xevent.type == ConfigureNotify)
348             && ((xevent.xconfigure.width != p_intf->p_sys->i_width)
349                 || (xevent.xconfigure.height != p_intf->p_sys->i_height)) )
350         {
351             /* Update dimensions */
352             b_resized = 1;
353             p_intf->p_sys->i_width = xevent.xconfigure.width;
354             p_intf->p_sys->i_height = xevent.xconfigure.height;
355         }
356         /* MapNotify event: change window status and disable screen saver */
357         else if( xevent.type == MapNotify)
358         {
359             if( (p_intf->p_vout != NULL) && !p_intf->p_vout->b_active )
360             {
361                 GnomeDisableScreenSaver( p_intf );
362                 p_intf->p_vout->b_active = 1;
363             }
364         }
365         /* UnmapNotify event: change window status and enable screen saver */
366         else if( xevent.type == UnmapNotify )
367         {
368             if( (p_intf->p_vout != NULL) && p_intf->p_vout->b_active )
369             {
370                 GnomeEnableScreenSaver( p_intf );
371                 p_intf->p_vout->b_active = 0;
372             }
373         }
374         /* Keyboard event */
375         else if( xevent.type == KeyPress )
376         {
377             if( XLookupString( &xevent.xkey, &i_key, 1, NULL, NULL ) )
378             {
379                 if( intf_ProcessKey( p_intf, i_key ) )
380                 {
381                     intf_DbgMsg( "unhandled key '%c' (%i)\n", (char) i_key, i_key );
382                 }
383             }
384         }
385         /* Mouse click */
386         else if( xevent.type == ButtonPress )
387         {
388             switch( ((XButtonEvent *)&xevent)->button )
389             {
390                 case Button1:
391                     /* in this part we will eventually manage
392                      * clicks for DVD navigation for instance */
393                     break;
394
395                 case Button2:
396                     GnomeTogglePointer( p_intf );
397                     break;
398
399                 case Button3:
400                     /* toggle the menu display */
401                     vlc_mutex_lock( &p_intf->p_sys->p_gnome->change_lock );
402                     p_intf->p_sys->p_gnome->b_popup_changed = 1;
403                     vlc_mutex_unlock( &p_intf->p_sys->p_gnome->change_lock );
404                     break;
405             }
406
407         }
408 #ifdef DEBUG
409         /* Other event */
410         else
411         {
412             intf_DbgMsg( "%p -> unhandled event type %d received\n",
413                          p_intf, xevent.type );
414         }
415 #endif
416     }
417
418     /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
419      * are handled - according to the man pages, the format is always 32
420      * in this case */
421     while( XCheckTypedEvent( p_intf->p_sys->p_display,
422                              ClientMessage, &xevent ) )
423     {
424         if( (xevent.xclient.message_type == p_intf->p_sys->wm_protocols)
425             && (xevent.xclient.data.l[0] == p_intf->p_sys->wm_delete_window ) )
426         {
427             p_intf->b_die = 1;
428         }
429         else
430         {
431             intf_DbgMsg( "%p -> unhandled ClientMessage received\n", p_intf );
432         }
433     }
434
435     /*
436      * Handle vout or interface windows resizing
437      */
438     if( p_intf->p_vout != NULL )
439     {
440         if( b_resized )
441         {
442             /* If interface window has been resized, change vout size */
443             intf_DbgMsg( "resizing output window\n" );
444             vlc_mutex_lock( &p_intf->p_vout->change_lock );
445             p_intf->p_vout->i_width =  p_intf->p_sys->i_width;
446             p_intf->p_vout->i_height = p_intf->p_sys->i_height;
447             p_intf->p_vout->i_changes |= VOUT_SIZE_CHANGE;
448             vlc_mutex_unlock( &p_intf->p_vout->change_lock );
449         }
450         else if( (p_intf->p_vout->i_width  != p_intf->p_sys->i_width) ||
451                  (p_intf->p_vout->i_height != p_intf->p_sys->i_height) )
452         {
453            /* If video output size has changed, change interface window size */
454             intf_DbgMsg( "resizing output window\n" );
455             p_intf->p_sys->i_width =    p_intf->p_vout->i_width;
456             p_intf->p_sys->i_height =   p_intf->p_vout->i_height;
457             XResizeWindow( p_intf->p_sys->p_display, p_intf->p_sys->window,
458                            p_intf->p_sys->i_width, p_intf->p_sys->i_height );
459         }
460     }
461 }
462
463 /*****************************************************************************
464  * GnomeEnableScreenSaver: enable screen saver
465  *****************************************************************************
466  * This function enable the screen saver on a display after it had been
467  * disabled by XDisableScreenSaver. Both functions use a counter mechanism to
468  * know wether the screen saver can be activated or not: if n successive calls
469  * are made to XDisableScreenSaver, n successive calls to XEnableScreenSaver
470  * will be required before the screen saver could effectively be activated.
471  *****************************************************************************/
472 void GnomeEnableScreenSaver( intf_thread_t *p_intf )
473 {
474     if( p_intf->p_sys->i_ss_count++ == 0 )
475     {
476         intf_Msg( "Enabling screen saver\n" );
477         XSetScreenSaver( p_intf->p_sys->p_display, p_intf->p_sys->i_ss_timeout,
478                          p_intf->p_sys->i_ss_interval, p_intf->p_sys->i_ss_blanking,
479                          p_intf->p_sys->i_ss_exposure );
480     }
481 }
482
483 /*****************************************************************************
484  * GnomeDisableScreenSaver: disable screen saver
485  *****************************************************************************
486  * See XEnableScreenSaver
487  *****************************************************************************/
488 void GnomeDisableScreenSaver( intf_thread_t *p_intf )
489 {
490     if( --p_intf->p_sys->i_ss_count == 0 )
491     {
492         /* Save screen saver informations */
493         XGetScreenSaver( p_intf->p_sys->p_display, &p_intf->p_sys->i_ss_timeout,
494                          &p_intf->p_sys->i_ss_interval, &p_intf->p_sys->i_ss_blanking,
495                          &p_intf->p_sys->i_ss_exposure );
496
497         /* Disable screen saver */
498         intf_Msg("Disabling screen saver\n");
499         XSetScreenSaver( p_intf->p_sys->p_display, 0,
500                          p_intf->p_sys->i_ss_interval, p_intf->p_sys->i_ss_blanking,
501                          p_intf->p_sys->i_ss_exposure );
502     }
503 }
504
505 /*****************************************************************************
506  * GnomeTogglePointer: hide or show the mouse pointer
507  *****************************************************************************
508  * This function hides the X pointer if it is visible by putting it at
509  * coordinates (32,32) and setting the pointer sprite to a blank one. To
510  * show it again, we disable the sprite and restore the original coordinates.
511  *****************************************************************************/
512 void GnomeTogglePointer( intf_thread_t *p_intf )
513 {
514     static Cursor cursor;
515     static boolean_t b_cursor = 0;
516
517     if( p_intf->p_sys->b_mouse )
518     {
519         p_intf->p_sys->b_mouse = 0;
520
521         if( !b_cursor )
522         {
523             XColor color;
524             Pixmap blank = XCreatePixmap( p_intf->p_sys->p_display,
525                                DefaultRootWindow(p_intf->p_sys->p_display),
526                                1, 1, 1 );
527
528             XParseColor( p_intf->p_sys->p_display,
529                          XCreateColormap( p_intf->p_sys->p_display,
530                                           DefaultRootWindow(
531                                                   p_intf->p_sys->p_display ),
532                                           DefaultVisual(
533                                                   p_intf->p_sys->p_display,
534                                                   p_intf->p_sys->i_screen ),
535                                           AllocNone ),
536                          "black", &color );
537
538             cursor = XCreatePixmapCursor( p_intf->p_sys->p_display,
539                            blank, blank, &color, &color, 1, 1 );
540
541             b_cursor = 1;
542         }
543         XDefineCursor( p_intf->p_sys->p_display,
544                        p_intf->p_sys->window, cursor );
545     }
546     else
547     {
548         p_intf->p_sys->b_mouse = 1;
549
550         XUndefineCursor( p_intf->p_sys->p_display, p_intf->p_sys->window );
551     }
552 }
553
554 /*****************************************************************************
555  * GnomeManageInterface: manage messages from the Gnome interface
556
557  *****************************************************************************
558  * In this function, called approx. 10 times a second, we check what the
559  * Gnome interface wanted to tell us.
560  *****************************************************************************/
561 static void GnomeManageInterface( intf_thread_t *p_intf )
562 {
563     gnome_thread_t *p_gnome = p_intf->p_sys->p_gnome;
564
565     /* lock the change structure */
566     vlc_mutex_lock( &p_gnome->change_lock );
567
568     /* you killed my father, prepare to die */
569     if( p_gnome->b_die )
570     {
571         p_intf->b_die = 1;
572     }
573
574     if( p_gnome->b_activity_changed )
575     {
576         vlc_mutex_lock( &p_intf->p_vout->picture_lock );
577         p_intf->p_vout->b_active = p_gnome->b_activity;
578         /* having to access p_main sucks */
579         p_main->p_aout->b_active = p_gnome->b_activity;
580         vlc_mutex_unlock( &p_intf->p_vout->picture_lock );
581
582         p_gnome->b_activity_changed = 0;
583     }
584
585     /* unlock the change structure */
586     vlc_mutex_unlock( &p_gnome->change_lock );
587 }
588
589 /*****************************************************************************
590  * GnomeManageMain: manage main thread messages
591  *****************************************************************************
592  * In this function, called approx. 10 times a second, we check what the
593  * main program wanted to tell us.
594  *****************************************************************************/
595 static gint GnomeManageMain( gpointer p_data )
596 {
597     gnome_thread_t *p_gnome = (void *)p_data;
598
599     /* lock the change structure */
600     vlc_mutex_lock( &p_gnome->change_lock );
601
602     if( p_gnome->b_die )
603     {
604         /* unlock the change structure */
605         vlc_mutex_unlock( &p_gnome->change_lock );
606
607         /* prepare to die, young man */
608         gtk_main_quit();
609         return( FALSE );
610     }
611
612     /* if the "display popup" flag has changed */
613     if( p_gnome->b_popup_changed )
614     {
615         gnome_popup_menu_do_popup( p_gnome->p_popup,
616                                    NULL, NULL, NULL, NULL );
617         p_gnome->b_popup_changed = 0;
618     }
619
620     /* unlock the change structure */
621     vlc_mutex_unlock( &p_gnome->change_lock );
622
623     return( TRUE );
624 }
625
626 /*****************************************************************************
627  * GnomeThread: special Gnome thread
628  *****************************************************************************
629  * this part of the interface is in a separate thread so that we can call
630  * gtk_main() from within it without annoying the rest of the program.
631  * XXX: the approach may look kludgy, and probably is, but I could not find
632  * a better way to dynamically load a Gnome interface at runtime.
633  *****************************************************************************/
634 void GnomeThread( gnome_thread_t *p_gnome )
635 {
636     /* gnome_init needs to know the command line. We don't care, so we
637      * give it an empty one */
638     char *p_args[] = { };
639
640     /* Sleep to avoid using all CPU - since some interfaces needs to access
641      * keyboard events, a 100ms delay is a good compromise */
642     gtk_timeout_add( INTF_IDLE_SLEEP / 1000, GnomeManageMain, p_gnome );
643  
644     gnome_init( "vlc", VERSION, 1, p_args );
645
646     /* create some useful widgets that will certainly be used */
647     p_gnome->p_window = create_intf_window();
648     p_gnome->p_popup = create_intf_popup( );
649
650     /* we don't create these ones yet because we perhaps won't need them */
651     p_gnome->p_about = NULL;
652     p_gnome->p_playlist = NULL;
653
654     /* store p_sys to keep an eye on it */
655     gtk_object_set_data( GTK_OBJECT(p_gnome->p_window), "p_gnome", p_gnome );
656     gtk_object_set_data( GTK_OBJECT(p_gnome->p_popup), "p_gnome", p_gnome );
657
658     /* show the control window */
659     //gtk_widget_show( p_gnome->p_window );
660
661     /* enter gnome mode */
662     gtk_main();
663 }
664