sdgui: accelerate the hamburger

The hamburger initially resisted being accelerated.
This commit is contained in:
Přemysl Eric Janouch 2021-10-20 08:34:11 +02:00
parent 54ef836eec
commit 85a30d20c3
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -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
@ -157,12 +158,39 @@ on_switch_page (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GtkWidget *page,
search (g_ptr_array_index (g.dictionaries, g.dictionary));
}
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 ();