aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-10-20 08:34:11 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-10-20 08:35:00 +0200
commit85a30d20c373383fdec7740ed655f8a9a6da5efd (patch)
tree5e779d304d28ca81b75a27294f033241f9321790 /src
parent54ef836eecf62d4f6c0ecc9746c925c60fba9946 (diff)
downloadtdv-85a30d20c373383fdec7740ed655f8a9a6da5efd.tar.gz
tdv-85a30d20c373383fdec7740ed655f8a9a6da5efd.tar.xz
tdv-85a30d20c373383fdec7740ed655f8a9a6da5efd.zip
sdgui: accelerate the hamburger
The hamburger initially resisted being accelerated.
Diffstat (limited to 'src')
-rw-r--r--src/sdgui.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/sdgui.c b/src/sdgui.c
index caae311..d40d2d3 100644
--- a/src/sdgui.c
+++ b/src/sdgui.c
@@ -30,6 +30,7 @@ static struct
{
GtkWidget *window; ///< Top-level window
GtkWidget *notebook; ///< Notebook with tabs
+ GtkWidget *hamburger; ///< Hamburger menu
GtkWidget *entry; ///< Search entry widget
GtkWidget *view; ///< Entries view
@@ -158,11 +159,38 @@ on_switch_page (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GtkWidget *page,
}
static gboolean
+accelerate_hamburger (GdkEvent *event)
+{
+ gchar *accelerator = NULL;
+ g_object_get (gtk_widget_get_settings (g.window), "gtk-menu-bar-accel",
+ &accelerator, NULL);
+ if (!accelerator)
+ return FALSE;
+
+ guint key = 0;
+ GdkModifierType mods = 0;
+ gtk_accelerator_parse (accelerator, &key, &mods);
+ g_free (accelerator);
+ if (!key || event->key.keyval != key || event->key.state != mods)
+ return FALSE;
+
+ gtk_button_clicked (GTK_BUTTON (g.hamburger));
+ return TRUE;
+}
+
+static gboolean
on_key_press (G_GNUC_UNUSED GtkWidget *widget, GdkEvent *event,
G_GNUC_UNUSED gpointer data)
{
+ // The "activate" signal of the GtkMenuButton cannot be used
+ // from a real accelerator, due to "no trigger event for menu popup".
+ if (accelerate_hamburger (event))
+ return TRUE;
+
if (event->key.state == GDK_CONTROL_MASK)
{
+ // Can't use gtk_widget_add_accelerator() to change-current-page(-1/+1)
+ // because that signal has arguments, which cannot be passed.
if (event->key.keyval == GDK_KEY_Page_Up)
{
gtk_notebook_prev_page (GTK_NOTEBOOK (g.notebook));
@@ -294,14 +322,15 @@ main (int argc, char *argv[])
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show_all (menu);
- GtkWidget *hamburger = gtk_menu_button_new ();
- gtk_menu_button_set_direction (GTK_MENU_BUTTON (hamburger), GTK_ARROW_NONE);
- gtk_menu_button_set_popup (GTK_MENU_BUTTON (hamburger), menu);
- gtk_button_set_relief (GTK_BUTTON (hamburger), GTK_RELIEF_NONE);
- gtk_widget_show (hamburger);
+ g.hamburger = gtk_menu_button_new ();
+ gtk_menu_button_set_direction
+ (GTK_MENU_BUTTON (g.hamburger), GTK_ARROW_NONE);
+ gtk_menu_button_set_popup (GTK_MENU_BUTTON (g.hamburger), menu);
+ gtk_button_set_relief (GTK_BUTTON (g.hamburger), GTK_RELIEF_NONE);
+ gtk_widget_show (g.hamburger);
gtk_notebook_set_action_widget
- (GTK_NOTEBOOK (g.notebook), hamburger, GTK_PACK_END);
+ (GTK_NOTEBOOK (g.notebook), g.hamburger, GTK_PACK_END);
// FIXME: when the clear icon shows, the widget changes in height
g.entry = gtk_search_entry_new ();