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