1 /*****************************************************************************
2 * showintf.c: control the display of the interface in fullscreen mode
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_interface.h>
36 #include <vlc_playlist.h>
42 /*****************************************************************************
43 * intf_sys_t: description and status of interface
44 *****************************************************************************/
48 vlc_object_t * p_vout;
49 bool b_button_pressed;
54 /*****************************************************************************
56 *****************************************************************************/
57 int Open ( vlc_object_t * );
58 void Close( vlc_object_t * );
59 static void RunIntf( intf_thread_t *p_intf );
60 static int InitThread( intf_thread_t *p_intf );
61 static int MouseEvent( vlc_object_t *, char const *,
62 vlc_value_t, vlc_value_t, void * );
64 /*****************************************************************************
66 *****************************************************************************/
67 #define THRESHOLD_TEXT N_( "Threshold" )
68 #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface." )
71 set_shortname( "Showintf" )
72 add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, true )
73 set_description( N_("Show interface with mouse") )
75 set_capability( "interface", 0 )
76 set_callbacks( Open, Close )
79 /*****************************************************************************
80 * Open: initialize interface
81 *****************************************************************************/
82 int Open( vlc_object_t *p_this )
84 intf_thread_t *p_intf = (intf_thread_t *)p_this;
86 /* Allocate instance and initialize some members */
87 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
88 if( p_intf->p_sys == NULL )
93 vlc_mutex_init( &p_intf->p_sys->lock );
94 p_intf->pf_run = RunIntf;
99 /*****************************************************************************
100 * Close: destroy interface
101 *****************************************************************************/
102 void Close( vlc_object_t *p_this )
104 intf_thread_t *p_intf = (intf_thread_t *)p_this;
106 /* Destroy structure */
107 vlc_mutex_destroy( &p_intf->p_sys->lock );
108 free( p_intf->p_sys );
112 /*****************************************************************************
114 *****************************************************************************/
115 static void RunIntf( intf_thread_t *p_intf )
117 int canc = vlc_savecancel( );
118 p_intf->p_sys->p_vout = NULL;
120 if( InitThread( p_intf ) < 0 )
122 msg_Err( p_intf, "cannot initialize interface" );
127 while( vlc_object_alive( p_intf ) )
129 vlc_mutex_lock( &p_intf->p_sys->lock );
131 /* Notify the interfaces */
132 if( p_intf->p_sys->b_triggered )
134 var_SetBool( p_intf->p_libvlc, "intf-show", true );
135 p_intf->p_sys->b_triggered = false;
138 vlc_mutex_unlock( &p_intf->p_sys->lock );
141 /* Take care of the video output */
142 if( p_intf->p_sys->p_vout && !vlc_object_alive (p_intf->p_sys->p_vout) )
144 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
145 MouseEvent, p_intf );
146 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
147 MouseEvent, p_intf );
148 vlc_object_release( p_intf->p_sys->p_vout );
149 p_intf->p_sys->p_vout = NULL;
152 if( p_intf->p_sys->p_vout == NULL )
154 p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
156 if( p_intf->p_sys->p_vout )
158 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
159 MouseEvent, p_intf );
160 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
161 MouseEvent, p_intf );
166 msleep( INTF_IDLE_SLEEP );
169 if( p_intf->p_sys->p_vout )
171 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
172 MouseEvent, p_intf );
173 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
174 MouseEvent, p_intf );
175 vlc_object_release( p_intf->p_sys->p_vout );
177 vlc_restorecancel( canc );
180 /*****************************************************************************
182 *****************************************************************************/
183 static int InitThread( intf_thread_t * p_intf )
185 if( vlc_object_alive( p_intf ) )
187 vlc_mutex_lock( &p_intf->p_sys->lock );
189 p_intf->p_sys->b_triggered = false;
190 p_intf->p_sys->b_button_pressed = false;
191 p_intf->p_sys->i_threshold =
192 config_GetInt( p_intf, "showintf-threshold" );
194 vlc_mutex_unlock( &p_intf->p_sys->lock );
204 /*****************************************************************************
205 * MouseEvent: callback for mouse events
206 *****************************************************************************/
207 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
208 vlc_value_t oldval, vlc_value_t newval, void *p_data )
210 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(newval);
213 int i_mouse_x, i_mouse_y;
214 intf_thread_t *p_intf = (intf_thread_t *)p_data;
216 /* Do nothing when the interface is already requested */
217 if( p_intf->p_sys->b_triggered )
220 /* Nothing to do when not in fullscreen mode */
221 var_Get( p_intf->p_sys->p_vout, "fullscreen", &val );
225 vlc_mutex_lock( &p_intf->p_sys->lock );
226 if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
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;
233 /* Very basic test, we even ignore the x value :) */
234 if ( i_mouse_y < p_intf->p_sys->i_threshold )
236 msg_Dbg( p_intf, "interface showing requested" );
237 p_intf->p_sys->b_triggered = true;
241 /* We keep track of the button state to avoid interferences with the
243 if( !p_intf->p_sys->b_button_pressed &&
244 !strcmp( psz_var, "mouse-button-down" ) )
246 p_intf->p_sys->b_button_pressed = true;
248 if( p_intf->p_sys->b_button_pressed &&
249 !strcmp( psz_var, "mouse-button-down" ) )
251 p_intf->p_sys->b_button_pressed = false;
254 vlc_mutex_unlock( &p_intf->p_sys->lock );