[gtk/wip/matthiasc/popup2: 34/51] popup: Add more keybindings
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/popup2: 34/51] popup: Add more keybindings
- Date: Mon, 18 Mar 2019 12:48:02 +0000 (UTC)
commit e5f33e8bd373cd6bcdc75baa8d2304a45213954d
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 3 23:26:00 2019 -0500
popup: Add more keybindings
This makes Enter and Space work to activate things.
gtk/gtkpopup.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkpopup.h | 5 +++++
2 files changed, 55 insertions(+)
---
diff --git a/gtk/gtkpopup.c b/gtk/gtkpopup.c
index 1a98d75ecc..33df24f531 100644
--- a/gtk/gtkpopup.c
+++ b/gtk/gtkpopup.c
@@ -29,6 +29,7 @@
#include "gtkenums.h"
#include "gtktypebuiltins.h"
#include "gtkmnemonichash.h"
+#include "gtkintl.h"
#include "gdk/gdkeventsprivate.h"
static GListStore *popup_list = NULL;
@@ -44,6 +45,13 @@ typedef struct {
GtkMnemonicHash *mnemonic_hash;
} GtkPopupPrivate;
+enum {
+ ACTIVATE_FOCUS,
+ ACTIVATE_DEFAULT,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
static void gtk_popup_root_interface_init (GtkRootInterface *iface);
@@ -418,6 +426,18 @@ gtk_popup_get_property (GObject *object,
}
}
+static void
+gtk_popup_activate_default (GtkPopup *popup)
+{
+ gtk_root_activate_default (GTK_ROOT (popup));
+}
+
+static void
+gtk_popup_activate_focus (GtkPopup *popup)
+{
+ gtk_root_activate_focus (GTK_ROOT (popup));
+}
+
static void
add_tab_bindings (GtkBindingSet *binding_set,
GdkModifierType modifiers,
@@ -457,14 +477,44 @@ gtk_popup_class_init (GtkPopupClass *klass)
widget_class->size_allocate = gtk_popup_size_allocate;
widget_class->move_focus = gtk_popup_move_focus;
+ klass->activate_default = gtk_popup_activate_default;
+ klass->activate_focus = gtk_popup_activate_focus;
+
gtk_root_install_properties (object_class, 1);
+ signals[ACTIVATE_FOCUS] =
+ g_signal_new (I_("activate-focus"),
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GtkPopupClass, activate_focus),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE,
+ 0);
+
+ signals[ACTIVATE_DEFAULT] =
+ g_signal_new (I_("activate-default"),
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GtkPopupClass, activate_default),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE,
+ 0);
+
binding_set = gtk_binding_set_by_class (klass);
add_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0, "activate-focus", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0, "activate-focus", 0);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0, "activate-default", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0, "activate-default", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0, "activate-default", 0);
}
GtkWidget *
diff --git a/gtk/gtkpopup.h b/gtk/gtkpopup.h
index ac745cfd64..c90f3597a4 100644
--- a/gtk/gtkpopup.h
+++ b/gtk/gtkpopup.h
@@ -47,6 +47,11 @@ struct _GtkPopup
struct _GtkPopupClass
{
GtkBinClass parent_class;
+
+ /* keybinding signals */
+
+ void (* activate_focus) (GtkPopup *popup);
+ void (* activate_default) (GtkPopup *popup);
};
GDK_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]