1 /*****************************************************************************
2 * gtk_main.c : Gtk+ wrapper for gtk_main
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: gtk_main.c,v 1.4 2002/08/21 17:31:58 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.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, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
29 #include <stdlib.h> /* atexit() */
37 /*****************************************************************************
39 *****************************************************************************/
40 static int Open ( vlc_object_t * );
41 static void Close ( vlc_object_t * );
43 static void GtkMain ( vlc_object_t * );
45 /*****************************************************************************
46 * The gtk_main_t object.
47 *****************************************************************************/
50 typedef struct gtk_main_t
56 /*****************************************************************************
57 * Local variables (mutex-protected).
58 *****************************************************************************/
59 static int i_refcount = 0;
60 static gtk_main_t * p_gtk_main = NULL;
62 /*****************************************************************************
64 *****************************************************************************/
66 set_description( _("Gtk+ helper module") );
67 set_capability( "gtk_main", 100 );
68 add_shortcut( "gtk" );
70 add_shortcut( "gnome" );
72 set_callbacks( Open, Close );
73 linked_with_a_crap_library_which_uses_atexit();
76 /*****************************************************************************
77 * Open: initialize and create window
78 *****************************************************************************/
79 static int Open( vlc_object_t *p_this )
81 vlc_mutex_lock( p_this->p_vlc->p_global_lock );
86 vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
91 p_gtk_main = vlc_object_create( p_this, sizeof(gtk_main_t) );
93 /* Only initialize gthreads if it's the first time we do it */
94 if( !g_thread_supported() )
96 g_thread_init( NULL );
99 /* Launch the gtk_main() thread. It will not return until it has
100 * called gdk_threads_enter(), which ensures us thread safety. */
101 if( vlc_thread_create( p_gtk_main, "gtk_main", GtkMain, VLC_TRUE ) )
103 vlc_object_destroy( p_gtk_main );
105 vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
110 vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
115 /*****************************************************************************
116 * Close: destroy interface window
117 *****************************************************************************/
118 static void Close( vlc_object_t *p_this )
120 vlc_mutex_lock( p_this->p_vlc->p_global_lock );
126 vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
131 vlc_thread_join( p_gtk_main );
133 vlc_object_destroy( p_gtk_main );
136 vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
139 static gint foo(gpointer foo)
144 /*****************************************************************************
145 * GtkMain: Gtk+ thread
146 *****************************************************************************
147 * this part of the interface is in a separate thread so that we can call
148 * gtk_main() from within it without annoying the rest of the program.
149 *****************************************************************************/
150 static void GtkMain( vlc_object_t *p_this )
152 /* gtk_init needs to know the command line. We don't care, so we
153 * give it an empty one */
154 static char *p_args[] = { "" };
156 static char **pp_args = p_args;
158 static int i_args = 1;
160 /* FIXME: deprecated ? */
161 /* gdk_threads_init(); */
164 gnome_init( p_this->p_vlc->psz_object_name, VERSION, i_args, p_args );
167 gtk_init( &i_args, &pp_args );
172 vlc_thread_ready( p_this );
174 /* If we don't add this simple timeout, gtk_main remains stuck ... */
175 gtk_timeout_add( INTF_IDLE_SLEEP / 1000, foo, p_this );