gtk_main.c
资源名称:vlc-1.0.5.zip [点击查看]
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:6k
源码类别:
midi
开发平台:
Unix_Linux
- /*****************************************************************************
- * gtk_main.c : Gtk+ wrapper for gtk_main
- *****************************************************************************
- * Copyright (C) 2002 the VideoLAN team
- * $Id: b127e5a8f69c0e08adefb645f867b7c7a42bdc14 $
- *
- * Authors: Samuel Hocevar <sam@zoy.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * 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
- * GNU General Public License for more details.
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
- /*****************************************************************************
- * Preamble
- *****************************************************************************/
- #ifdef HAVE_CONFIG_H
- # include "config.h"
- #endif
- #include <vlc_common.h>
- #include <vlc_plugin.h>
- #include <gtk/gtk.h>
- #if defined(MODULE_NAME_IS_gtk2_main)
- # include <glib.h>
- #endif
- #if defined(MODULE_NAME_IS_gnome_main) || defined(MODULE_NAME_IS_gnome2_main)
- # include <gnome.h>
- #endif
- /*****************************************************************************
- * Local prototypes.
- *****************************************************************************/
- static int Open ( vlc_object_t * );
- static void Close ( vlc_object_t * );
- static void* GtkMain ( vlc_object_t * );
- /*****************************************************************************
- * Local variables (mutex-protected).
- *****************************************************************************/
- static int i_refcount = 0;
- static vlc_object_t * p_gtk_main = NULL;
- /*****************************************************************************
- * Module descriptor
- *****************************************************************************/
- vlc_module_begin ()
- int i_cap;
- set_description( N_("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
- set_capability( "gui-helper", i_cap )
- set_callbacks( Open, Close )
- linked_with_a_crap_library_which_uses_atexit ()
- vlc_module_end ()
- static vlc_mutex_t gtk_lock = VLC_STATIC_MUTEX;
- /*****************************************************************************
- * Open: initialize and create window
- *****************************************************************************/
- static int Open( vlc_object_t *p_this )
- {
- vlc_mutex_lock( >k_lock );
- if( i_refcount > 0 )
- {
- i_refcount++;
- vlc_mutex_unlock( >k_lock );
- return VLC_SUCCESS;
- }
- p_gtk_main = vlc_object_create( p_this, sizeof( vlc_object_t ) );
- /* Only initialize gthreads if it's the first time we do it */
- if( !g_thread_supported() )
- {
- g_thread_init( NULL );
- }
- /* Launch the gtk_main() thread. It will not return until it has
- * called gdk_threads_enter(), which ensures us thread safety. */
- if( vlc_thread_create( p_gtk_main, "gtk_main", GtkMain,
- VLC_THREAD_PRIORITY_LOW ) )
- {
- vlc_object_release( p_gtk_main );
- i_refcount--;
- vlc_mutex_unlock( >k_lock );
- return VLC_ETHREAD;
- }
- i_refcount++;
- vlc_mutex_unlock( >k_lock );
- return VLC_SUCCESS;
- }
- /*****************************************************************************
- * Close: destroy interface window
- *****************************************************************************/
- static void Close( vlc_object_t *p_this )
- {
- vlc_mutex_lock( >k_lock );
- i_refcount--;
- if( --i_refcount == 0 )
- {
- gtk_main_quit();
- vlc_thread_join( p_gtk_main );
- vlc_object_release( p_gtk_main );
- p_gtk_main = NULL;
- }
- vlc_mutex_unlock( >k_lock );
- }
- static gint foo( gpointer bar ) { return TRUE; }
- /*****************************************************************************
- * GtkMain: Gtk+ thread
- *****************************************************************************
- * this part of the interface is in a separate thread so that we can call
- * gtk_main() from within it without annoying the rest of the program.
- *****************************************************************************/
- 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[] = { "", 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;
- int canc = vlc_savecancel ();
- /* FIXME: deprecated ? */
- #if defined(MODULE_NAME_IS_gtk2_main) || defined(MODULE_NAME_IS_gnome2_main)
- gdk_threads_init();
- #endif
- #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 );
- #endif
- gdk_threads_enter();
- vlc_thread_ready( p_this );
- /* 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 */
- gtk_main();
- gdk_threads_leave();
- vlc_restorecancel (canc);
- return NULL;
- }