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 *****************************************************************************/
33 #include <vlc_interface.h>
35 #include <vlc_playlist.h>
41 /*****************************************************************************
42 * intf_sys_t: description and status of interface
43 *****************************************************************************/
46 vlc_object_t * p_vout;
47 vlc_bool_t b_button_pressed;
48 vlc_bool_t b_triggered;
52 /*****************************************************************************
54 *****************************************************************************/
55 int E_(Open) ( vlc_object_t * );
56 void E_(Close)( vlc_object_t * );
57 static void RunIntf( intf_thread_t *p_intf );
58 static int InitThread( intf_thread_t *p_intf );
59 static int MouseEvent( vlc_object_t *, char const *,
60 vlc_value_t, vlc_value_t, void * );
62 /*****************************************************************************
64 *****************************************************************************/
65 #define THRESHOLD_TEXT N_( "Threshold" )
66 #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface." )
69 set_shortname( "Showintf" );
70 add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, VLC_TRUE );
71 set_description( _("Show interface with mouse") );
73 set_capability( "interface", 0 );
74 set_callbacks( E_(Open), E_(Close) );
77 /*****************************************************************************
78 * Open: initialize interface
79 *****************************************************************************/
80 int E_(Open)( vlc_object_t *p_this )
82 intf_thread_t *p_intf = (intf_thread_t *)p_this;
84 /* Allocate instance and initialize some members */
85 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
86 if( p_intf->p_sys == NULL )
91 p_intf->pf_run = RunIntf;
96 /*****************************************************************************
97 * Close: destroy interface
98 *****************************************************************************/
99 void E_(Close)( vlc_object_t *p_this )
101 intf_thread_t *p_intf = (intf_thread_t *)p_this;
103 /* Destroy structure */
104 free( p_intf->p_sys );
108 /*****************************************************************************
110 *****************************************************************************/
111 static void RunIntf( intf_thread_t *p_intf )
113 p_intf->p_sys->p_vout = NULL;
115 if( InitThread( p_intf ) < 0 )
117 msg_Err( p_intf, "cannot initialize interface" );
122 while( !intf_ShouldDie( p_intf ) )
124 vlc_mutex_lock( &p_intf->change_lock );
126 /* Notify the interfaces */
127 if( p_intf->p_sys->b_triggered )
129 playlist_t *p_playlist = pl_Yield( p_intf );
130 var_SetBool( p_playlist, "intf-show", VLC_TRUE );
131 vlc_object_release( p_playlist );
132 p_intf->p_sys->b_triggered = VLC_FALSE;
135 vlc_mutex_unlock( &p_intf->change_lock );
138 /* Take care of the video output */
139 if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die )
141 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
142 MouseEvent, p_intf );
143 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
144 MouseEvent, p_intf );
145 vlc_object_release( p_intf->p_sys->p_vout );
146 p_intf->p_sys->p_vout = NULL;
149 if( p_intf->p_sys->p_vout == NULL )
151 p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
153 if( p_intf->p_sys->p_vout )
155 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
156 MouseEvent, p_intf );
157 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
158 MouseEvent, p_intf );
163 msleep( INTF_IDLE_SLEEP );
166 if( p_intf->p_sys->p_vout )
168 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
169 MouseEvent, p_intf );
170 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
171 MouseEvent, p_intf );
172 vlc_object_release( p_intf->p_sys->p_vout );
176 /*****************************************************************************
178 *****************************************************************************/
179 static int InitThread( intf_thread_t * p_intf )
181 if( !intf_ShouldDie( p_intf ) )
183 vlc_mutex_lock( &p_intf->change_lock );
185 p_intf->p_sys->b_triggered = VLC_FALSE;
186 p_intf->p_sys->b_button_pressed = VLC_FALSE;
187 p_intf->p_sys->i_threshold =
188 config_GetInt( p_intf, "showintf-threshold" );
190 vlc_mutex_unlock( &p_intf->change_lock );
200 /*****************************************************************************
201 * MouseEvent: callback for mouse events
202 *****************************************************************************/
203 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
204 vlc_value_t oldval, vlc_value_t newval, void *p_data )
206 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(newval);
209 int i_mouse_x, i_mouse_y;
210 intf_thread_t *p_intf = (intf_thread_t *)p_data;
212 /* Do nothing when the interface is already requested */
213 if( p_intf->p_sys->b_triggered )
216 /* Nothing to do when not in fullscreen mode */
217 var_Get( p_intf->p_sys->p_vout, "fullscreen", &val );
221 vlc_mutex_lock( &p_intf->change_lock );
222 if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
224 var_Get( p_intf->p_sys->p_vout, "mouse-x", &val );
225 i_mouse_x = val.i_int;
226 var_Get( p_intf->p_sys->p_vout, "mouse-y", &val );
227 i_mouse_y = val.i_int;
229 /* Very basic test, we even ignore the x value :) */
230 if ( i_mouse_y < p_intf->p_sys->i_threshold )
232 msg_Dbg( p_intf, "interface showing requested" );
233 p_intf->p_sys->b_triggered = VLC_TRUE;
237 /* We keep track of the button state to avoid interferences with the
239 if( !p_intf->p_sys->b_button_pressed &&
240 !strcmp( psz_var, "mouse-button-down" ) )
242 p_intf->p_sys->b_button_pressed = VLC_TRUE;
244 if( p_intf->p_sys->b_button_pressed &&
245 !strcmp( psz_var, "mouse-button-down" ) )
247 p_intf->p_sys->b_button_pressed = VLC_FALSE;
250 vlc_mutex_unlock( &p_intf->change_lock );