Commit ce001542 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

gestures: process gestures directly from event and clean up

This is similar to hotkeys. There is no need for a hand-over thread.
parent 02503055
...@@ -47,9 +47,7 @@ struct intf_sys_t ...@@ -47,9 +47,7 @@ struct intf_sys_t
{ {
vlc_mutex_t lock; vlc_mutex_t lock;
vout_thread_t *p_vout; vout_thread_t *p_vout;
bool b_got_gesture;
bool b_button_pressed; bool b_button_pressed;
int i_mouse_x, i_mouse_y;
int i_last_x, i_last_y; int i_last_x, i_last_y;
unsigned int i_pattern; unsigned int i_pattern;
int i_num_gestures; int i_num_gestures;
...@@ -69,11 +67,6 @@ struct intf_sys_t ...@@ -69,11 +67,6 @@ struct intf_sys_t
static int Open ( vlc_object_t * ); static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * ); static void Close ( vlc_object_t * );
static int MouseEvent ( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
/* Exported functions */
static void RunIntf ( intf_thread_t *p_intf );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -111,6 +104,12 @@ vlc_module_begin () ...@@ -111,6 +104,12 @@ vlc_module_begin ()
set_callbacks( Open, Close ) set_callbacks( Open, Close )
vlc_module_end () vlc_module_end ()
static int MovedEvent( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static int ButtonEvent( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
static void RunIntf ( intf_thread_t *p_intf );
/***************************************************************************** /*****************************************************************************
* OpenIntf: initialize interface * OpenIntf: initialize interface
*****************************************************************************/ *****************************************************************************/
...@@ -128,7 +127,6 @@ static int Open ( vlc_object_t *p_this ) ...@@ -128,7 +127,6 @@ static int Open ( vlc_object_t *p_this )
vlc_mutex_init( &p_sys->lock ); vlc_mutex_init( &p_sys->lock );
p_sys->p_vout = NULL; p_sys->p_vout = NULL;
p_sys->b_got_gesture = false;
p_sys->b_button_pressed = false; p_sys->b_button_pressed = false;
p_sys->i_threshold = var_InheritInteger( p_intf, "gestures-threshold" ); p_sys->i_threshold = var_InheritInteger( p_intf, "gestures-threshold" );
...@@ -162,20 +160,21 @@ static int gesture( int i_pattern, int i_num ) ...@@ -162,20 +160,21 @@ static int gesture( int i_pattern, int i_num )
static void Close ( vlc_object_t *p_this ) static void Close ( vlc_object_t *p_this )
{ {
intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_thread_t *p_intf = (intf_thread_t *)p_this;
intf_sys_t *p_sys = p_intf->p_sys;
// Destroy the callbacks // Destroy the callbacks
if( p_intf->p_sys->p_vout ) if( 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 ); MovedEvent, 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 ); ButtonEvent, p_intf );
vlc_object_release( p_intf->p_sys->p_vout ); vlc_object_release( p_sys->p_vout );
} }
/* Destroy structure */ /* Destroy structure */
vlc_mutex_destroy( &p_intf->p_sys->lock ); vlc_mutex_destroy( &p_sys->lock );
free( p_intf->p_sys ); free( p_sys );
} }
...@@ -193,214 +192,15 @@ static void RunIntf( intf_thread_t *p_intf ) ...@@ -193,214 +192,15 @@ static void RunIntf( intf_thread_t *p_intf )
{ {
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
/*
* mouse cursor
*/
if( p_sys->b_got_gesture )
{
int i_interval = 0;
/* Do something */
/* If you modify this, please try to follow this convention:
Start with LEFT, RIGHT for playback related commands
and UP, DOWN, for other commands */
playlist_t * p_playlist = pl_Get( p_intf );
switch( p_sys->i_pattern )
{
case LEFT:
msg_Dbg( p_intf, "Go backward in the movie!" );
p_input = playlist_CurrentInput( p_playlist );
if( p_input )
{
i_interval = var_InheritInteger( p_intf , "short-jump-size" );
if ( i_interval > 0 )
{
mtime_t i_time = ( (mtime_t)( -i_interval ) * 1000000L);
var_SetTime( p_input, "time-offset", i_time );
}
vlc_object_release( p_input );
}
break;
case RIGHT:
msg_Dbg( p_intf, "Go forward in the movie!" );
p_input = playlist_CurrentInput( p_playlist );
if( p_input )
{
i_interval = var_InheritInteger( p_intf , "short-jump-size" );
if ( i_interval > 0 )
{
mtime_t i_time = ( (mtime_t)( i_interval ) * 1000000L);
var_SetTime( p_input, "time-offset", i_time );
}
vlc_object_release( p_input );
}
break;
case GESTURE(LEFT,UP,NONE,NONE):
msg_Dbg( p_intf, "Going slower." );
var_TriggerCallback( p_playlist, "rate-slower" );
break;
case GESTURE(RIGHT,UP,NONE,NONE):
msg_Dbg( p_intf, "Going faster." );
var_TriggerCallback( p_playlist, "rate-faster" );
break;
case GESTURE(LEFT,RIGHT,NONE,NONE):
case GESTURE(RIGHT,LEFT,NONE,NONE):
msg_Dbg( p_intf, "Play/Pause" );
p_input = playlist_CurrentInput( p_playlist );
if( p_input )
{
int i_state = var_GetInteger( p_input, "state" );
var_SetInteger( p_input, "state", ( i_state != PLAYING_S )
? PLAYING_S : PAUSE_S );
vlc_object_release( p_input );
}
break;
case GESTURE(LEFT,DOWN,NONE,NONE):
playlist_Prev( p_playlist );
break;
case GESTURE(RIGHT,DOWN,NONE,NONE):
playlist_Next( p_playlist );
break;
case UP:
msg_Dbg(p_intf, "Louder");
aout_VolumeUp( p_playlist, 1, NULL );
break;
case DOWN:
msg_Dbg(p_intf, "Quieter");
aout_VolumeDown( p_playlist, 1, NULL );
break;
case GESTURE(UP,DOWN,NONE,NONE):
case GESTURE(DOWN,UP,NONE,NONE):
msg_Dbg( p_intf, "Mute sound" );
aout_ToggleMute( p_playlist, NULL );
break;
case GESTURE(UP,RIGHT,NONE,NONE):
{
vlc_value_t list, list2;
int i_count, i, i_audio_es;
p_input = playlist_CurrentInput( p_playlist );
if( !p_input )
break;
i_audio_es = var_GetInteger( p_input, "audio-es" );
var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
&list, &list2 );
i_count = list.p_list->i_count;
if( i_count <= 1 )
{
var_FreeList( &list, &list2 );
vlc_object_release( p_input );
break;
}
for( i = 0; i < i_count; i++ )
{
if( i_audio_es == list.p_list->p_values[i].i_int )
break;
}
/* value of audio-es was not in choices list */
if( i == i_count )
{
msg_Warn( p_input,
"invalid current audio track, selecting 0" );
i = 0;
}
else if( i == i_count - 1 )
i = 1;
else
i++;
var_SetInteger( p_input, "audio-es", list.p_list->p_values[i].i_int );
var_FreeList( &list, &list2 );
vlc_object_release( p_input );
}
break;
case GESTURE(DOWN,RIGHT,NONE,NONE):
{
vlc_value_t list, list2;
int i_count, i, i_spu_es;
p_input = playlist_CurrentInput( p_playlist );
if( !p_input )
break;
i_spu_es = var_GetInteger( p_input, "spu-es" );
var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
&list, &list2 );
i_count = list.p_list->i_count;
if( i_count <= 1 )
{
vlc_object_release( p_input );
var_FreeList( &list, &list2 );
break;
}
for( i = 0; i < i_count; i++ )
{
if( i_spu_es == list.p_list->p_values[i].i_int )
{
break;
}
}
/* value of spu-es was not in choices list */
if( i == i_count )
{
msg_Warn( p_input,
"invalid current subtitle track, selecting 0" );
i = 0;
}
else if( i == i_count - 1 )
i = 0;
else
i++;
var_SetInteger( p_input, "spu-es", list.p_list->p_values[i].i_int);
var_FreeList( &list, &list2 );
vlc_object_release( p_input );
}
break;
case GESTURE(UP,LEFT,NONE,NONE):
{
bool val = var_ToggleBool( pl_Get( p_intf ), "fullscreen" );
if( p_sys->p_vout )
var_SetBool( p_sys->p_vout, "fullscreen", val );
break;
}
case GESTURE(DOWN,LEFT,NONE,NONE):
/* FIXME: Should close the vout!"*/
libvlc_Quit( p_intf->p_libvlc );
break;
case GESTURE(DOWN,LEFT,UP,RIGHT):
case GESTURE(UP,RIGHT,DOWN,LEFT):
msg_Dbg( p_intf, "a square was drawn!" );
break;
default:
break;
}
p_sys->i_num_gestures = 0;
p_sys->i_pattern = 0;
p_sys->b_got_gesture = false;
}
/* /*
* video output * video output
*/ */
if( p_sys->p_vout && !vlc_object_alive( p_sys->p_vout ) ) if( p_sys->p_vout && !vlc_object_alive( p_sys->p_vout ) )
{ {
var_DelCallback( p_sys->p_vout, "mouse-moved", var_DelCallback( p_sys->p_vout, "mouse-moved",
MouseEvent, p_intf ); MovedEvent, p_intf );
var_DelCallback( p_sys->p_vout, "mouse-button-down", var_DelCallback( p_sys->p_vout, "mouse-button-down",
MouseEvent, p_intf ); ButtonEvent, p_intf );
vlc_object_release( p_sys->p_vout ); vlc_object_release( p_sys->p_vout );
p_sys->p_vout = NULL; p_sys->p_vout = NULL;
} }
...@@ -416,9 +216,9 @@ static void RunIntf( intf_thread_t *p_intf ) ...@@ -416,9 +216,9 @@ static void RunIntf( intf_thread_t *p_intf )
if( p_sys->p_vout ) if( p_sys->p_vout )
{ {
var_AddCallback( p_sys->p_vout, "mouse-moved", var_AddCallback( p_sys->p_vout, "mouse-moved",
MouseEvent, p_intf ); MovedEvent, p_intf );
var_AddCallback( p_sys->p_vout, "mouse-button-down", var_AddCallback( p_sys->p_vout, "mouse-button-down",
MouseEvent, p_intf ); ButtonEvent, p_intf );
} }
} }
...@@ -431,35 +231,210 @@ static void RunIntf( intf_thread_t *p_intf ) ...@@ -431,35 +231,210 @@ static void RunIntf( intf_thread_t *p_intf )
vlc_restorecancel( canc ); vlc_restorecancel( canc );
} }
/***************************************************************************** static void ProcessGesture( intf_thread_t *p_intf )
* MouseEvent: callback for mouse events
*****************************************************************************/
static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
VLC_UNUSED(p_this); VLC_UNUSED(oldval); intf_sys_t *p_sys = p_intf->p_sys;
int pattern = 0; playlist_t *p_playlist = pl_Get( p_intf );
/* Do something */
/* If you modify this, please try to follow this convention:
Start with LEFT, RIGHT for playback related commands
and UP, DOWN, for other commands */
switch( p_sys->i_pattern )
{
case LEFT:
{
msg_Dbg( p_intf, "Go backward in the movie!" );
input_thread_t *p_input = playlist_CurrentInput( p_playlist );
if( p_input == NULL )
break;
int it = var_InheritInteger( p_intf , "short-jump-size" );
if( it > 0 )
var_SetTime( p_input, "time-offset", -CLOCK_FREQ * it );
vlc_object_release( p_input );
break;
}
case RIGHT:
{
msg_Dbg( p_intf, "Go forward in the movie!" );
input_thread_t *p_input = playlist_CurrentInput( p_playlist );
if( p_input == NULL )
break;
signed int i_horizontal, i_vertical; int it = var_InheritInteger( p_intf , "short-jump-size" );
if( it > 0 )
var_SetTime( p_input, "time-offset", CLOCK_FREQ * it );
vlc_object_release( p_input );
break;
}
case GESTURE(LEFT,UP,NONE,NONE):
msg_Dbg( p_intf, "Going slower." );
var_TriggerCallback( p_playlist, "rate-slower" );
break;
case GESTURE(RIGHT,UP,NONE,NONE):
msg_Dbg( p_intf, "Going faster." );
var_TriggerCallback( p_playlist, "rate-faster" );
break;
case GESTURE(LEFT,RIGHT,NONE,NONE):
case GESTURE(RIGHT,LEFT,NONE,NONE):
{
msg_Dbg( p_intf, "Play/Pause" );
input_thread_t *p_input = playlist_CurrentInput( p_playlist );
if( p_input == NULL )
break;
int i_state = var_GetInteger( p_input, "state" );
i_state = (i_state == PLAYING_S) ? PAUSE_S : PLAYING_S;
var_SetInteger( p_input, "state", i_state );
vlc_object_release( p_input );
break;
}
case GESTURE(LEFT,DOWN,NONE,NONE):
playlist_Prev( p_playlist );
break;
case GESTURE(RIGHT,DOWN,NONE,NONE):
playlist_Next( p_playlist );
break;
case UP:
msg_Dbg(p_intf, "Louder");
aout_VolumeUp( p_playlist, 1, NULL );
break;
case DOWN:
msg_Dbg(p_intf, "Quieter");
aout_VolumeDown( p_playlist, 1, NULL );
break;
case GESTURE(UP,DOWN,NONE,NONE):
case GESTURE(DOWN,UP,NONE,NONE):
msg_Dbg( p_intf, "Mute sound" );
aout_ToggleMute( p_playlist, NULL );
break;
case GESTURE(UP,RIGHT,NONE,NONE):
{
input_thread_t *p_input = playlist_CurrentInput( p_playlist );
if( p_input == NULL )
break;
vlc_value_t list, list2;
var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
&list, &list2 );
if( list.p_list->i_count > 1 )
{
int i_audio_es = var_GetInteger( p_input, "audio-es" );
int i;
for( i = 0; i < list.p_list->i_count; i++ )
if( i_audio_es == list.p_list->p_values[i].i_int )
break;
/* value of audio-es was not in choices list */
if( i == list.p_list->i_count )
{
msg_Warn( p_input,
"invalid current audio track, selecting 0" );
i = 0;
}
else if( i == list.p_list->i_count - 1 )
i = 1;
else
i++;
var_SetInteger( p_input, "audio-es",
list.p_list->p_values[i].i_int );
}
var_FreeList( &list, &list2 );
vlc_object_release( p_input );
break;
}
case GESTURE(DOWN,RIGHT,NONE,NONE):
{
input_thread_t *p_input = playlist_CurrentInput( p_playlist );
if( p_input == NULL )
break;
vlc_value_t list, list2;
var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
&list, &list2 );
if( list.p_list->i_count > 1 )
{
int i_audio_es = var_GetInteger( p_input, "spu-es" );
int i;
for( i = 0; i < list.p_list->i_count; i++ )
if( i_audio_es == list.p_list->p_values[i].i_int )
break;
/* value of audio-es was not in choices list */
if( i == list.p_list->i_count )
{
msg_Warn( p_input,
"invalid current subtitle track, selecting 0" );
i = 0;
}
else if( i == list.p_list->i_count - 1 )
i = 1;
else
i++;
var_SetInteger( p_input, "audio-es",
list.p_list->p_values[i].i_int );
}
var_FreeList( &list, &list2 );
vlc_object_release( p_input );
break;
}
case GESTURE(UP,LEFT,NONE,NONE):
{
bool val = var_ToggleBool( pl_Get( p_intf ), "fullscreen" );
if( p_sys->p_vout )
var_SetBool( p_sys->p_vout, "fullscreen", val );
break;
}
case GESTURE(DOWN,LEFT,NONE,NONE):
/* FIXME: Should close the vout!"*/
libvlc_Quit( p_intf->p_libvlc );
break;
case GESTURE(DOWN,LEFT,UP,RIGHT):
case GESTURE(UP,RIGHT,DOWN,LEFT):
msg_Dbg( p_intf, "a square was drawn!" );
break;
}
p_sys->i_num_gestures = 0;
p_sys->i_pattern = 0;
}
static int MovedEvent( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
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; intf_sys_t *p_sys = p_intf->p_sys;
vlc_mutex_lock( &p_sys->lock ); (void) p_this; (void) psz_var; (void) oldval;
/* don't process new gestures before the last events are processed */ vlc_mutex_lock( &p_sys->lock );
if( p_sys->b_got_gesture ) if( p_sys->b_button_pressed )
{ {
vlc_mutex_unlock( &p_sys->lock ); int i_horizontal = newval.coords.x - p_sys->i_last_x;
return VLC_SUCCESS; int i_vertical = newval.coords.y - p_sys->i_last_y;
} int pattern = 0;
if( !strcmp( psz_var, "mouse-moved" ) && p_sys->b_button_pressed )
{
p_sys->i_mouse_x = newval.coords.x;
p_sys->i_mouse_y = newval.coords.y;
i_horizontal = p_sys->i_mouse_x - p_sys->i_last_x;
i_horizontal = i_horizontal / p_sys->i_threshold; i_horizontal = i_horizontal / p_sys->i_threshold;
i_vertical = p_sys->i_mouse_y - p_sys->i_last_y;
i_vertical = i_vertical / p_sys->i_threshold; i_vertical = i_vertical / p_sys->i_threshold;
if( i_horizontal < 0 ) if( i_horizontal < 0 )
...@@ -482,10 +457,11 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, ...@@ -482,10 +457,11 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
msg_Dbg( p_intf, "down gesture (%d)", i_vertical ); msg_Dbg( p_intf, "down gesture (%d)", i_vertical );
pattern = DOWN; pattern = DOWN;
} }
if( pattern ) if( pattern )
{ {
p_sys->i_last_y = p_sys->i_mouse_y; p_sys->i_last_x = newval.coords.x;
p_sys->i_last_x = p_sys->i_mouse_x; p_sys->i_last_y = newval.coords.y;
if( gesture( p_sys->i_pattern, p_sys->i_num_gestures - 1 ) if( gesture( p_sys->i_pattern, p_sys->i_num_gestures - 1 )
!= pattern ) != pattern )
{ {
...@@ -495,21 +471,37 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, ...@@ -495,21 +471,37 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
} }
} }
else if( !strcmp( psz_var, "mouse-button-down" ) ) vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS;
}
static int ButtonEvent( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t val, void *p_data )
{
intf_thread_t *p_intf = p_data;
intf_sys_t *p_sys = p_intf->p_sys;
(void) p_this; (void) psz_var; (void) oldval;
vlc_mutex_lock( &p_sys->lock );
if( val.i_int & p_sys->i_button_mask )
{ {
if( (newval.i_int & p_sys->i_button_mask) && !p_sys->b_button_pressed ) if( !p_sys->b_button_pressed )
{ {
p_sys->b_button_pressed = true; p_sys->b_button_pressed = true;
var_GetCoords( p_sys->p_vout, "mouse-moved", var_GetCoords( p_sys->p_vout, "mouse-moved",
&p_sys->i_last_x, &p_sys->i_last_y ); &p_sys->i_last_x, &p_sys->i_last_y );
} }
else if( !( newval.i_int & p_sys->i_button_mask ) && p_sys->b_button_pressed ) }
else
{
if( p_sys->b_button_pressed )
{ {
p_sys->b_button_pressed = false; p_sys->b_button_pressed = false;
p_sys->b_got_gesture = true; ProcessGesture( p_intf );
} }
} }
vlc_mutex_unlock( &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