]> git.sesse.net Git - vlc/blob - modules/gui/gtk2/gnome2.c
* async_queue.*: AsyncQueue::remove is now thread-safe to avoid potential
[vlc] / modules / gui / gtk2 / gnome2.c
1 /*****************************************************************************
2  * gnome2.c : GNOME 2 plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: gnome2.c,v 1.3 2004/03/03 20:39:52 gbazin Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/intf.h>
34
35 #include <gnome.h>
36
37 #include "gnome2_interface.h"
38 #include "gnome2_support.h"
39
40 /*****************************************************************************
41  * Local prototypes.
42  *****************************************************************************/
43 static int  Open         ( vlc_object_t * );
44 static void Close        ( vlc_object_t * );
45
46 static void Run          ( intf_thread_t * );
47 static int  Manage       ( intf_thread_t * );
48
49 /*****************************************************************************
50  * Module descriptor
51  *****************************************************************************/
52 vlc_module_begin();
53     int i = getenv( "DISPLAY" ) == NULL ? 15 : 95;
54     set_description( _("Gtk2 interface") );
55     set_capability( "interface", i );
56     set_callbacks( Open, Close );
57     set_program( "gvlc" );
58 vlc_module_end();
59
60 /*****************************************************************************
61  * intf_sys_t
62  *****************************************************************************/
63 struct intf_sys_t
64 {
65     module_t *p_gui_helper;
66
67     GtkWidget *p_app;
68 };
69
70 /*****************************************************************************
71  * Open: initialize and create window
72  *****************************************************************************/
73 static int Open( vlc_object_t *p_this )
74 {
75     intf_thread_t *p_intf = (intf_thread_t *)p_this;
76
77     /* Allocate instance and initialize some members */
78     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
79     if( p_intf->p_sys == NULL )
80     {
81         msg_Err( p_intf, "out of memory" );
82         return VLC_ENOMEM;
83     }
84
85 #ifdef NEED_GTK2_MAIN
86     p_intf->p_sys->p_gui_helper =
87         module_Need( p_this, "gui-helper", "gnome2", VLC_TRUE );
88     if( p_intf->p_sys->p_gui_helper == NULL )
89     {
90         free( p_intf->p_sys );
91         return VLC_ENOMOD;
92     }
93 #endif
94
95     p_intf->pf_run = Run;
96
97     return VLC_SUCCESS;
98 }
99
100 /*****************************************************************************
101  * Close: destroy interface window
102  *****************************************************************************/
103 static void Close( vlc_object_t *p_this )
104 {
105     intf_thread_t *p_intf = (intf_thread_t *)p_this;
106
107 #ifdef NEED_GTK2_MAIN
108     module_Unneed( p_intf, p_intf->p_sys->p_gui_helper );
109 #endif
110
111     /* Destroy structure */
112     free( p_intf->p_sys );
113 }
114
115 /*****************************************************************************
116  * Run: Gtk+ thread
117  *****************************************************************************
118  * this part of the interface is in a separate thread so that we can call
119  * gtk_main() from within it without annoying the rest of the program.
120  *****************************************************************************/
121 static void Run( intf_thread_t *p_intf )
122 {
123 #ifdef NEED_GTK2_MAIN
124     gdk_threads_enter();
125 #else
126     /* gnome_program_init needs to know the command line. We don't care, so
127      * we give it an empty one */
128     char  *p_args[] = { "", NULL };
129     int    i_args   = 1;
130     int    i_dummy;
131
132     gtk_set_locale();
133     gnome_program_init( PACKAGE, VERSION, LIBGNOMEUI_MODULE,
134                         i_args, p_args,
135                         GNOME_PARAM_APP_DATADIR, "",//PACKAGE_DATA_DIR,
136                         NULL );
137 #endif
138
139     /* Create some useful widgets that will certainly be used */
140     p_intf->p_sys->p_app = create_app1();
141
142     /* Set the title of the main window */
143     //gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_app),
144     //                      VOUT_TITLE " (Gtk+ interface)" );
145
146     /* Show the control window */
147     gtk_widget_show( p_intf->p_sys->p_app );
148
149 #ifdef NEED_GTK2_MAIN
150     while( !p_intf->b_die )
151     {
152         Manage( p_intf );
153
154         /* Sleep to avoid using all CPU - since some interfaces need to
155          * access keyboard events, a 100ms delay is a good compromise */
156         gdk_threads_leave();
157         msleep( INTF_IDLE_SLEEP );
158         gdk_threads_enter();
159     }
160 #else
161     /* Sleep to avoid using all CPU - since some interfaces needs to access
162      * keyboard events, a 100ms delay is a good compromise */
163     i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage,
164                                p_intf );
165     /* Enter Gtk mode */
166     gtk_main();
167     /* Remove the timeout */
168     gtk_timeout_remove( i_dummy );
169 #endif
170
171     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_app) );
172
173 #ifdef NEED_GTK2_MAIN
174     gdk_threads_leave();
175 #endif
176 }
177
178 /* following functions are local */
179
180 /*****************************************************************************
181  * Manage: manage main thread messages
182  *****************************************************************************
183  * In this function, called approx. 10 times a second, we check what the
184  * main program wanted to tell us.
185  *****************************************************************************/
186 static int Manage( intf_thread_t *p_intf )
187 {
188 #ifndef NEED_GTK2_MAIN
189     if( p_intf->b_die )
190     {
191         gtk_main_quit();
192
193         return FALSE;
194     }
195 #endif
196
197     return TRUE;
198 }