[gtk/wip/matthiasc/shortcut-2] shortcutmanager: Add a trigger lookup function
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/shortcut-2] shortcutmanager: Add a trigger lookup function
- Date: Mon, 23 Mar 2020 18:48:18 +0000 (UTC)
commit 6c44b6bc80c64a3be1f38c3f01ff06a1c25e8eb7
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Mar 23 14:45:38 2020 -0400
shortcutmanager: Add a trigger lookup function
This function finds a trigger, given a shortcut action
and a target widget.
gtk/gtkshortcutmanager.c | 38 ++++++++++++++++++++++++++++++++++++++
gtk/gtkshortcutmanager.h | 4 ++++
2 files changed, 42 insertions(+)
---
diff --git a/gtk/gtkshortcutmanager.c b/gtk/gtkshortcutmanager.c
index 625e594d84..f73a32c521 100644
--- a/gtk/gtkshortcutmanager.c
+++ b/gtk/gtkshortcutmanager.c
@@ -22,6 +22,7 @@
#include "gtkshortcutmanager.h"
#include "gtkshortcutmanagerprivate.h"
#include "gtkflattenlistmodel.h"
+#include "gtkshortcut.h"
/**
* SECTION:gtkshortcutmanager
@@ -121,3 +122,40 @@ gtk_shortcut_manager_default_init (GtkShortcutManagerInterface *iface)
iface->remove_controller = gtk_shortcut_manager_default_remove_controller;
}
+GtkShortcutTrigger *
+gtk_shortcut_manager_get_trigger (GtkShortcutManager *self,
+ GtkShortcutAction *action,
+ GtkWidget *widget)
+{
+ GtkPropagationPhase phase[2] = { GTK_PHASE_CAPTURE, GTK_PHASE_BUBBLE };
+ int i;
+
+ for (i = 0; i < 2; i++)
+ {
+ GListModel *model;
+
+ model = G_LIST_MODEL (gtk_shortcut_manager_get_model (self, phase[i]));
+ if (model)
+ {
+ for (i = 0; i < g_list_model_get_n_items (model); i++)
+ {
+ GtkShortcut *shortcut;
+
+ shortcut = g_list_model_get_item (model, i);
+ g_object_unref (shortcut);
+
+ if (gtk_shortcut_action_equal (action, gtk_shortcut_get_action (shortcut)))
+ {
+ GListModel *child_model = gtk_flatten_list_model_get_model_for_item
(GTK_FLATTEN_LIST_MODEL (model), i);
+ if (GTK_IS_SHORTCUT_CONTROLLER (child_model))
+ {
+ if (widget == gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (child_model)))
+ return gtk_shortcut_get_trigger (shortcut);
+ }
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
diff --git a/gtk/gtkshortcutmanager.h b/gtk/gtkshortcutmanager.h
index 0d4ece9745..c60edb994d 100644
--- a/gtk/gtkshortcutmanager.h
+++ b/gtk/gtkshortcutmanager.h
@@ -65,6 +65,10 @@ struct _GtkShortcutManagerInterface
GtkShortcutController *controller);
};
+GtkShortcutTrigger *
+gtk_shortcut_manager_get_trigger (GtkShortcutManager *self,
+ GtkShortcutAction *action,
+ GtkWidget *widget);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]