From bde8175d393d8dbd8998268480a370e6daf9370e Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Thu, 28 Oct 2021 06:33:12 +0000 Subject: [PATCH] gitmodules: Update libnkutils Signed-off-by: Quentin Glidic --- include/view.h | 12 ++++++++-- include/widgets/widget.h | 14 ++++++++++++ source/keyb.c | 13 +++++++---- source/view.c | 48 ++++++++++++++++++++++++++++++++-------- source/widgets/widget.c | 15 +++++++++++++ subprojects/libnkutils | 2 +- test/mode-test.c | 5 ++++- 7 files changed, 92 insertions(+), 17 deletions(-) diff --git a/include/view.h b/include/view.h index 01cfa04b..1971ad7e 100644 --- a/include/view.h +++ b/include/view.h @@ -170,8 +170,16 @@ void rofi_view_restart(RofiViewState *state); * * @returns TRUE if action was handled. */ -gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope, - guint action); +gboolean rofi_view_check_action(RofiViewState *state, BindingsScope scope, + guint action); + +/** + * @param state The handle to the view + * @param scope The scope of the action + * @param action The action + */ +void rofi_view_trigger_action(RofiViewState *state, BindingsScope scope, + guint action); /** * @param state The handle to the view diff --git a/include/widgets/widget.h b/include/widgets/widget.h index e4139d02..aa64b84f 100644 --- a/include/widgets/widget.h +++ b/include/widgets/widget.h @@ -281,6 +281,20 @@ gboolean widget_need_redraw(widget *wid); */ widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y); +/** + * @param wid The widget handle + * @param action The action to trigger + * @param x A pointer to the x coordinate of the click + * @param y A pointer to the y coordinate of the click + * + * Trigger an action on widget. + * param x and param y are relative to param wid . + * + * @returns Whether the action would be handled or not + */ +WidgetTriggerActionResult widget_check_action(widget *wid, guint action, + gint x, gint y); + /** * @param wid The widget handle * @param action The action to trigger diff --git a/source/keyb.c b/source/keyb.c index 6b32af02..d2bab474 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -142,9 +142,14 @@ void setup_abe ( void ) } } -static gboolean binding_trigger_action ( guint64 scope, G_GNUC_UNUSED gpointer target, gpointer user_data ) +static gboolean binding_check_action ( guint64 scope, G_GNUC_UNUSED gpointer target, gpointer user_data ) { - return rofi_view_trigger_action ( rofi_view_get_active (), scope, GPOINTER_TO_UINT ( user_data ) ); + return rofi_view_check_action ( rofi_view_get_active (), scope, GPOINTER_TO_UINT ( user_data ) ) ? NK_BINDINGS_BINDING_TRIGGERED : NK_BINDINGS_BINDING_NOT_TRIGGERED; +} + +static void binding_trigger_action ( guint64 scope, G_GNUC_UNUSED gpointer target, gpointer user_data ) +{ + rofi_view_trigger_action ( rofi_view_get_active (), scope, GPOINTER_TO_UINT ( user_data ) ); } guint key_binding_get_action_from_name ( const char *name ) @@ -171,7 +176,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, binding_trigger_action, GUINT_TO_POINTER ( b->id ), NULL, &error ) ) { + if ( !nk_bindings_add_binding ( bindings, b->scope, entry, binding_check_action, binding_trigger_action, GUINT_TO_POINTER ( b->id ), NULL, &error ) ) { char *str = g_markup_printf_escaped ( "Failed to set binding %s for: %s (%s):\n\t%s\n", b->binding, b->comment, b->name, error->message ); g_string_append ( error_msg, str ); @@ -191,7 +196,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], binding_trigger_action, GSIZE_TO_POINTER ( j ), NULL, NULL ); + nk_bindings_add_binding ( bindings, i, mouse_default_bindings[j], binding_check_action, binding_trigger_action, GSIZE_TO_POINTER ( j ), NULL, NULL ); } } diff --git a/source/view.c b/source/view.c index 3010a08d..27994eb1 100644 --- a/source/view.c +++ b/source/view.c @@ -1470,12 +1470,10 @@ static void rofi_view_trigger_global_action(KeyBindingAction action) { } } -gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope, - guint action) { - rofi_view_set_user_timeout(NULL); +gboolean rofi_view_check_action(RofiViewState *state, BindingsScope scope, + guint action) { switch (scope) { case SCOPE_GLOBAL: - rofi_view_trigger_global_action(action); return TRUE; case SCOPE_MOUSE_LISTVIEW: case SCOPE_MOUSE_LISTVIEW_ELEMENT: @@ -1489,15 +1487,11 @@ gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope, return FALSE; } widget_xy_to_relative(target, &x, &y); - switch (widget_trigger_action(target, action, x, y)) { + switch (widget_check_action(target, action, x, y)) { case WIDGET_TRIGGER_ACTION_RESULT_IGNORED: return FALSE; case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END: - target = NULL; - /* FALLTHRU */ case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN: - state->mouse.motion_target = target; - /* FALLTHRU */ case WIDGET_TRIGGER_ACTION_RESULT_HANDLED: return TRUE; } @@ -1507,6 +1501,42 @@ gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope, return FALSE; } +void rofi_view_trigger_action(RofiViewState *state, BindingsScope scope, + guint action) { + rofi_view_set_user_timeout(NULL); + switch (scope) { + case SCOPE_GLOBAL: + rofi_view_trigger_global_action(action); + return; + case SCOPE_MOUSE_LISTVIEW: + case SCOPE_MOUSE_LISTVIEW_ELEMENT: + case SCOPE_MOUSE_EDITBOX: + case SCOPE_MOUSE_SCROLLBAR: + case SCOPE_MOUSE_MODE_SWITCHER: { + gint x = state->mouse.x, y = state->mouse.y; + widget *target = widget_find_mouse_target(WIDGET(state->main_window), + (WidgetType)scope, x, y); + if (target == NULL) { + return; + } + widget_xy_to_relative(target, &x, &y); + switch (widget_trigger_action(target, action, x, y)) { + case WIDGET_TRIGGER_ACTION_RESULT_IGNORED: + return; + case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END: + target = NULL; + /* FALLTHRU */ + case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN: + state->mouse.motion_target = target; + /* FALLTHRU */ + case WIDGET_TRIGGER_ACTION_RESULT_HANDLED: + return; + } + break; + } + } +} + void rofi_view_handle_text(RofiViewState *state, char *text) { if (textbox_append_text(state->text, text, strlen(text))) { state->refilter = TRUE; diff --git a/source/widgets/widget.c b/source/widgets/widget.c index aaaea1f8..3eb5debd 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -548,6 +548,21 @@ widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y) { return NULL; } +WidgetTriggerActionResult widget_check_action(widget *wid, guint action, + gint x, gint y) { + if (wid == NULL) { + return FALSE; + } + if (wid->trigger_action == NULL) { + return FALSE; + } + /* + * TODO: We should probably add a check_action callback to the widgets + * to do extra checks + */ + return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; +} + WidgetTriggerActionResult widget_trigger_action(widget *wid, guint action, gint x, gint y) { if (wid == NULL) { diff --git a/subprojects/libnkutils b/subprojects/libnkutils index 6164baca..24377c9d 160000 --- a/subprojects/libnkutils +++ b/subprojects/libnkutils @@ -1 +1 @@ -Subproject commit 6164bacaef10031ce77380499cfad2ae818ab6b0 +Subproject commit 24377c9d163b520778ce6511f3d649e1dc4521d2 diff --git a/test/mode-test.c b/test/mode-test.c index 2c4c7216..8b76d65d 100644 --- a/test/mode-test.c +++ b/test/mode-test.c @@ -97,10 +97,13 @@ RofiViewState * rofi_view_get_active ( void ) { return NULL; } -gboolean rofi_view_trigger_action ( G_GNUC_UNUSED RofiViewState *state, G_GNUC_UNUSED BindingsScope scope, G_GNUC_UNUSED guint action ) +gboolean rofi_view_check_action ( G_GNUC_UNUSED RofiViewState *state, G_GNUC_UNUSED BindingsScope scope, G_GNUC_UNUSED guint action ) { return FALSE; } +void rofi_view_trigger_action ( G_GNUC_UNUSED RofiViewState *state, G_GNUC_UNUSED BindingsScope scope, G_GNUC_UNUSED guint action ) +{ +} void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data ) {