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 *****************************************************************************/
29 #include <vlc_interface.h>
31 #include <vlc_playlist.h>
37 /*****************************************************************************
38 * intf_sys_t: description and status of interface
39 *****************************************************************************/
42 vlc_object_t * p_vout;
43 vlc_bool_t b_button_pressed;
44 vlc_bool_t b_triggered;
48 /*****************************************************************************
50 *****************************************************************************/
51 int E_(Open) ( vlc_object_t * );
52 void E_(Close)( vlc_object_t * );
53 static void RunIntf( intf_thread_t *p_intf );
54 static int InitThread( intf_thread_t *p_intf );
55 static int MouseEvent( vlc_object_t *, char const *,
56 vlc_value_t, vlc_value_t, void * );
58 /*****************************************************************************
60 *****************************************************************************/
61 #define THRESHOLD_TEXT N_( "Threshold" )
62 #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface." )
65 set_shortname( "Showintf" );
66 add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, VLC_TRUE );
67 set_description( _("Show interface with mouse") );
69 set_capability( "interface", 0 );
70 set_callbacks( E_(Open), E_(Close) );
73 /*****************************************************************************
74 * Open: initialize interface
75 *****************************************************************************/
76 int E_(Open)( vlc_object_t *p_this )
78 intf_thread_t *p_intf = (intf_thread_t *)p_this;
80 /* Allocate instance and initialize some members */
81 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
82 if( p_intf->p_sys == NULL )
87 p_intf->pf_run = RunIntf;
92 /*****************************************************************************
93 * Close: destroy interface
94 *****************************************************************************/
95 void E_(Close)( vlc_object_t *p_this )
97 intf_thread_t *p_intf = (intf_thread_t *)p_this;
99 /* Destroy structure */
100 free( p_intf->p_sys );
104 /*****************************************************************************
106 *****************************************************************************/
107 static void RunIntf( intf_thread_t *p_intf )
109 p_intf->p_sys->p_vout = NULL;
111 if( InitThread( p_intf ) < 0 )
113 msg_Err( p_intf, "cannot initialize interface" );
118 while( !intf_ShouldDie( p_intf ) )
120 vlc_mutex_lock( &p_intf->change_lock );
122 /* Notify the interfaces */
123 if( p_intf->p_sys->b_triggered )
125 playlist_t *p_playlist = pl_Yield( p_intf );
126 var_SetBool( p_playlist, "intf-show", VLC_TRUE );
127 vlc_object_release( p_playlist );
128 p_intf->p_sys->b_triggered = VLC_FALSE;
131 vlc_mutex_unlock( &p_intf->change_lock );
134 /* Take care of the video output */
135 if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die )
137 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
138 MouseEvent, p_intf );
139 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
140 MouseEvent, p_intf );
141 vlc_object_release( p_intf->p_sys->p_vout );
142 p_intf->p_sys->p_vout = NULL;
145 if( p_intf->p_sys->p_vout == NULL )
147 p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
149 if( p_intf->p_sys->p_vout )
151 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
152 MouseEvent, p_intf );
153 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
154 MouseEvent, p_intf );
159 msleep( INTF_IDLE_SLEEP );
162 if( p_intf->p_sys->p_vout )
164 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
165 MouseEvent, p_intf );
166 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
167 MouseEvent, p_intf );
168 vlc_object_release( p_intf->p_sys->p_vout );
172 /*****************************************************************************
174 *****************************************************************************/
175 static int InitThread( intf_thread_t * p_intf )
177 if( !intf_ShouldDie( p_intf ) )
179 vlc_mutex_lock( &p_intf->change_lock );
181 p_intf->p_sys->b_triggered = VLC_FALSE;
182 p_intf->p_sys->b_button_pressed = VLC_FALSE;
183 p_intf->p_sys->i_threshold =
184 config_GetInt( p_intf, "showintf-threshold" );
186 vlc_mutex_unlock( &p_intf->change_lock );
196 /*****************************************************************************
197 * MouseEvent: callback for mouse events
198 *****************************************************************************/
199 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
200 vlc_value_t oldval, vlc_value_t newval, void *p_data )
204 int i_mouse_x, i_mouse_y;
205 intf_thread_t *p_intf = (intf_thread_t *)p_data;
207 /* Do nothing when the interface is already requested */
208 if( p_intf->p_sys->b_triggered )
211 /* Nothing to do when not in fullscreen mode */
212 var_Get( p_intf->p_sys->p_vout, "fullscreen", &val );
216 vlc_mutex_lock( &p_intf->change_lock );
217 if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
219 var_Get( p_intf->p_sys->p_vout, "mouse-x", &val );
220 i_mouse_x = val.i_int;
221 var_Get( p_intf->p_sys->p_vout, "mouse-y", &val );
222 i_mouse_y = val.i_int;
224 /* Very basic test, we even ignore the x value :) */
225 if ( i_mouse_y < p_intf->p_sys->i_threshold )
227 msg_Dbg( p_intf, "interface showing requested" );
228 p_intf->p_sys->b_triggered = VLC_TRUE;
232 /* We keep track of the button state to avoid interferences with the
234 if( !p_intf->p_sys->b_button_pressed &&
235 !strcmp( psz_var, "mouse-button-down" ) )
237 p_intf->p_sys->b_button_pressed = VLC_TRUE;
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_FALSE;
245 vlc_mutex_unlock( &p_intf->change_lock );