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 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
37 #if defined(MODULE_NAME_IS_gtk2_main)
41 #if defined(MODULE_NAME_IS_gnome_main) || defined(MODULE_NAME_IS_gnome2_main)
45 /*****************************************************************************
47 *****************************************************************************/
48 static int Open ( vlc_object_t * );
49 static void Close ( vlc_object_t * );
51 static void GtkMain ( vlc_object_t * );
53 /*****************************************************************************
54 * Local variables (mutex-protected).
55 *****************************************************************************/
56 static int i_refcount = 0;
57 static vlc_object_t * p_gtk_main = NULL;
59 /*****************************************************************************
61 *****************************************************************************/
64 set_description( N_("Gtk+ GUI helper") );
65 #if defined(MODULE_NAME_IS_gtk_main)
67 add_shortcut( "gtk" );
68 #elif defined(MODULE_NAME_IS_gnome_main)
70 add_shortcut( "gtk" );
71 add_shortcut( "gnome" );
72 #elif defined(MODULE_NAME_IS_gtk2_main)
74 add_shortcut( "gtk2" );
75 #elif defined(MODULE_NAME_IS_gnome2_main)
77 add_shortcut( "gtk2" );
78 add_shortcut( "gnome2" );
80 set_capability( "gui-helper", i_cap );
81 set_callbacks( Open, Close );
82 linked_with_a_crap_library_which_uses_atexit();
85 /*****************************************************************************
86 * Open: initialize and create window
87 *****************************************************************************/
88 static int Open( vlc_object_t *p_this )
92 lock = var_AcquireMutex( "gtk" );
97 vlc_mutex_unlock( lock );
102 p_gtk_main = vlc_object_create( p_this, sizeof( vlc_object_t ) );
104 /* Only initialize gthreads if it's the first time we do it */
105 if( !g_thread_supported() )
107 g_thread_init( NULL );
110 /* Launch the gtk_main() thread. It will not return until it has
111 * called gdk_threads_enter(), which ensures us thread safety. */
112 if( vlc_thread_create( p_gtk_main, "gtk_main", GtkMain,
113 VLC_THREAD_PRIORITY_LOW, true ) )
115 vlc_object_release( p_gtk_main );
117 vlc_mutex_unlock( lock );
122 vlc_mutex_unlock( lock );
127 /*****************************************************************************
128 * Close: destroy interface window
129 *****************************************************************************/
130 static void Close( vlc_object_t *p_this )
134 lock = var_AcquireMutex( "gtk" );
140 vlc_mutex_unlock( lock );
145 vlc_thread_join( p_gtk_main );
147 vlc_object_release( p_gtk_main );
150 vlc_mutex_unlock( lock );
153 static gint foo( gpointer bar ) { return TRUE; }
155 /*****************************************************************************
156 * GtkMain: Gtk+ thread
157 *****************************************************************************
158 * this part of the interface is in a separate thread so that we can call
159 * gtk_main() from within it without annoying the rest of the program.
160 *****************************************************************************/
161 static void GtkMain( vlc_object_t *p_this )
163 /* gtk_init needs to know the command line. We don't care, so we
164 * give it an empty one */
165 static char *p_args[] = { "", NULL };
166 #if defined(MODULE_NAME_IS_gtk_main) || defined(MODULE_NAME_IS_gtk2_main)
167 static char **pp_args = p_args;
169 static int i_args = 1;
171 /* FIXME: deprecated ? */
172 #if defined(MODULE_NAME_IS_gtk2_main) || defined(MODULE_NAME_IS_gnome2_main)
176 #if defined(MODULE_NAME_IS_gnome_main)
177 gnome_init( p_this->p_libvlc->psz_object_name, VERSION, i_args, p_args );
178 #elif defined(MODULE_NAME_IS_gnome2_main)
179 gnome_program_init( PACKAGE, VERSION, LIBGNOMEUI_MODULE,
181 GNOME_PARAM_APP_DATADIR, "",//PACKAGE_DATA_DIR,
185 gtk_init( &i_args, &pp_args );
190 vlc_thread_ready( p_this );
192 /* If we don't add this simple timeout, gtk_main remains stuck if
193 * we try to close the window without having sent any gtk event. */
194 gtk_timeout_add( INTF_IDLE_SLEEP / 1000, foo, p_this );