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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
38 /*****************************************************************************
39 * intf_sys_t: description and status of interface
40 *****************************************************************************/
43 vlc_object_t * p_vout;
44 vlc_bool_t b_button_pressed;
45 vlc_bool_t b_triggered;
49 /*****************************************************************************
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 * );
59 /*****************************************************************************
61 *****************************************************************************/
62 #define THRESHOLD_TEXT N_( "Threshold" )
63 #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface." )
66 set_shortname( "Showintf" );
67 add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, VLC_TRUE );
68 set_description( _("Show interface with mouse") );
70 set_capability( "interface", 0 );
71 set_callbacks( E_(Open), E_(Close) );
74 /*****************************************************************************
75 * Open: initialize interface
76 *****************************************************************************/
77 int E_(Open)( vlc_object_t *p_this )
79 intf_thread_t *p_intf = (intf_thread_t *)p_this;
81 /* Allocate instance and initialize some members */
82 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
83 if( p_intf->p_sys == NULL )
88 p_intf->pf_run = RunIntf;
93 /*****************************************************************************
94 * Close: destroy interface
95 *****************************************************************************/
96 void E_(Close)( vlc_object_t *p_this )
98 intf_thread_t *p_intf = (intf_thread_t *)p_this;
100 /* Destroy structure */
101 free( p_intf->p_sys );
105 /*****************************************************************************
107 *****************************************************************************/
108 static void RunIntf( intf_thread_t *p_intf )
110 p_intf->p_sys->p_vout = NULL;
112 if( InitThread( p_intf ) < 0 )
114 msg_Err( p_intf, "cannot initialize interface" );
119 while( !p_intf->b_die )
121 vlc_mutex_lock( &p_intf->change_lock );
123 /* Notify the interfaces */
124 if( p_intf->p_sys->b_triggered )
126 playlist_t *p_playlist = pl_Yield( p_intf );
127 var_SetBool( p_playlist, "intf-show", VLC_TRUE );
128 vlc_object_release( p_playlist );
129 p_intf->p_sys->b_triggered = VLC_FALSE;
132 vlc_mutex_unlock( &p_intf->change_lock );
135 /* Take care of the video output */
136 if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die )
138 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
139 MouseEvent, p_intf );
140 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
141 MouseEvent, p_intf );
142 vlc_object_release( p_intf->p_sys->p_vout );
143 p_intf->p_sys->p_vout = NULL;
146 if( p_intf->p_sys->p_vout == NULL )
148 p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
150 if( p_intf->p_sys->p_vout )
152 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
153 MouseEvent, p_intf );
154 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
155 MouseEvent, p_intf );
160 msleep( INTF_IDLE_SLEEP );
163 if( p_intf->p_sys->p_vout )
165 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
166 MouseEvent, p_intf );
167 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
168 MouseEvent, p_intf );
169 vlc_object_release( p_intf->p_sys->p_vout );
173 /*****************************************************************************
175 *****************************************************************************/
176 static int InitThread( intf_thread_t * p_intf )
180 vlc_mutex_lock( &p_intf->change_lock );
182 p_intf->p_sys->b_triggered = VLC_FALSE;
183 p_intf->p_sys->b_button_pressed = VLC_FALSE;
184 p_intf->p_sys->i_threshold =
185 config_GetInt( p_intf, "showintf-threshold" );
187 vlc_mutex_unlock( &p_intf->change_lock );
197 /*****************************************************************************
198 * MouseEvent: callback for mouse events
199 *****************************************************************************/
200 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
201 vlc_value_t oldval, vlc_value_t newval, void *p_data )
205 int i_mouse_x, i_mouse_y;
206 intf_thread_t *p_intf = (intf_thread_t *)p_data;
208 /* Do nothing when the interface is already requested */
209 if( p_intf->p_sys->b_triggered )
212 /* Nothing to do when not in fullscreen mode */
213 var_Get( p_intf->p_sys->p_vout, "fullscreen", &val );
217 vlc_mutex_lock( &p_intf->change_lock );
218 if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
220 var_Get( p_intf->p_sys->p_vout, "mouse-x", &val );
221 i_mouse_x = val.i_int;
222 var_Get( p_intf->p_sys->p_vout, "mouse-y", &val );
223 i_mouse_y = val.i_int;
225 /* Very basic test, we even ignore the x value :) */
226 if ( i_mouse_y < p_intf->p_sys->i_threshold )
228 msg_Dbg( p_intf, "interface showing requested" );
229 p_intf->p_sys->b_triggered = VLC_TRUE;
233 /* We keep track of the button state to avoid interferences with the
235 if( !p_intf->p_sys->b_button_pressed &&
236 !strcmp( psz_var, "mouse-button-down" ) )
238 p_intf->p_sys->b_button_pressed = VLC_TRUE;
240 if( p_intf->p_sys->b_button_pressed &&
241 !strcmp( psz_var, "mouse-button-down" ) )
243 p_intf->p_sys->b_button_pressed = VLC_FALSE;
246 vlc_mutex_unlock( &p_intf->change_lock );