Commit 0412df76 authored by Rémi Duraffort's avatar Rémi Duraffort

gestures: factorisation, cleaning and fix a warning.

parent 7e66b53b
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
struct intf_sys_t struct intf_sys_t
{ {
vlc_mutex_t lock; vlc_mutex_t lock;
vlc_object_t * p_vout; vout_thread_t *p_vout;
bool b_got_gesture; bool b_got_gesture;
bool b_button_pressed; bool b_button_pressed;
int i_mouse_x, i_mouse_y; int i_mouse_x, i_mouse_y;
...@@ -178,6 +178,7 @@ void Close ( vlc_object_t *p_this ) ...@@ -178,6 +178,7 @@ void Close ( vlc_object_t *p_this )
*****************************************************************************/ *****************************************************************************/
static void RunIntf( intf_thread_t *p_intf ) static void RunIntf( intf_thread_t *p_intf )
{ {
intf_sys_t *p_sys = p_intf->p_sys;
playlist_t * p_playlist = NULL; playlist_t * p_playlist = NULL;
int canc = vlc_savecancel(); int canc = vlc_savecancel();
input_thread_t *p_input; input_thread_t *p_input;
...@@ -185,12 +186,12 @@ static void RunIntf( intf_thread_t *p_intf ) ...@@ -185,12 +186,12 @@ static void RunIntf( intf_thread_t *p_intf )
/* Main loop */ /* Main loop */
while( vlc_object_alive( p_intf ) ) while( vlc_object_alive( p_intf ) )
{ {
vlc_mutex_lock( &p_intf->p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
/* /*
* mouse cursor * mouse cursor
*/ */
if( p_intf->p_sys->b_got_gesture ) if( p_sys->b_got_gesture )
{ {
vlc_value_t val; vlc_value_t val;
int i_interval = 0; int i_interval = 0;
...@@ -198,7 +199,7 @@ static void RunIntf( intf_thread_t *p_intf ) ...@@ -198,7 +199,7 @@ static void RunIntf( intf_thread_t *p_intf )
/* If you modify this, please try to follow this convention: /* If you modify this, please try to follow this convention:
Start with LEFT, RIGHT for playback related commands Start with LEFT, RIGHT for playback related commands
and UP, DOWN, for other commands */ and UP, DOWN, for other commands */
switch( p_intf->p_sys->i_pattern ) switch( p_sys->i_pattern )
{ {
case LEFT: case LEFT:
msg_Dbg( p_intf, "Go backward in the movie!" ); msg_Dbg( p_intf, "Go backward in the movie!" );
...@@ -299,7 +300,7 @@ static void RunIntf( intf_thread_t *p_intf ) ...@@ -299,7 +300,7 @@ static void RunIntf( intf_thread_t *p_intf )
case GESTURE(UP,DOWN,NONE,NONE): case GESTURE(UP,DOWN,NONE,NONE):
case GESTURE(DOWN,UP,NONE,NONE): case GESTURE(DOWN,UP,NONE,NONE):
msg_Dbg(p_intf, "Mute sound"); msg_Dbg( p_intf, "Mute sound" );
aout_VolumeMute( p_intf, NULL ); aout_VolumeMute( p_intf, NULL );
break; break;
...@@ -390,11 +391,11 @@ static void RunIntf( intf_thread_t *p_intf ) ...@@ -390,11 +391,11 @@ static void RunIntf( intf_thread_t *p_intf )
break; break;
case GESTURE(UP,LEFT,NONE,NONE): case GESTURE(UP,LEFT,NONE,NONE):
if (p_intf->p_sys->p_vout ) if( p_sys->p_vout )
{ {
var_Get( p_intf->p_sys->p_vout, "fullscreen", &val ); var_Get( p_sys->p_vout, "fullscreen", &val );
val.b_bool = !val.b_bool; val.b_bool = !val.b_bool;
var_Set( p_intf->p_sys->p_vout, "fullscreen", val ); var_Set( p_sys->p_vout, "fullscreen", val );
} }
break; break;
...@@ -404,49 +405,49 @@ static void RunIntf( intf_thread_t *p_intf ) ...@@ -404,49 +405,49 @@ static void RunIntf( intf_thread_t *p_intf )
break; break;
case GESTURE(DOWN,LEFT,UP,RIGHT): case GESTURE(DOWN,LEFT,UP,RIGHT):
case GESTURE(UP,RIGHT,DOWN,LEFT): case GESTURE(UP,RIGHT,DOWN,LEFT):
msg_Dbg(p_intf, "a square was drawn!" ); msg_Dbg( p_intf, "a square was drawn!" );
break; break;
default: default:
break; break;
} }
p_intf->p_sys->i_num_gestures = 0; p_sys->i_num_gestures = 0;
p_intf->p_sys->i_pattern = 0; p_sys->i_pattern = 0;
p_intf->p_sys->b_got_gesture = false; p_sys->b_got_gesture = false;
} }
/* /*
* video output * video output
*/ */
if( p_intf->p_sys->p_vout && !vlc_object_alive (p_intf->p_sys->p_vout) ) if( p_sys->p_vout && !vlc_object_alive( p_sys->p_vout ) )
{ {
var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved", var_DelCallback( p_sys->p_vout, "mouse-moved",
MouseEvent, p_intf ); MouseEvent, p_intf );
var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down", var_DelCallback( p_sys->p_vout, "mouse-button-down",
MouseEvent, p_intf ); MouseEvent, p_intf );
vlc_object_release( p_intf->p_sys->p_vout ); vlc_object_release( p_sys->p_vout );
p_intf->p_sys->p_vout = NULL; p_sys->p_vout = NULL;
} }
if( p_intf->p_sys->p_vout == NULL ) if( p_sys->p_vout == NULL )
{ {
p_playlist = pl_Hold( p_intf ); p_playlist = pl_Hold( p_intf );
p_input = playlist_CurrentInput( p_playlist ); p_input = playlist_CurrentInput( p_playlist );
pl_Release( p_intf ); pl_Release( p_intf );
if( p_input ) if( p_input )
{ {
p_intf->p_sys->p_vout = input_GetVout( p_input ); p_sys->p_vout = input_GetVout( p_input );
vlc_object_release( p_input ); vlc_object_release( p_input );
} }
if( p_intf->p_sys->p_vout ) if( p_sys->p_vout )
{ {
var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved", var_AddCallback( p_sys->p_vout, "mouse-moved",
MouseEvent, p_intf ); MouseEvent, p_intf );
var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down", var_AddCallback( p_sys->p_vout, "mouse-button-down",
MouseEvent, p_intf ); MouseEvent, p_intf );
} }
} }
vlc_mutex_unlock( &p_intf->p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
/* Wait a bit */ /* Wait a bit */
msleep( INTF_IDLE_SLEEP ); msleep( INTF_IDLE_SLEEP );
...@@ -462,33 +463,29 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, ...@@ -462,33 +463,29 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(p_this); VLC_UNUSED(oldval);
vlc_value_t val;
int pattern = 0; int pattern = 0;
signed int i_horizontal, i_vertical; signed int i_horizontal, i_vertical;
intf_thread_t *p_intf = (intf_thread_t *)p_data; intf_thread_t *p_intf = (intf_thread_t *)p_data;
intf_sys_t *p_sys = p_intf->p_sys;
vlc_mutex_lock( &p_intf->p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
/* don't process new gestures before the last events are processed */ /* don't process new gestures before the last events are processed */
if( p_intf->p_sys->b_got_gesture ) if( p_sys->b_got_gesture )
{ {
vlc_mutex_unlock( &p_intf->p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
if( !strcmp(psz_var, "mouse-moved" ) && p_intf->p_sys->b_button_pressed ) if( !strcmp( psz_var, "mouse-moved" ) && p_sys->b_button_pressed )
{ {
var_Get( p_intf->p_sys->p_vout, "mouse-x", &val ); p_sys->i_mouse_x = var_GetInteger( p_sys->p_vout, "mouse-x" );
p_intf->p_sys->i_mouse_x = val.i_int; p_sys->i_mouse_y = var_GetInteger( p_sys->p_vout, "mouse-y" );
var_Get( p_intf->p_sys->p_vout, "mouse-y", &val ); i_horizontal = p_sys->i_mouse_x - p_sys->i_last_x;
p_intf->p_sys->i_mouse_y = val.i_int; i_horizontal = i_horizontal / p_sys->i_threshold;
i_horizontal = p_intf->p_sys->i_mouse_x - i_vertical = p_sys->i_mouse_y - p_sys->i_last_y;
p_intf->p_sys->i_last_x; i_vertical = i_vertical / p_sys->i_threshold;
i_horizontal = i_horizontal / p_intf->p_sys->i_threshold;
i_vertical = p_intf->p_sys->i_mouse_y
- p_intf->p_sys->i_last_y;
i_vertical = i_vertical / p_intf->p_sys->i_threshold;
if( i_horizontal < 0 ) if( i_horizontal < 0 )
{ {
...@@ -512,37 +509,33 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, ...@@ -512,37 +509,33 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
} }
if( pattern ) if( pattern )
{ {
p_intf->p_sys->i_last_y = p_intf->p_sys->i_mouse_y; p_sys->i_last_y = p_sys->i_mouse_y;
p_intf->p_sys->i_last_x = p_intf->p_sys->i_mouse_x; p_sys->i_last_x = p_sys->i_mouse_x;
if( gesture( p_intf->p_sys->i_pattern, if( gesture( p_sys->i_pattern, p_sys->i_num_gestures - 1 )
p_intf->p_sys->i_num_gestures - 1 ) != pattern ) != pattern )
{ {
p_intf->p_sys->i_pattern |= p_sys->i_pattern |= pattern << ( p_sys->i_num_gestures * 4 );
pattern << ( p_intf->p_sys->i_num_gestures * 4 ); p_sys->i_num_gestures++;
p_intf->p_sys->i_num_gestures++;
} }
} }
} }
if( !strcmp( psz_var, "mouse-button-down" ) else if( !strcmp( psz_var, "mouse-button-down" ) )
&& newval.i_int & p_intf->p_sys->i_button_mask
&& !p_intf->p_sys->b_button_pressed )
{ {
p_intf->p_sys->b_button_pressed = true; if( (newval.i_int & p_sys->i_button_mask) && !p_sys->b_button_pressed )
var_Get( p_intf->p_sys->p_vout, "mouse-x", &val ); {
p_intf->p_sys->i_last_x = val.i_int; p_sys->b_button_pressed = true;
var_Get( p_intf->p_sys->p_vout, "mouse-y", &val ); p_sys->i_last_x = var_GetInteger( p_sys->p_vout, "mouse-x" );
p_intf->p_sys->i_last_y = val.i_int; p_sys->i_last_y = var_GetInteger( p_sys->p_vout, "mouse-y" );
} }
if( !strcmp( psz_var, "mouse-button-down" ) else if( !( newval.i_int & p_sys->i_button_mask ) && p_sys->b_button_pressed )
&& !( newval.i_int & p_intf->p_sys->i_button_mask )
&& p_intf->p_sys->b_button_pressed )
{ {
p_intf->p_sys->b_button_pressed = false; p_sys->b_button_pressed = false;
p_intf->p_sys->b_got_gesture = true; p_sys->b_got_gesture = true;
}
} }
vlc_mutex_unlock( &p_intf->p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment