1 /*****************************************************************************
2 * gtk2.c : Gtk2 plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
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., 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 "gtk2_callbacks.h"
38 #include "gtk2_interface.h"
39 #include "gtk2_support.h"
41 /*****************************************************************************
43 *****************************************************************************/
44 static int Open ( vlc_object_t * );
45 static void Close ( vlc_object_t * );
47 static void Run ( intf_thread_t * );
48 static int Manage ( intf_thread_t * );
50 /*****************************************************************************
52 *****************************************************************************/
54 int i = getenv( "DISPLAY" ) == NULL ? 15 : 95;
55 set_category( CAT_INTERFACE );
56 set_subcategory( SUBCAT_INTERFACE_GENERAL );
57 set_description( _("Gtk2 interface") );
58 set_capability( "interface", i );
59 set_callbacks( Open, Close );
60 set_program( "gvlc" );
63 /*****************************************************************************
65 *****************************************************************************/
68 module_t *p_gui_helper;
73 /*****************************************************************************
74 * Open: initialize and create window
75 *****************************************************************************/
76 static int Open( vlc_object_t *p_this )
78 intf_thread_t *p_intf = (intf_thread_t *)p_this;
80 /* Allocate instance and initialize some members */
81 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
82 if( p_intf->p_sys == NULL )
84 msg_Err( p_intf, "out of memory" );
89 p_intf->p_sys->p_gui_helper =
90 module_Need( p_this, "gui-helper", "gtk2", VLC_TRUE );
91 if( p_intf->p_sys->p_gui_helper == NULL )
93 free( p_intf->p_sys );
103 /*****************************************************************************
104 * Close: destroy interface window
105 *****************************************************************************/
106 static void Close( vlc_object_t *p_this )
108 intf_thread_t *p_intf = (intf_thread_t *)p_this;
110 #ifdef NEED_GTK2_MAIN
111 module_Unneed( p_intf, p_intf->p_sys->p_gui_helper );
114 /* Destroy structure */
115 free( p_intf->p_sys );
118 /*****************************************************************************
120 *****************************************************************************
121 * this part of the interface is in a separate thread so that we can call
122 * gtk_main() from within it without annoying the rest of the program.
123 *****************************************************************************/
124 static void Run( intf_thread_t *p_intf )
126 #ifdef NEED_GTK2_MAIN
129 /* gtk_init needs to know the command line. We don't care, so we
130 * give it an empty one */
131 char *p_args[] = { "", NULL };
132 char **pp_args = p_args;
137 gtk_init( &i_args, &pp_args );
140 /* Create some useful widgets that will certainly be used */
141 p_intf->p_sys->p_window = create_window1();
143 /* Set the title of the main window */
144 gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
145 VOUT_TITLE " (Gtk2 interface)");
147 /* Show the control window */
148 gtk_widget_show( p_intf->p_sys->p_window );
150 #ifdef NEED_GTK2_MAIN
151 while( !p_intf->b_die )
155 /* Sleep to avoid using all CPU - since some interfaces need to
156 * access keyboard events, a 100ms delay is a good compromise */
158 msleep( INTF_IDLE_SLEEP );
162 /* Sleep to avoid using all CPU - since some interfaces needs to access
163 * keyboard events, a 100ms delay is a good compromise */
164 i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage,
168 /* Remove the timeout */
169 gtk_timeout_remove( i_dummy );
172 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
174 #ifdef NEED_GTK2_MAIN
179 /* following functions are local */
181 /*****************************************************************************
182 * Manage: manage main thread messages
183 *****************************************************************************
184 * In this function, called approx. 10 times a second, we check what the
185 * main program wanted to tell us.
186 *****************************************************************************/
187 static int Manage( intf_thread_t *p_intf )
189 #ifndef NEED_GTK2_MAIN