From 4891bcd7ebe88959e9a3fbe63c1cf13a99290a08 Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Tue, 30 May 2017 14:14:51 +0200 Subject: [PATCH] bindings: Use a wrapper around rofi_view_trigger_action Signed-off-by: Quentin Glidic --- include/view.h | 5 +++-- source/keyb.c | 9 +++++++-- source/view.c | 9 ++++----- test/mode-test.c | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/view.h b/include/view.h index a7f3ebbe..6dd82230 100644 --- a/include/view.h +++ b/include/view.h @@ -139,11 +139,12 @@ void rofi_view_restart ( RofiViewState *state ); /** * @param state The handle to the view - * @param action The keyboard action + * @param scope The scope of the action + * @param action The action * * @returns TRUE if action was handled. */ -gboolean rofi_view_trigger_action ( guint scope, gpointer user_data ); +gboolean rofi_view_trigger_action ( RofiViewState *state, BindingsScope scope, guint action ); /** * @param state The handle to the view diff --git a/source/keyb.c b/source/keyb.c index c54bbfde..26837c05 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -140,6 +140,11 @@ void setup_abe ( void ) } } +static gboolean binding_trigger_action ( guint scope, gpointer user_data ) +{ + return rofi_view_trigger_action ( rofi_view_get_active (), scope, GPOINTER_TO_UINT ( user_data ) ); +} + gboolean parse_keys_abe ( NkBindings *bindings ) { GError *error = NULL; @@ -152,7 +157,7 @@ gboolean parse_keys_abe ( NkBindings *bindings ) // Iter over bindings. const char *const sep = ","; for ( char *entry = strtok_r ( keystr, sep, &sp ); entry != NULL; entry = strtok_r ( NULL, sep, &sp ) ) { - if ( !nk_bindings_add_binding ( bindings, b->scope, entry, rofi_view_trigger_action, GUINT_TO_POINTER ( b->id ), NULL, &error ) ) { + if ( !nk_bindings_add_binding ( bindings, b->scope, entry, binding_trigger_action, GUINT_TO_POINTER ( b->id ), NULL, &error ) ) { g_string_append_c ( g_string_append ( error_msg, error->message ), '\n' ); g_clear_error ( &error ); } @@ -168,7 +173,7 @@ gboolean parse_keys_abe ( NkBindings *bindings ) for ( gsize i = SCOPE_MIN_FIXED; i <= SCOPE_MAX_FIXED; ++i ) { for ( gsize j = 1; j < G_N_ELEMENTS ( mouse_default_bindings ); ++j ) { - nk_bindings_add_binding ( bindings, i, mouse_default_bindings[j], rofi_view_trigger_action, GSIZE_TO_POINTER ( j ), NULL, NULL ); + nk_bindings_add_binding ( bindings, i, mouse_default_bindings[j], binding_trigger_action, GSIZE_TO_POINTER ( j ), NULL, NULL ); } } diff --git a/source/view.c b/source/view.c index db2890cc..e33e89ed 100644 --- a/source/view.c +++ b/source/view.c @@ -1343,13 +1343,12 @@ static void rofi_view_trigger_global_action ( KeyBindingAction action ) } } -gboolean rofi_view_trigger_action ( guint scope, gpointer user_data ) +gboolean rofi_view_trigger_action ( RofiViewState *state, BindingsScope scope, guint action ) { - RofiViewState *state = rofi_view_get_active (); - switch ( (BindingsScope) scope ) + switch ( scope ) { case SCOPE_GLOBAL: - rofi_view_trigger_global_action ( GPOINTER_TO_UINT ( user_data ) ); + rofi_view_trigger_global_action ( action ); return TRUE; case SCOPE_MOUSE_LISTVIEW: case SCOPE_MOUSE_LISTVIEW_ELEMENT: @@ -1363,7 +1362,7 @@ gboolean rofi_view_trigger_action ( guint scope, gpointer user_data ) return FALSE; } widget_xy_to_relative ( target, &x, &y ); - switch ( widget_trigger_action ( target, GPOINTER_TO_UINT ( user_data ), x, y ) ) + switch ( widget_trigger_action ( target, action, x, y ) ) { case WIDGET_TRIGGER_ACTION_RESULT_IGNORED: return FALSE; diff --git a/test/mode-test.c b/test/mode-test.c index 36f5822f..f066c0d1 100644 --- a/test/mode-test.c +++ b/test/mode-test.c @@ -69,7 +69,7 @@ RofiViewState * rofi_view_get_active ( void ) { return NULL; } -gboolean rofi_view_trigger_action ( G_GNUC_UNUSED guint scope, G_GNUC_UNUSED gpointer user_data ) +gboolean rofi_view_trigger_action ( G_GNUC_UNUSED RofiViewState *state, G_GNUC_UNUSED BindingsScope scope, G_GNUC_UNUSED guint action ) { return FALSE; }