1 /*****************************************************************************
2 * gtk2.c : Gtk2 plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: gtk2.c,v 1.3 2004/03/03 20:39:52 gbazin Exp $
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_description( _("Gtk2 interface") );
56 set_capability( "interface", i );
57 set_callbacks( Open, Close );
58 set_program( "gvlc" );
61 /*****************************************************************************
63 *****************************************************************************/
66 module_t *p_gui_helper;
71 /*****************************************************************************
72 * Open: initialize and create window
73 *****************************************************************************/
74 static int Open( vlc_object_t *p_this )
76 intf_thread_t *p_intf = (intf_thread_t *)p_this;
78 /* Allocate instance and initialize some members */
79 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
80 if( p_intf->p_sys == NULL )
82 msg_Err( p_intf, "out of memory" );
87 p_intf->p_sys->p_gui_helper =
88 module_Need( p_this, "gui-helper", "gtk2", VLC_TRUE );
89 if( p_intf->p_sys->p_gui_helper == NULL )
91 free( p_intf->p_sys );
101 /*****************************************************************************
102 * Close: destroy interface window
103 *****************************************************************************/
104 static void Close( vlc_object_t *p_this )
106 intf_thread_t *p_intf = (intf_thread_t *)p_this;
108 #ifdef NEED_GTK2_MAIN
109 module_Unneed( p_intf, p_intf->p_sys->p_gui_helper );
112 /* Destroy structure */
113 free( p_intf->p_sys );
116 /*****************************************************************************
118 *****************************************************************************
119 * this part of the interface is in a separate thread so that we can call
120 * gtk_main() from within it without annoying the rest of the program.
121 *****************************************************************************/
122 static void Run( intf_thread_t *p_intf )
124 #ifdef NEED_GTK2_MAIN
127 /* gtk_init needs to know the command line. We don't care, so we
128 * give it an empty one */
129 char *p_args[] = { "", NULL };
130 char **pp_args = p_args;
135 gtk_init( &i_args, &pp_args );
138 /* Create some useful widgets that will certainly be used */
139 p_intf->p_sys->p_window = create_window1();
141 /* Set the title of the main window */
142 gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
143 VOUT_TITLE " (Gtk2 interface)");
145 /* Show the control window */
146 gtk_widget_show( p_intf->p_sys->p_window );
148 #ifdef NEED_GTK2_MAIN
149 while( !p_intf->b_die )
153 /* Sleep to avoid using all CPU - since some interfaces need to
154 * access keyboard events, a 100ms delay is a good compromise */
156 msleep( INTF_IDLE_SLEEP );
160 /* Sleep to avoid using all CPU - since some interfaces needs to access
161 * keyboard events, a 100ms delay is a good compromise */
162 i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage,
166 /* Remove the timeout */
167 gtk_timeout_remove( i_dummy );
170 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
172 #ifdef NEED_GTK2_MAIN
177 /* following functions are local */
179 /*****************************************************************************
180 * Manage: manage main thread messages
181 *****************************************************************************
182 * In this function, called approx. 10 times a second, we check what the
183 * main program wanted to tell us.
184 *****************************************************************************/
185 static int Manage( intf_thread_t *p_intf )
187 #ifndef NEED_GTK2_MAIN