X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Fgtk_main.c;h=51cef4ade839610e2bf8309e79c44c22cb6fe74f;hb=9c24ad3ef121fbda9d6f50fdcbbe1a2193c838a5;hp=3c684a1a70ce63b6cb8fd94279579d4f1d098f1c;hpb=2799d36bc8abdc28df29a202acdb27223b25a7a7;p=vlc diff --git a/modules/misc/gtk_main.c b/modules/misc/gtk_main.c index 3c684a1a70..51cef4ade8 100644 --- a/modules/misc/gtk_main.c +++ b/modules/misc/gtk_main.c @@ -1,8 +1,8 @@ /***************************************************************************** * gtk_main.c : Gtk+ wrapper for gtk_main ***************************************************************************** - * Copyright (C) 2002 VideoLAN - * $Id: gtk_main.c,v 1.6 2002/09/30 11:05:39 sam Exp $ + * Copyright (C) 2002 the VideoLAN team + * $Id$ * * Authors: Samuel Hocevar * @@ -10,7 +10,7 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -18,19 +18,26 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include -#include /* atexit() */ #include -#ifdef MODULE_NAME_IS_gnome_main +#if defined(MODULE_NAME_IS_gtk2_main) +# include +#endif + +#if defined(MODULE_NAME_IS_gnome_main) || defined(MODULE_NAME_IS_gnome2_main) # include #endif @@ -42,35 +49,34 @@ static void Close ( vlc_object_t * ); static void GtkMain ( vlc_object_t * ); -/***************************************************************************** - * The gtk_main_t object. - *****************************************************************************/ -#define MAX_ATEXIT 10 - -typedef struct gtk_main_t -{ - VLC_COMMON_MEMBERS - -} gtk_main_t; - /***************************************************************************** * Local variables (mutex-protected). *****************************************************************************/ -static int i_refcount = 0; -static gtk_main_t * p_gtk_main = NULL; +static int i_refcount = 0; +static vlc_object_t * p_gtk_main = NULL; /***************************************************************************** * Module descriptor *****************************************************************************/ vlc_module_begin(); - set_description( _("Gtk+ helper module") ); -#ifdef MODULE_NAME_IS_gtk_main - set_capability( "gtk_main", 90 ); -#else - set_capability( "gtk_main", 100 ); + int i_cap; + set_description( _("Gtk+ GUI helper") ); +#if defined(MODULE_NAME_IS_gtk_main) + i_cap = 90; + add_shortcut( "gtk" ); +#elif defined(MODULE_NAME_IS_gnome_main) + i_cap = 100; + add_shortcut( "gtk" ); add_shortcut( "gnome" ); +#elif defined(MODULE_NAME_IS_gtk2_main) + i_cap = 95; + add_shortcut( "gtk2" ); +#elif defined(MODULE_NAME_IS_gnome2_main) + i_cap = 105; + add_shortcut( "gtk2" ); + add_shortcut( "gnome2" ); #endif - add_shortcut( "gtk" ); + set_capability( "gui-helper", i_cap ); set_callbacks( Open, Close ); linked_with_a_crap_library_which_uses_atexit(); vlc_module_end(); @@ -80,17 +86,19 @@ vlc_module_end(); *****************************************************************************/ static int Open( vlc_object_t *p_this ) { - vlc_mutex_lock( p_this->p_vlc->p_global_lock ); + vlc_mutex_t *lock; + + lock = var_AcquireMutex( "gtk" ); if( i_refcount > 0 ) { i_refcount++; - vlc_mutex_unlock( p_this->p_vlc->p_global_lock ); + vlc_mutex_unlock( lock ); return VLC_SUCCESS; } - p_gtk_main = vlc_object_create( p_this, sizeof(gtk_main_t) ); + p_gtk_main = vlc_object_create( p_this, VLC_OBJECT_GENERIC ); /* Only initialize gthreads if it's the first time we do it */ if( !g_thread_supported() ) @@ -103,14 +111,14 @@ static int Open( vlc_object_t *p_this ) if( vlc_thread_create( p_gtk_main, "gtk_main", GtkMain, VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) ) { - vlc_object_destroy( p_gtk_main ); + vlc_object_release( p_gtk_main ); i_refcount--; - vlc_mutex_unlock( p_this->p_vlc->p_global_lock ); + vlc_mutex_unlock( lock ); return VLC_ETHREAD; } i_refcount++; - vlc_mutex_unlock( p_this->p_vlc->p_global_lock ); + vlc_mutex_unlock( lock ); return VLC_SUCCESS; } @@ -120,29 +128,28 @@ static int Open( vlc_object_t *p_this ) *****************************************************************************/ static void Close( vlc_object_t *p_this ) { - vlc_mutex_lock( p_this->p_vlc->p_global_lock ); + vlc_mutex_t *lock; + + lock = var_AcquireMutex( "gtk" ); i_refcount--; if( i_refcount > 0 ) { - vlc_mutex_unlock( p_this->p_vlc->p_global_lock ); + vlc_mutex_unlock( lock ); return; } gtk_main_quit(); vlc_thread_join( p_gtk_main ); - vlc_object_destroy( p_gtk_main ); + vlc_object_release( p_gtk_main ); p_gtk_main = NULL; - vlc_mutex_unlock( p_this->p_vlc->p_global_lock ); + vlc_mutex_unlock( lock ); } -static gint foo(gpointer foo) -{ - return TRUE; -} +static gint foo( gpointer bar ) { return TRUE; } /***************************************************************************** * GtkMain: Gtk+ thread @@ -154,17 +161,24 @@ static void GtkMain( vlc_object_t *p_this ) { /* gtk_init needs to know the command line. We don't care, so we * give it an empty one */ - static char *p_args[] = { "" }; -#ifdef MODULE_NAME_IS_gtk_main + static char *p_args[] = { "", NULL }; +#if defined(MODULE_NAME_IS_gtk_main) || defined(MODULE_NAME_IS_gtk2_main) static char **pp_args = p_args; #endif static int i_args = 1; /* FIXME: deprecated ? */ - /* gdk_threads_init(); */ +#if defined(MODULE_NAME_IS_gtk2_main) || defined(MODULE_NAME_IS_gnome2_main) + gdk_threads_init(); +#endif -#ifdef MODULE_NAME_IS_gnome_main - gnome_init( p_this->p_vlc->psz_object_name, VERSION, i_args, p_args ); +#if defined(MODULE_NAME_IS_gnome_main) + gnome_init( p_this->p_libvlc->psz_object_name, VERSION, i_args, p_args ); +#elif defined(MODULE_NAME_IS_gnome2_main) + gnome_program_init( PACKAGE, VERSION, LIBGNOMEUI_MODULE, + i_args, p_args, + GNOME_PARAM_APP_DATADIR, "",//PACKAGE_DATA_DIR, + NULL ); #else gtk_set_locale(); gtk_init( &i_args, &pp_args ); @@ -174,7 +188,8 @@ static void GtkMain( vlc_object_t *p_this ) vlc_thread_ready( p_this ); - /* If we don't add this simple timeout, gtk_main remains stuck ... */ + /* If we don't add this simple timeout, gtk_main remains stuck if + * we try to close the window without having sent any gtk event. */ gtk_timeout_add( INTF_IDLE_SLEEP / 1000, foo, p_this ); /* Enter Gtk mode */ @@ -182,4 +197,3 @@ static void GtkMain( vlc_object_t *p_this ) gdk_threads_leave(); } -