1 /*****************************************************************************
2 * gtk_main.c : Gtk+ wrapper for gtk_main
3 *****************************************************************************
4 * Copyright (C) 2002 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #if defined(MODULE_NAME_IS_gtk2_main)
36 #if defined(MODULE_NAME_IS_gnome_main) || defined(MODULE_NAME_IS_gnome2_main)
40 /*****************************************************************************
42 *****************************************************************************/
43 static int Open ( vlc_object_t * );
44 static void Close ( vlc_object_t * );
46 static void GtkMain ( vlc_object_t * );
48 /*****************************************************************************
49 * Local variables (mutex-protected).
50 *****************************************************************************/
51 static int i_refcount = 0;
52 static vlc_object_t * p_gtk_main = NULL;
54 /*****************************************************************************
56 *****************************************************************************/
59 set_description( _("Gtk+ GUI helper") );
60 #if defined(MODULE_NAME_IS_gtk_main)
62 add_shortcut( "gtk" );
63 #elif defined(MODULE_NAME_IS_gnome_main)
65 add_shortcut( "gtk" );
66 add_shortcut( "gnome" );
67 #elif defined(MODULE_NAME_IS_gtk2_main)
69 add_shortcut( "gtk2" );
70 #elif defined(MODULE_NAME_IS_gnome2_main)
72 add_shortcut( "gtk2" );
73 add_shortcut( "gnome2" );
75 set_capability( "gui-helper", i_cap );
76 set_callbacks( Open, Close );
77 linked_with_a_crap_library_which_uses_atexit();
80 /*****************************************************************************
81 * Open: initialize and create window
82 *****************************************************************************/
83 static int Open( vlc_object_t *p_this )
87 lock = var_AcquireMutex( "gtk" );
92 vlc_mutex_unlock( lock );
97 p_gtk_main = vlc_object_create( p_this, VLC_OBJECT_GENERIC );
99 /* Only initialize gthreads if it's the first time we do it */
100 if( !g_thread_supported() )
102 g_thread_init( NULL );
105 /* Launch the gtk_main() thread. It will not return until it has
106 * called gdk_threads_enter(), which ensures us thread safety. */
107 if( vlc_thread_create( p_gtk_main, "gtk_main", GtkMain,
108 VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
110 vlc_object_destroy( p_gtk_main );
112 vlc_mutex_unlock( lock );
117 vlc_mutex_unlock( lock );
122 /*****************************************************************************
123 * Close: destroy interface window
124 *****************************************************************************/
125 static void Close( vlc_object_t *p_this )
129 lock = var_AcquireMutex( "gtk" );
135 vlc_mutex_unlock( lock );
140 vlc_thread_join( p_gtk_main );
142 vlc_object_destroy( p_gtk_main );
145 vlc_mutex_unlock( lock );
148 static gint foo( gpointer bar ) { return TRUE; }
150 /*****************************************************************************
151 * GtkMain: Gtk+ thread
152 *****************************************************************************
153 * this part of the interface is in a separate thread so that we can call
154 * gtk_main() from within it without annoying the rest of the program.
155 *****************************************************************************/
156 static void GtkMain( vlc_object_t *p_this )
158 /* gtk_init needs to know the command line. We don't care, so we
159 * give it an empty one */
160 static char *p_args[] = { "", NULL };
161 #if defined(MODULE_NAME_IS_gtk_main) || defined(MODULE_NAME_IS_gtk2_main)
162 static char **pp_args = p_args;
164 static int i_args = 1;
166 /* FIXME: deprecated ? */
167 #if defined(MODULE_NAME_IS_gtk2_main) || defined(MODULE_NAME_IS_gnome2_main)
171 #if defined(MODULE_NAME_IS_gnome_main)
172 gnome_init( p_this->p_libvlc->psz_object_name, VERSION, i_args, p_args );
173 #elif defined(MODULE_NAME_IS_gnome2_main)
174 gnome_program_init( PACKAGE, VERSION, LIBGNOMEUI_MODULE,
176 GNOME_PARAM_APP_DATADIR, "",//PACKAGE_DATA_DIR,
180 gtk_init( &i_args, &pp_args );
185 vlc_thread_ready( p_this );
187 /* If we don't add this simple timeout, gtk_main remains stuck if
188 * we try to close the window without having sent any gtk event. */
189 gtk_timeout_add( INTF_IDLE_SLEEP / 1000, foo, p_this );