From 73dd5bf1a08c0c6ca1d1312e4e966267a1afda08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?=
Date: Sat, 13 Nov 2021 09:40:10 +0100 Subject: [PATCH] Improve key handling Iteration should be limited to the view. g_signal_connect_after() did not work as I hoped it would. --- fastiv.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/fastiv.c b/fastiv.c index 17fc470..7aee564 100644 --- a/fastiv.c +++ b/fastiv.c @@ -280,6 +280,26 @@ on_key_press(G_GNUC_UNUSED GtkWidget *widget, GdkEventKey *event, on_open(); return TRUE; + case GDK_KEY_Tab: + case GDK_KEY_Return: + gtk_stack_set_visible_child(GTK_STACK(g.stack), + gtk_stack_get_visible_child(GTK_STACK(g.stack)) == + g.view_scroller + ? g.browser_scroller + : g.view_scroller); + return TRUE; + } + } + return FALSE; +} + +static gboolean +on_key_press_view(G_GNUC_UNUSED GtkWidget *widget, GdkEventKey *event, + G_GNUC_UNUSED gpointer data) +{ + switch (event->state & gtk_accelerator_get_default_mod_mask()) { + case 0: + switch (event->keyval) { case GDK_KEY_Left: case GDK_KEY_Up: case GDK_KEY_Page_Up: @@ -292,15 +312,6 @@ on_key_press(G_GNUC_UNUSED GtkWidget *widget, GdkEventKey *event, case GDK_KEY_space: on_next(); return TRUE; - - case GDK_KEY_Tab: - case GDK_KEY_Return: - gtk_stack_set_visible_child(GTK_STACK(g.stack), - gtk_stack_get_visible_child(GTK_STACK(g.stack)) == - g.view_scroller - ? g.browser_scroller - : g.view_scroller); - return TRUE; } } return FALSE; @@ -364,6 +375,8 @@ main(int argc, char *argv[]) g.view = g_object_new(FASTIV_TYPE_VIEW, NULL); gtk_widget_set_vexpand(g.view, TRUE); gtk_widget_set_hexpand(g.view, TRUE); + g_signal_connect(g.view, "key-press-event", + G_CALLBACK(on_key_press_view), NULL); gtk_container_add(GTK_CONTAINER(g.view_scroller), g.view); gtk_widget_show_all(g.view_scroller);