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_plugin.h>
34 #include <vlc_interface.h>
36 #include <vlc_playlist.h>
42 /*****************************************************************************
43 * intf_sys_t: description and status of interface
44 *****************************************************************************/
47 vlc_object_t * p_vout;
48 bool b_button_pressed;
53 /*****************************************************************************
55 *****************************************************************************/
56 int E_(Open) ( vlc_object_t * );
57 void E_(Close)( vlc_object_t * );
58 static void RunIntf( intf_thread_t *p_intf );
59 static int InitThread( 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 add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, true );
72 set_description( _("Show interface with mouse") );
74 set_capability( "interface", 0 );
75 set_callbacks( E_(Open), E_(Close) );
78 /*****************************************************************************
79 * Open: initialize interface
80 *****************************************************************************/
81 int E_(Open)( vlc_object_t *p_this )
83 intf_thread_t *p_intf = (intf_thread_t *)p_this;
85 /* Allocate instance and initialize some members */
86 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
87 if( p_intf->p_sys == NULL )
92 p_intf->pf_run = RunIntf;
97 /*****************************************************************************
98 * Close: destroy interface
99 *****************************************************************************/
100 void E_(Close)( vlc_object_t *p_this )
102 intf_thread_t *p_intf = (intf_thread_t *)p_this;
104 /* Destroy structure */
105 free( p_intf->p_sys );
109 /*****************************************************************************
111 *****************************************************************************/
112 static void RunIntf( intf_thread_t *p_intf )
114 p_intf->p_sys->p_vout = NULL;
116 if( InitThread( p_intf ) < 0 )
118 msg_Err( p_intf, "cannot initialize interface" );
123 while( !intf_ShouldDie( p_intf ) )
125 vlc_mutex_lock( &p_intf->change_lock );
127 /* Notify the interfaces */
128 if( p_intf->p_sys->b_triggered )
130 playlist_t *p_playlist = pl_Yield( p_intf );
131 var_SetBool( p_playlist, "intf-show", true );
132 vlc_object_release( p_playlist );
133 p_intf->p_sys->b_triggered = false;
136 vlc_mutex_unlock( &p_intf->change_lock );
139 /* Take care of the video output */
140 if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die )
142 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
143 MouseEvent, p_intf );
144 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
145 MouseEvent, p_intf );
146 vlc_object_release( p_intf->p_sys->p_vout );
147 p_intf->p_sys->p_vout = NULL;
150 if( p_intf->p_sys->p_vout == NULL )
152 p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
154 if( p_intf->p_sys->p_vout )
156 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
157 MouseEvent, p_intf );
158 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
159 MouseEvent, p_intf );
164 msleep( INTF_IDLE_SLEEP );
167 if( p_intf->p_sys->p_vout )
169 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
170 MouseEvent, p_intf );
171 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
172 MouseEvent, p_intf );
173 vlc_object_release( p_intf->p_sys->p_vout );
177 /*****************************************************************************
179 *****************************************************************************/
180 static int InitThread( intf_thread_t * p_intf )
182 if( !intf_ShouldDie( p_intf ) )
184 vlc_mutex_lock( &p_intf->change_lock );
186 p_intf->p_sys->b_triggered = false;
187 p_intf->p_sys->b_button_pressed = false;
188 p_intf->p_sys->i_threshold =
189 config_GetInt( p_intf, "showintf-threshold" );
191 vlc_mutex_unlock( &p_intf->change_lock );
201 /*****************************************************************************
202 * MouseEvent: callback for mouse events
203 *****************************************************************************/
204 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
205 vlc_value_t oldval, vlc_value_t newval, void *p_data )
207 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(newval);
210 int i_mouse_x, i_mouse_y;
211 intf_thread_t *p_intf = (intf_thread_t *)p_data;
213 /* Do nothing when the interface is already requested */
214 if( p_intf->p_sys->b_triggered )
217 /* Nothing to do when not in fullscreen mode */
218 var_Get( p_intf->p_sys->p_vout, "fullscreen", &val );
222 vlc_mutex_lock( &p_intf->change_lock );
223 if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
225 var_Get( p_intf->p_sys->p_vout, "mouse-x", &val );
226 i_mouse_x = val.i_int;
227 var_Get( p_intf->p_sys->p_vout, "mouse-y", &val );
228 i_mouse_y = val.i_int;
230 /* Very basic test, we even ignore the x value :) */
231 if ( i_mouse_y < p_intf->p_sys->i_threshold )
233 msg_Dbg( p_intf, "interface showing requested" );
234 p_intf->p_sys->b_triggered = true;
238 /* We keep track of the button state to avoid interferences with the
240 if( !p_intf->p_sys->b_button_pressed &&
241 !strcmp( psz_var, "mouse-button-down" ) )
243 p_intf->p_sys->b_button_pressed = true;
245 if( p_intf->p_sys->b_button_pressed &&
246 !strcmp( psz_var, "mouse-button-down" ) )
248 p_intf->p_sys->b_button_pressed = false;
251 vlc_mutex_unlock( &p_intf->change_lock );