diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-02-11 08:11:58 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-02-11 08:20:10 +0100 |
commit | c899ceff10a01623e7d33c0ea38556113f103afc (patch) | |
tree | f6b26e75baec2a2fd3e1650643dc3331f4299ac0 /src | |
parent | 4d95f46d366c60e2206295812ec267a749f95749 (diff) | |
download | tdv-c899ceff10a01623e7d33c0ea38556113f103afc.tar.gz tdv-c899ceff10a01623e7d33c0ea38556113f103afc.tar.xz tdv-c899ceff10a01623e7d33c0ea38556113f103afc.zip |
sdgui: avoid focusing tab headers by mouse
Our tabs have dummy contents, which causes some complications.
Diffstat (limited to 'src')
-rw-r--r-- | src/sdgui.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/sdgui.c b/src/sdgui.c index 9c0f70d..54ef40d 100644 --- a/src/sdgui.c +++ b/src/sdgui.c @@ -164,6 +164,11 @@ on_switch_page (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GtkWidget *page, g.last = g.dictionary; g.dictionary = page_num; search (g_ptr_array_index (g.dictionaries, g.dictionary)); + + // Hack: Make right-clicking notebook arrows also re-focus the entry. + GdkEvent *event = gtk_get_current_event (); + if (event && event->type == GDK_BUTTON_PRESS) + gtk_widget_grab_focus (g.entry); } static gboolean @@ -240,6 +245,21 @@ on_key_press (G_GNUC_UNUSED GtkWidget *widget, GdkEvent *event, return FALSE; } +static gboolean +on_tab_focus (G_GNUC_UNUSED GtkWidget *widget, + G_GNUC_UNUSED GtkDirectionType direction, G_GNUC_UNUSED gpointer user_data) +{ + // Hack: Make it so that tab headers don't retain newly gained focus + // when clicked, re-focus the entry instead. + GdkEvent *event = gtk_get_current_event (); + if (!event || event->type != GDK_BUTTON_PRESS + || event->button.button != GDK_BUTTON_PRIMARY) + return FALSE; + + gtk_widget_grab_focus (g.entry); + return TRUE; +} + static void init_tabs (void) { @@ -247,6 +267,7 @@ init_tabs (void) { Dictionary *dict = g_ptr_array_index (g.dictionaries, i); GtkWidget *dummy = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + g_signal_connect (dummy, "focus", G_CALLBACK (on_tab_focus), NULL); GtkWidget *label = gtk_label_new (dict->name); gtk_notebook_insert_page (GTK_NOTEBOOK (g.notebook), dummy, label, 0); } |