1 /*****************************************************************************
2 * familiar.c : familiar plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: familiar.c,v 1.7 2002/07/31 20:56:51 sam Exp $
7 * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
37 #include "familiar_callbacks.h"
38 #include "familiar_interface.h"
39 #include "familiar_support.h"
42 /*****************************************************************************
43 * Local variables (mutex-protected).
44 *****************************************************************************/
45 static void ** pp_global_data = NULL;
47 /*****************************************************************************
48 * g_atexit: kludge to avoid the Gtk+ thread to segfault at exit
49 *****************************************************************************
50 * gtk_init() makes several calls to g_atexit() which calls atexit() to
51 * register tidying callbacks to be called at program exit. Since the Gtk+
52 * plugin is likely to be unloaded at program exit, we have to export this
53 * symbol to intercept the g_atexit() calls. Talk about crude hack.
54 *****************************************************************************/
55 void g_atexit( GVoidFunc func )
57 intf_thread_t *p_intf;
61 if( pp_global_data == NULL )
67 p_intf = (intf_thread_t *)*pp_global_data;
74 i_dummy < MAX_ATEXIT && p_intf->p_sys->pf_callback[i_dummy] != NULL;
80 if( i_dummy >= MAX_ATEXIT - 1 )
82 msg_Err( p_intf, "too many atexit() callbacks to register" );
86 p_intf->p_sys->pf_callback[i_dummy] = func;
87 p_intf->p_sys->pf_callback[i_dummy + 1] = NULL;
90 /*****************************************************************************
92 *****************************************************************************/
93 static int Open ( vlc_object_t * );
94 static void Close ( vlc_object_t * );
96 static void Run ( intf_thread_t * );
98 /*****************************************************************************
100 *****************************************************************************/
102 set_description( _("Familiar Linux Gtk+ interface module") );
103 set_capability( "interface", 70 );
104 set_callbacks( Open, Close );
107 /*****************************************************************************
108 * Open: initialize and create window
109 *****************************************************************************/
110 static int Open( vlc_object_t *p_this )
112 intf_thread_t *p_intf = (intf_thread_t *)p_this;
114 /* Allocate instance and initialize some members */
115 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
116 if( p_intf->p_sys == NULL )
118 msg_Err( p_intf, "out of memory" );
122 /* Initialize Gtk+ thread */
123 p_intf->p_sys->p_input = NULL;
125 p_intf->pf_run = Run;
130 /*****************************************************************************
131 * Close: destroy interface window
132 *****************************************************************************/
133 static void Close( vlc_object_t *p_this )
135 intf_thread_t *p_intf = (intf_thread_t *)p_this;
137 if( p_intf->p_sys->p_input )
139 vlc_object_release( p_intf->p_sys->p_input );
142 /* Destroy structure */
143 if (p_intf->p_sys) free( p_intf->p_sys );
146 /*****************************************************************************
148 *****************************************************************************
149 * this part of the interface is in a separate thread so that we can call
150 * gtk_main() from within it without annoying the rest of the program.
151 * XXX: the approach may look kludgy, and probably is, but I could not find
152 * a better way to dynamically load a Gtk+ interface at runtime.
153 *****************************************************************************/
154 static void Run( intf_thread_t *p_intf )
156 /* gtk_init needs to know the command line. We don't care, so we
157 * give it an empty one */
158 char *p_args[] = { "" };
159 char **pp_args = p_args;
163 /* Initialize Gtk+ */
166 /* gtk_init will register stuff with g_atexit, so we need to take
167 * the global lock if we want to be able to intercept the calls */
168 vlc_mutex_lock( p_intf->p_vlc->p_global_lock );
169 *p_intf->p_vlc->pp_global_data = p_intf;
170 gtk_init( &i_args, &pp_args );
171 vlc_mutex_unlock( p_intf->p_vlc->p_global_lock );
173 /* Create some useful widgets that will certainly be used */
175 add_pixmap_directory("share");
176 p_intf->p_sys->p_window = create_familiar();
177 if (p_intf->p_sys->p_window == NULL)
179 msg_Err( p_intf, "unable to create familiar interface" );
182 /* Set the title of the main window */
183 gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
184 VOUT_TITLE " (Familiar Linux interface)");
186 /* Get the slider object */
187 p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
188 GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
189 // gtk_widget_hide( GTK_WIDGET(p_intf->p_sys->p_notebook) );
191 /* Store p_intf to keep an eye on it */
192 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
194 /* Show the control window */
195 gtk_widget_show( p_intf->p_sys->p_window );
200 /* Remove the timeout */
201 gtk_timeout_remove( i_dummy );