[gnome-flashback] shell: add UngrabAccelerators



commit 4c6df96397457697be23cfb4f1a09764750d14d0
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed May 29 20:22:00 2019 +0300

    shell: add UngrabAccelerators
    
    Needed by GNOME Settings Daemon.
    
    https://gitlab.gnome.org/GNOME/gnome-settings-daemon/commit/d493f5034cda
    https://gitlab.gnome.org/GNOME/gnome-settings-daemon/merge_requests/103

 gnome-flashback/libshell/flashback-shell.c   | 71 ++++++++++++++++++++++++----
 gnome-flashback/libshell/org.gnome.Shell.xml |  4 ++
 2 files changed, 65 insertions(+), 10 deletions(-)
---
diff --git a/gnome-flashback/libshell/flashback-shell.c b/gnome-flashback/libshell/flashback-shell.c
index 46da6c7..9ef0ed4 100644
--- a/gnome-flashback/libshell/flashback-shell.c
+++ b/gnome-flashback/libshell/flashback-shell.c
@@ -183,6 +183,28 @@ grab_accelerator (FlashbackShell *shell,
   return action;
 }
 
+static gboolean
+ungrab_accelerator (FlashbackShell *shell,
+                    guint           action,
+                    const gchar    *sender)
+{
+  const gchar *grabbed_by;
+  gboolean success;
+
+  grabbed_by = g_hash_table_lookup (shell->grabbed_accelerators,
+                                    GUINT_TO_POINTER (action));
+
+  if (g_strcmp0 (grabbed_by, sender) != 0)
+    return FALSE;
+
+  success = real_ungrab (shell, action);
+
+  if (success)
+    g_hash_table_remove (shell->grabbed_accelerators, GUINT_TO_POINTER (action));
+
+  return success;
+}
+
 static gboolean
 handle_eval (FlashbackDBusShell    *dbus_shell,
              GDBusMethodInvocation *invocation,
@@ -352,23 +374,50 @@ handle_ungrab_accelerator (FlashbackDBusShell    *dbus_shell,
                            gpointer               user_data)
 {
   FlashbackShell *shell;
-  gchar *sender;
-       gboolean success;
+  const gchar *sender;
+  gboolean success;
 
   shell = FLASHBACK_SHELL (user_data);
-  success = FALSE;
-  sender = (gchar *) g_hash_table_lookup (shell->grabbed_accelerators,
-                                          GUINT_TO_POINTER (action));
 
-  if (g_strcmp0 (sender, g_dbus_method_invocation_get_sender (invocation)) == 0)
+  sender = g_dbus_method_invocation_get_sender (invocation);
+  success = ungrab_accelerator (shell, action, sender);
+
+  flashback_dbus_shell_complete_ungrab_accelerator (dbus_shell, invocation, success);
+
+  return TRUE;
+}
+
+static gboolean
+handle_ungrab_accelerators (FlashbackDBusShell    *dbus_shell,
+                            GDBusMethodInvocation *invocation,
+                            GVariant              *actions,
+                            gpointer               user_data)
+{
+  FlashbackShell *shell;
+  const char *sender;
+  gboolean success;
+  GVariantIter iter;
+  GVariant *child;
+
+  shell = FLASHBACK_SHELL (user_data);
+
+  sender = g_dbus_method_invocation_get_sender (invocation);
+  success = TRUE;
+
+  g_variant_iter_init (&iter, actions);
+  while ((child = g_variant_iter_next_value (&iter)))
     {
-      success = real_ungrab (shell, action);
+      guint action;
+
+      g_variant_get (child, "u", &action);
+      g_variant_unref (child);
 
-      if (success)
-        g_hash_table_remove (shell->grabbed_accelerators, GUINT_TO_POINTER (action));
+      success &= ungrab_accelerator (shell, action, sender);
     }
 
-  flashback_dbus_shell_complete_ungrab_accelerator (dbus_shell, invocation, success);
+  flashback_dbus_shell_complete_ungrab_accelerators (dbus_shell,
+                                                     invocation,
+                                                     success);
 
   return TRUE;
 }
@@ -406,6 +455,8 @@ name_appeared_handler (GDBusConnection *connection,
                     G_CALLBACK (handle_grab_accelerators), shell);
   g_signal_connect (skeleton, "handle-ungrab-accelerator",
                     G_CALLBACK (handle_ungrab_accelerator), shell);
+  g_signal_connect (skeleton, "handle-ungrab-accelerators",
+                    G_CALLBACK (handle_ungrab_accelerators), shell);
 
   flashback_dbus_shell_set_mode (skeleton, "");
   flashback_dbus_shell_set_overview_active (skeleton, FALSE);
diff --git a/gnome-flashback/libshell/org.gnome.Shell.xml b/gnome-flashback/libshell/org.gnome.Shell.xml
index 163c0a9..42e2983 100644
--- a/gnome-flashback/libshell/org.gnome.Shell.xml
+++ b/gnome-flashback/libshell/org.gnome.Shell.xml
@@ -32,6 +32,10 @@
       <arg type="u" direction="in" name="action" />
       <arg type="b" direction="out" name="success" />
     </method>
+    <method name="UngrabAccelerators">
+      <arg type="au" direction="in" name="actions" />
+      <arg type="b" direction="out" name="success" />
+    </method>
     <signal name="AcceleratorActivated">
       <arg name="action" type="u" />
       <arg name="parameters" type="a{sv}" />


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