[libdazzle] shortcuts: be more lax on shortcut manager discovery



commit cb5a4ff1545b501aabc244afb8527fc370db2eee
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 3 01:14:05 2018 -0700

    shortcuts: be more lax on shortcut manager discovery

 src/shortcuts/dzl-shortcut-tooltip.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/src/shortcuts/dzl-shortcut-tooltip.c b/src/shortcuts/dzl-shortcut-tooltip.c
index 87c570f..292b6c6 100644
--- a/src/shortcuts/dzl-shortcut-tooltip.c
+++ b/src/shortcuts/dzl-shortcut-tooltip.c
@@ -88,6 +88,30 @@ enum {
 
 static GParamSpec *properties [N_PROPS];
 
+static DzlShortcutManager *
+find_manager (GtkWidget *widget)
+{
+  DzlShortcutController *controller;
+  DzlShortcutManager *manager = NULL;
+
+  if (widget == NULL)
+    return NULL;
+
+  if (!(controller = dzl_shortcut_controller_try_find (widget)))
+    {
+      widget = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
+      controller = dzl_shortcut_controller_try_find (widget);
+    }
+
+  if (controller != NULL)
+    manager = dzl_shortcut_controller_get_manager (controller);
+
+  if (manager == NULL)
+    manager = dzl_shortcut_manager_get_default ();
+
+  return manager;
+}
+
 static gboolean
 dzl_shortcut_tooltip_query_cb (DzlShortcutTooltip *self,
                                gint                x,
@@ -96,7 +120,6 @@ dzl_shortcut_tooltip_query_cb (DzlShortcutTooltip *self,
                                GtkTooltip         *tooltip,
                                GtkWidget          *widget)
 {
-  DzlShortcutController *controller;
   const DzlShortcutChord *chord;
   DzlShortcutManager *manager = NULL;
   DzlShortcutTheme *theme = NULL;
@@ -110,9 +133,8 @@ dzl_shortcut_tooltip_query_cb (DzlShortcutTooltip *self,
   g_assert (GTK_IS_WIDGET (widget));
   g_assert (widget == self->widget);
 
-  if ((controller = dzl_shortcut_controller_try_find (widget)) &&
-      (manager = dzl_shortcut_controller_get_manager (controller)))
-    theme = dzl_shortcut_manager_get_theme (manager);
+  manager = find_manager (widget);
+  theme = dzl_shortcut_manager_get_theme (manager);
 
   title = self->title;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]