]> git.sesse.net Git - vlc/blob - modules/control/showintf.c
* control/http: fix "pl.current"
[vlc] / modules / control / showintf.c
1 /*****************************************************************************
2  * showintf.c: control the display of the interface in fullscreen mode
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/intf.h>
32 #include <vlc/vout.h>
33
34 #ifdef HAVE_UNISTD_H
35 #    include <unistd.h>
36 #endif
37
38 /*****************************************************************************
39  * intf_sys_t: description and status of interface
40  *****************************************************************************/
41 struct intf_sys_t
42 {
43     vlc_object_t * p_vout;
44     vlc_bool_t     b_button_pressed;
45     vlc_bool_t     b_triggered;
46     int            i_threshold;
47 };
48
49 /*****************************************************************************
50  * Local prototypes.
51  *****************************************************************************/
52 int  E_(Open) ( vlc_object_t * );
53 void E_(Close)( vlc_object_t * );
54 static void RunIntf( intf_thread_t *p_intf );
55 static int  InitThread( intf_thread_t *p_intf );
56 static int  MouseEvent( vlc_object_t *, char const *,
57                         vlc_value_t, vlc_value_t, void * );
58
59 /*****************************************************************************
60  * Module descriptor
61  *****************************************************************************/
62 #define THRESHOLD_TEXT N_( "Threshold" )
63 #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface." )
64
65 vlc_module_begin();
66     set_shortname( "Showintf" );
67     add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, VLC_TRUE );
68     set_description( _("Show interface with mouse") );
69
70     set_capability( "interface", 0 );
71     set_callbacks( E_(Open), E_(Close) );
72 vlc_module_end();
73
74 /*****************************************************************************
75  * Open: initialize interface
76  *****************************************************************************/
77 int E_(Open)( vlc_object_t *p_this )
78 {
79     intf_thread_t *p_intf = (intf_thread_t *)p_this;
80
81     /* Allocate instance and initialize some members */
82     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
83     if( p_intf->p_sys == NULL )
84     {
85         return( 1 );
86     };
87
88     p_intf->pf_run = RunIntf;
89
90     return( 0 );
91 }
92
93 /*****************************************************************************
94  * Close: destroy interface
95  *****************************************************************************/
96 void E_(Close)( vlc_object_t *p_this )
97 {
98     intf_thread_t *p_intf = (intf_thread_t *)p_this;
99
100     /* Destroy structure */
101     free( p_intf->p_sys );
102 }
103
104
105 /*****************************************************************************
106  * RunIntf: main loop
107  *****************************************************************************/
108 static void RunIntf( intf_thread_t *p_intf )
109 {
110     p_intf->p_sys->p_vout = NULL;
111
112     if( InitThread( p_intf ) < 0 )
113     {
114         msg_Err( p_intf, "cannot initialize interface" );
115         return;
116     }
117
118     /* Main loop */
119     while( !p_intf->b_die )
120     {
121         vlc_mutex_lock( &p_intf->change_lock );
122
123         /* Notify the interfaces */
124         if( p_intf->p_sys->b_triggered )
125         {
126             playlist_t *p_playlist =
127                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
128                                                FIND_ANYWHERE );
129
130             if( p_playlist != NULL )
131             {
132                 vlc_value_t val;
133                 val.b_bool = VLC_TRUE;
134                 var_Set( p_playlist, "intf-show", val );
135                 vlc_object_release( p_playlist );
136             }
137             p_intf->p_sys->b_triggered = VLC_FALSE;
138         }
139
140         vlc_mutex_unlock( &p_intf->change_lock );
141
142
143         /* Take care of the video output */
144         if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die )
145         {
146             var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
147                              MouseEvent, p_intf );
148             var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
149                              MouseEvent, p_intf );
150             vlc_object_release( p_intf->p_sys->p_vout );
151             p_intf->p_sys->p_vout = NULL;
152         }
153
154         if( p_intf->p_sys->p_vout == NULL )
155         {
156             p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
157                                                      FIND_ANYWHERE );
158             if( p_intf->p_sys->p_vout )
159             {
160                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
161                                  MouseEvent, p_intf );
162                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
163                                  MouseEvent, p_intf );
164             }
165         }
166
167         /* Wait a bit */
168         msleep( INTF_IDLE_SLEEP );
169     }
170
171     if( p_intf->p_sys->p_vout )
172     {
173         var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
174                          MouseEvent, p_intf );
175         var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
176                          MouseEvent, p_intf );
177         vlc_object_release( p_intf->p_sys->p_vout );
178     }
179 }
180
181 /*****************************************************************************
182  * InitThread:
183  *****************************************************************************/
184 static int InitThread( intf_thread_t * p_intf )
185 {
186     if( !p_intf->b_die )
187     {
188         vlc_mutex_lock( &p_intf->change_lock );
189
190         p_intf->p_sys->b_triggered = VLC_FALSE;
191         p_intf->p_sys->b_button_pressed = VLC_FALSE;
192         p_intf->p_sys->i_threshold =
193             config_GetInt( p_intf, "showintf-threshold" );
194
195         vlc_mutex_unlock( &p_intf->change_lock );
196
197         return 0;
198     }
199     else
200     {
201         return -1;
202     }
203 }
204
205 /*****************************************************************************
206  * MouseEvent: callback for mouse events
207  *****************************************************************************/
208 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
209                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
210 {
211     vlc_value_t val;
212
213     int i_mouse_x, i_mouse_y;
214     intf_thread_t *p_intf = (intf_thread_t *)p_data;
215
216     /* Do nothing when the interface is already requested */
217     if( p_intf->p_sys->b_triggered )
218         return VLC_SUCCESS;
219
220     /* Nothing to do when not in fullscreen mode */
221     var_Get( p_intf->p_sys->p_vout, "fullscreen", &val );
222     if( !val.i_int )
223         return VLC_SUCCESS;
224
225     vlc_mutex_lock( &p_intf->change_lock );
226     if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
227     {
228         var_Get( p_intf->p_sys->p_vout, "mouse-x", &val );
229         i_mouse_x = val.i_int;
230         var_Get( p_intf->p_sys->p_vout, "mouse-y", &val );
231         i_mouse_y = val.i_int;
232
233         /* Very basic test, we even ignore the x value :) */
234         if ( i_mouse_y < p_intf->p_sys->i_threshold )
235         {
236             msg_Dbg( p_intf, "interface showing requested" );
237             p_intf->p_sys->b_triggered = VLC_TRUE;
238         }
239     }
240
241     /* We keep track of the button state to avoid interferences with the
242      * gestures plugin */
243     if( !p_intf->p_sys->b_button_pressed &&
244         !strcmp( psz_var, "mouse-button-down" ) )
245     {
246         p_intf->p_sys->b_button_pressed = VLC_TRUE;
247     }
248     if( p_intf->p_sys->b_button_pressed &&
249         !strcmp( psz_var, "mouse-button-down" ) )
250     {
251         p_intf->p_sys->b_button_pressed = VLC_FALSE;
252     }
253
254     vlc_mutex_unlock( &p_intf->change_lock );
255
256     return VLC_SUCCESS;
257 }