X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Fgestures.c;h=e7003c9abd601b0a7c5622fd05544118045cdaab;hb=1d5a0a9ca664284d3b5981dffbf0a60e2f6a88f7;hp=678aed2063817c831bd06cc0a3c229519eecdd72;hpb=1914caa52af9351e0e190933dd7622eee0aadaf4;p=vlc diff --git a/modules/control/gestures.c b/modules/control/gestures.c index 678aed2063..e7003c9abd 100644 --- a/modules/control/gestures.c +++ b/modules/control/gestures.c @@ -24,10 +24,13 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include #include @@ -43,8 +46,8 @@ struct intf_sys_t { vlc_object_t * p_vout; - vlc_bool_t b_got_gesture; - vlc_bool_t b_button_pressed; + bool b_got_gesture; + bool b_button_pressed; int i_mouse_x, i_mouse_y; int i_last_x, i_last_y; unsigned int i_pattern; @@ -63,8 +66,8 @@ struct intf_sys_t #define NONE 0 #define GESTURE( a, b, c, d ) (a | ( b << 4 ) | ( c << 8 ) | ( d << 12 )) -int E_(Open) ( vlc_object_t * ); -void E_(Close) ( vlc_object_t * ); +int Open ( vlc_object_t * ); +void Close ( vlc_object_t * ); static int InitThread ( intf_thread_t *p_intf ); static void EndThread ( intf_thread_t *p_intf ); static int MouseEvent ( vlc_object_t *, char const *, @@ -84,29 +87,29 @@ static void RunIntf ( intf_thread_t *p_intf ); #define BUTTON_LONGTEXT N_( \ "Trigger button for mouse gestures." ) -static const char *button_list[] = { "left", "middle", "right" }; -static const char *button_list_text[] = +static const char *const button_list[] = { "left", "middle", "right" }; +static const char *const button_list_text[] = { N_("Left"), N_("Middle"), N_("Right") }; vlc_module_begin(); - set_shortname( _("Gestures")); + set_shortname( N_("Gestures")); set_category( CAT_INTERFACE ); set_subcategory( SUBCAT_INTERFACE_CONTROL ); add_integer( "gestures-threshold", 30, NULL, - THRESHOLD_TEXT, THRESHOLD_LONGTEXT, VLC_TRUE ); + THRESHOLD_TEXT, THRESHOLD_LONGTEXT, true ); add_string( "gestures-button", "right", NULL, - BUTTON_TEXT, BUTTON_LONGTEXT, VLC_FALSE ); + BUTTON_TEXT, BUTTON_LONGTEXT, false ); change_string_list( button_list, button_list_text, 0 ); - set_description( _("Mouse gestures control interface") ); + set_description( N_("Mouse gestures control interface") ); set_capability( "interface", 0 ); - set_callbacks( E_(Open), E_(Close) ); + set_callbacks( Open, Close ); vlc_module_end(); /***************************************************************************** * OpenIntf: initialize interface *****************************************************************************/ -int E_(Open) ( vlc_object_t *p_this ) +int Open ( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; @@ -138,10 +141,10 @@ static input_thread_t * input_from_playlist ( playlist_t *p_playlist ) { input_thread_t * p_input; - PL_LOCK; - p_input = p_playlist->p_input; - if( p_input ) - vlc_object_yield( p_input ); + PL_LOCK; + p_input = p_playlist->p_input; + if( p_input ) + vlc_object_yield( p_input ); PL_UNLOCK; return p_input; @@ -150,7 +153,7 @@ static input_thread_t * input_from_playlist ( playlist_t *p_playlist ) /***************************************************************************** * CloseIntf: destroy dummy interface *****************************************************************************/ -void E_(Close) ( vlc_object_t *p_this ) +void Close ( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; @@ -170,7 +173,6 @@ static void RunIntf( intf_thread_t *p_intf ) p_intf->p_sys->p_vout = NULL; vlc_mutex_unlock( &p_intf->change_lock ); - if( InitThread( p_intf ) < 0 ) { msg_Err( p_intf, "can't initialize interface thread" ); @@ -224,17 +226,14 @@ static void RunIntf( intf_thread_t *p_intf ) case GESTURE(RIGHT,LEFT,NONE,NONE): { input_thread_t * p_input; - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + p_playlist = pl_Yield( p_intf ); p_input = input_from_playlist( p_playlist ); - + vlc_object_release( p_playlist ); + if( !p_input ) - { - vlc_object_release( p_playlist ); break; - } - + val.i_int = PLAYING_S; if( p_input ) { @@ -251,27 +250,16 @@ static void RunIntf( intf_thread_t *p_intf ) } msg_Dbg(p_intf, "Play/Pause"); vlc_object_release( p_input ); - vlc_object_release( p_playlist ); } break; case GESTURE(LEFT,DOWN,NONE,NONE): - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist == NULL ) - { - break; - } + p_playlist = pl_Yield( p_intf ); playlist_Prev( p_playlist ); vlc_object_release( p_playlist ); break; case GESTURE(RIGHT,DOWN,NONE,NONE): - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist == NULL ) - { - break; - } + p_playlist = pl_Yield( p_intf ); playlist_Next( p_playlist ); vlc_object_release( p_playlist ); @@ -304,19 +292,14 @@ static void RunIntf( intf_thread_t *p_intf ) vlc_value_t val, list, list2; int i_count, i; - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - - if( !p_playlist ) - break; + p_playlist = pl_Yield( p_intf ); p_input = input_from_playlist( p_playlist ); + vlc_object_release( p_playlist ); + if( !p_input ) - { - vlc_object_release( p_playlist ); break; - } var_Get( p_input, "audio-es", &val ); var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES, @@ -324,7 +307,8 @@ static void RunIntf( intf_thread_t *p_intf ) i_count = list.p_list->i_count; if( i_count <= 1 ) { - continue; + vlc_object_release( p_input ); + break; } for( i = 0; i < i_count; i++ ) { @@ -355,7 +339,6 @@ static void RunIntf( intf_thread_t *p_intf ) i++; } vlc_object_release( p_input ); - vlc_object_release( p_playlist ); } break; case GESTURE(DOWN,RIGHT,NONE,NONE): @@ -364,20 +347,14 @@ static void RunIntf( intf_thread_t *p_intf ) vlc_value_t val, list, list2; int i_count, i; - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - - if( !p_playlist ) - break; + p_playlist = pl_Yield( p_intf ); p_input = input_from_playlist( p_playlist ); + vlc_object_release( p_playlist ); if( !p_input ) - { - vlc_object_release( p_playlist ); break; - } - + var_Get( p_input, "spu-es", &val ); var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES, @@ -385,7 +362,8 @@ static void RunIntf( intf_thread_t *p_intf ) i_count = list.p_list->i_count; if( i_count <= 1 ) { - continue; + vlc_object_release( p_input ); + break; } for( i = 0; i < i_count; i++ ) { @@ -409,12 +387,11 @@ static void RunIntf( intf_thread_t *p_intf ) } else { - var_Set( p_input, "spu-es", + var_Set( p_input, "spu-es", list.p_list->p_values[i+1] ); i = i + 1; } vlc_object_release( p_input ); - vlc_object_release( p_playlist ); } break; case GESTURE(UP,LEFT,NONE,NONE): @@ -426,7 +403,7 @@ static void RunIntf( intf_thread_t *p_intf ) break; case GESTURE(DOWN,LEFT,NONE,NONE): /* FIXME: Should close the vout!"*/ - p_intf->p_libvlc->b_die = VLC_TRUE; + vlc_object_kill( p_intf->p_libvlc ); break; case GESTURE(DOWN,LEFT,UP,RIGHT): case GESTURE(UP,RIGHT,DOWN,LEFT): @@ -437,13 +414,13 @@ static void RunIntf( intf_thread_t *p_intf ) } p_intf->p_sys->i_num_gestures = 0; p_intf->p_sys->i_pattern = 0; - p_intf->p_sys->b_got_gesture = VLC_FALSE; + p_intf->p_sys->b_got_gesture = false; } /* * video output */ - if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die ) + if( p_intf->p_sys->p_vout && !vlc_object_alive (p_intf->p_sys->p_vout) ) { var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved", MouseEvent, p_intf ); @@ -491,8 +468,8 @@ static int InitThread( intf_thread_t * p_intf ) * during those operations */ vlc_mutex_lock( &p_intf->change_lock ); - p_intf->p_sys->b_got_gesture = VLC_FALSE; - p_intf->p_sys->b_button_pressed = VLC_FALSE; + p_intf->p_sys->b_got_gesture = false; + p_intf->p_sys->b_button_pressed = false; p_intf->p_sys->i_threshold = config_GetInt( p_intf, "gestures-threshold" ); psz_button = config_GetPsz( p_intf, "gestures-button" ); @@ -546,6 +523,7 @@ static void EndThread( intf_thread_t * p_intf ) 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); vlc_value_t val; int pattern = 0; @@ -612,7 +590,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, && newval.i_int & p_intf->p_sys->i_button_mask && !p_intf->p_sys->b_button_pressed ) { - p_intf->p_sys->b_button_pressed = VLC_TRUE; + p_intf->p_sys->b_button_pressed = true; var_Get( p_intf->p_sys->p_vout, "mouse-x", &val ); p_intf->p_sys->i_last_x = val.i_int; var_Get( p_intf->p_sys->p_vout, "mouse-y", &val ); @@ -622,8 +600,8 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, && !( newval.i_int & p_intf->p_sys->i_button_mask ) && p_intf->p_sys->b_button_pressed ) { - p_intf->p_sys->b_button_pressed = VLC_FALSE; - p_intf->p_sys->b_got_gesture = VLC_TRUE; + p_intf->p_sys->b_button_pressed = false; + p_intf->p_sys->b_got_gesture = true; } vlc_mutex_unlock( &p_intf->change_lock );