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 *****************************************************************************/
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 MouseEvent( vlc_object_t *, char const *,
61 vlc_value_t, vlc_value_t, void * );
63 /*****************************************************************************
65 *****************************************************************************/
66 #define THRESHOLD_TEXT N_( "Threshold" )
67 #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface." )
70 set_shortname( "Showintf" )
71 set_description( N_("Show interface with mouse") )
73 set_capability( "interface", 0 )
74 set_callbacks( Open, Close )
76 set_category( CAT_INTERFACE )
77 set_subcategory( SUBCAT_INTERFACE_CONTROL )
79 add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, true )
82 /*****************************************************************************
83 * Open: initialize interface
84 *****************************************************************************/
85 int Open( vlc_object_t *p_this )
87 intf_thread_t *p_intf = (intf_thread_t *)p_this;
89 /* Allocate instance and initialize some members */
90 intf_sys_t *p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
94 vlc_mutex_init( &p_sys->lock );
96 p_sys->b_button_pressed = false;
97 p_sys->b_triggered = false;
98 p_sys->i_threshold = config_GetInt( p_intf, "showintf-threshold" );
100 p_intf->pf_run = RunIntf;
105 /*****************************************************************************
106 * Close: destroy interface
107 *****************************************************************************/
108 void Close( vlc_object_t *p_this )
110 intf_thread_t *p_intf = (intf_thread_t *)p_this;
112 /* Destroy structure */
113 vlc_mutex_destroy( &p_intf->p_sys->lock );
114 free( p_intf->p_sys );
118 /*****************************************************************************
120 *****************************************************************************/
121 static void RunIntf( intf_thread_t *p_intf )
123 int canc = vlc_savecancel( );
126 while( vlc_object_alive( p_intf ) )
128 vlc_mutex_lock( &p_intf->p_sys->lock );
130 /* Notify the interfaces */
131 if( p_intf->p_sys->b_triggered )
133 var_SetBool( p_intf->p_libvlc, "intf-show", true );
134 p_intf->p_sys->b_triggered = false;
137 vlc_mutex_unlock( &p_intf->p_sys->lock );
140 /* Take care of the video output */
141 if( p_intf->p_sys->p_vout && !vlc_object_alive (p_intf->p_sys->p_vout) )
143 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
144 MouseEvent, p_intf );
145 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
146 MouseEvent, p_intf );
147 vlc_object_release( p_intf->p_sys->p_vout );
148 p_intf->p_sys->p_vout = NULL;
151 if( p_intf->p_sys->p_vout == NULL )
153 p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
155 if( p_intf->p_sys->p_vout )
157 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
158 MouseEvent, p_intf );
159 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
160 MouseEvent, p_intf );
165 msleep( INTF_IDLE_SLEEP );
168 if( p_intf->p_sys->p_vout )
170 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
171 MouseEvent, p_intf );
172 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
173 MouseEvent, p_intf );
174 vlc_object_release( p_intf->p_sys->p_vout );
176 vlc_restorecancel( canc );
179 /*****************************************************************************
180 * MouseEvent: callback for mouse events
181 *****************************************************************************/
182 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
183 vlc_value_t oldval, vlc_value_t newval, void *p_data )
185 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(newval);
187 int i_mouse_x, i_mouse_y;
188 intf_thread_t *p_intf = (intf_thread_t *)p_data;
190 /* Do nothing when the interface is already requested */
191 if( p_intf->p_sys->b_triggered )
194 /* Nothing to do when not in fullscreen mode */
195 if( !var_GetBool( p_intf->p_sys->p_vout, "fullscreen" ) )
198 vlc_mutex_lock( &p_intf->p_sys->lock );
199 if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
201 i_mouse_x = var_GetInteger( p_intf->p_sys->p_vout, "mouse-x" );
202 i_mouse_y = var_GetInteger( p_intf->p_sys->p_vout, "mouse-y" );
204 /* Very basic test, we even ignore the x value :) */
205 if ( i_mouse_y < p_intf->p_sys->i_threshold )
207 msg_Dbg( p_intf, "interface showing requested" );
208 p_intf->p_sys->b_triggered = true;
212 /* We keep track of the button state to avoid interferences with the
214 if( !p_intf->p_sys->b_button_pressed &&
215 !strcmp( psz_var, "mouse-button-down" ) )
217 p_intf->p_sys->b_button_pressed = true;
219 if( p_intf->p_sys->b_button_pressed &&
220 !strcmp( psz_var, "mouse-button-down" ) )
222 p_intf->p_sys->b_button_pressed = false;
225 vlc_mutex_unlock( &p_intf->p_sys->lock );