[libdazzle] shortcuts: activate default actions from theme



commit 09c3fd3d63e8bca6c14f7d57b6dac738c5c8477f
Author: Christian Hergert <chergert redhat com>
Date:   Tue Nov 21 18:43:57 2017 -0800

    shortcuts: activate default actions from theme
    
    If we have actions defined in the theme instead of in the
    GtkApplication action registration, we might need to find these
    in the internal theme.

 src/shortcuts/dzl-shortcut-manager.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/src/shortcuts/dzl-shortcut-manager.c b/src/shortcuts/dzl-shortcut-manager.c
index e7e1274..d59733d 100644
--- a/src/shortcuts/dzl-shortcut-manager.c
+++ b/src/shortcuts/dzl-shortcut-manager.c
@@ -804,6 +804,8 @@ dzl_shortcut_manager_run_fallbacks (DzlShortcutManager     *self,
                                     GtkWidget              *toplevel,
                                     const DzlShortcutChord *chord)
 {
+  DzlShortcutManagerPrivate *priv = dzl_shortcut_manager_get_instance_private (self);
+
   g_assert (DZL_IS_SHORTCUT_MANAGER (self));
   g_assert (GTK_IS_WIDGET (widget));
   g_assert (GTK_IS_WIDGET (toplevel));
@@ -812,6 +814,7 @@ dzl_shortcut_manager_run_fallbacks (DzlShortcutManager     *self,
   if (dzl_shortcut_chord_get_length (chord) == 1)
     {
       GApplication *app = g_application_get_default ();
+      const gchar *action;
       GdkModifierType state;
       guint keyval;
 
@@ -821,6 +824,29 @@ dzl_shortcut_manager_run_fallbacks (DzlShortcutManager     *self,
       if (gtk_bindings_activate (G_OBJECT (toplevel), keyval, state))
         return TRUE;
 
+      /*
+       * See if we have something defined for this theme that
+       * can be activated directly.
+       */
+      action = _dzl_shortcut_theme_lookup_action (priv->internal_theme, chord);
+
+      if (action != NULL)
+        {
+          g_autofree gchar *prefix = NULL;
+          g_autofree gchar *name = NULL;
+          g_autoptr(GVariant) target = NULL;
+
+          dzl_g_action_name_parse_full (action, &prefix, &name, &target);
+
+          if (dzl_gtk_widget_action (toplevel, prefix, name, target))
+            return TRUE;
+        }
+
+      /*
+       * Now fallback to trying to activate the action within GtkApplication
+       * as the legacy Gtk bindings would do.
+       */
+
       if (GTK_IS_APPLICATION (app))
         {
           g_autofree gchar *accel = dzl_shortcut_chord_to_string (chord);
@@ -832,11 +858,12 @@ dzl_shortcut_manager_run_fallbacks (DzlShortcutManager     *self,
             {
               for (guint i = 0; actions[i] != NULL; i++)
                 {
-                  const gchar *action = actions[i];
                   g_autofree gchar *prefix = NULL;
                   g_autofree gchar *name = NULL;
                   g_autoptr(GVariant) param = NULL;
 
+                  action = actions[i];
+
                   if (!dzl_g_action_name_parse_full (action, &prefix, &name, &param))
                     {
                       g_warning ("Failed to parse: %s", action);


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