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 add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, true )
72 set_description( N_("Show interface with mouse") )
74 set_capability( "interface", 0 )
75 set_callbacks( Open, Close )
78 /*****************************************************************************
79 * Open: initialize interface
80 *****************************************************************************/
81 int 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 intf_sys_t *p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
90 vlc_mutex_init( &p_sys->lock );
92 p_sys->b_button_pressed = false;
93 p_sys->b_triggered = false;
94 p_sys->i_threshold = config_GetInt( p_intf, "showintf-threshold" );
96 p_intf->pf_run = RunIntf;
101 /*****************************************************************************
102 * Close: destroy interface
103 *****************************************************************************/
104 void Close( vlc_object_t *p_this )
106 intf_thread_t *p_intf = (intf_thread_t *)p_this;
108 /* Destroy structure */
109 vlc_mutex_destroy( &p_intf->p_sys->lock );
110 free( p_intf->p_sys );
114 /*****************************************************************************
116 *****************************************************************************/
117 static void RunIntf( intf_thread_t *p_intf )
119 int canc = vlc_savecancel( );
122 while( vlc_object_alive( p_intf ) )
124 vlc_mutex_lock( &p_intf->p_sys->lock );
126 /* Notify the interfaces */
127 if( p_intf->p_sys->b_triggered )
129 var_SetBool( p_intf->p_libvlc, "intf-show", true );
130 p_intf->p_sys->b_triggered = false;
133 vlc_mutex_unlock( &p_intf->p_sys->lock );
136 /* Take care of the video output */
137 if( p_intf->p_sys->p_vout && !vlc_object_alive (p_intf->p_sys->p_vout) )
139 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
140 MouseEvent, p_intf );
141 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
142 MouseEvent, p_intf );
143 vlc_object_release( p_intf->p_sys->p_vout );
144 p_intf->p_sys->p_vout = NULL;
147 if( p_intf->p_sys->p_vout == NULL )
149 p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
151 if( p_intf->p_sys->p_vout )
153 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
154 MouseEvent, p_intf );
155 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
156 MouseEvent, p_intf );
161 msleep( INTF_IDLE_SLEEP );
164 if( p_intf->p_sys->p_vout )
166 var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
167 MouseEvent, p_intf );
168 var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
169 MouseEvent, p_intf );
170 vlc_object_release( p_intf->p_sys->p_vout );
172 vlc_restorecancel( canc );
175 /*****************************************************************************
176 * MouseEvent: callback for mouse events
177 *****************************************************************************/
178 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
179 vlc_value_t oldval, vlc_value_t newval, void *p_data )
181 VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(newval);
183 int i_mouse_x, i_mouse_y;
184 intf_thread_t *p_intf = (intf_thread_t *)p_data;
186 /* Do nothing when the interface is already requested */
187 if( p_intf->p_sys->b_triggered )
190 /* Nothing to do when not in fullscreen mode */
191 if( !var_GetBool( p_intf->p_sys->p_vout, "fullscreen" ) )
194 vlc_mutex_lock( &p_intf->p_sys->lock );
195 if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
197 i_mouse_x = var_GetInteger( p_intf->p_sys->p_vout, "mouse-x" );
198 i_mouse_y = var_GetInteger( p_intf->p_sys->p_vout, "mouse-y" );
200 /* Very basic test, we even ignore the x value :) */
201 if ( i_mouse_y < p_intf->p_sys->i_threshold )
203 msg_Dbg( p_intf, "interface showing requested" );
204 p_intf->p_sys->b_triggered = true;
208 /* We keep track of the button state to avoid interferences with the
210 if( !p_intf->p_sys->b_button_pressed &&
211 !strcmp( psz_var, "mouse-button-down" ) )
213 p_intf->p_sys->b_button_pressed = true;
215 if( p_intf->p_sys->b_button_pressed &&
216 !strcmp( psz_var, "mouse-button-down" ) )
218 p_intf->p_sys->b_button_pressed = false;
221 vlc_mutex_unlock( &p_intf->p_sys->lock );