[gnome-control-center] applications: Add shortcuts permissions



commit 64283554360efac98c89a1840921476196940878
Author: Olivier Fourdan <ofourdan redhat com>
Date:   Thu Mar 5 15:10:47 2020 +0100

    applications: Add shortcuts permissions
    
    gnome-shell saves the user choice for applications allowed to disable
    regular shortcuts in the permission store, using "GRANTED" or "DENIED"
    (in gnome-shell/js/ui/inhibitShortcutsDialog.js).
    
    Add a new entry to change that permission in the application panel,
    similar to what gnome-shell does.

 panels/applications/cc-applications-panel.c  | 59 ++++++++++++++++++++++++++++
 panels/applications/cc-applications-panel.ui |  6 +++
 2 files changed, 65 insertions(+)
---
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index 0e192fe910..c75b86660e 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -94,6 +94,7 @@ struct _CcApplicationsPanel
   CcInfoRow       *no_camera;
   CcToggleRow     *location;
   CcInfoRow       *no_location;
+  CcToggleRow     *shortcuts;
   CcToggleRow     *microphone;
   CcInfoRow       *no_microphone;
   CcInfoRow       *builtin;
@@ -511,6 +512,50 @@ wallpaper_cb (CcApplicationsPanel *self)
     set_wallpaper_allowed (self, cc_toggle_row_get_allowed (self->wallpaper));
 }
 
+/* --- shortcuts permissions (flatpak) --- */
+
+static void
+get_shortcuts_allowed (CcApplicationsPanel *self,
+                       const gchar         *app_id,
+                       gboolean            *set,
+                       gboolean            *granted)
+{
+  g_auto(GStrv) perms = NULL;
+
+  perms = get_portal_permissions (self, "gnome", "shortcuts-inhibitor", app_id);
+
+  /* GNOME Shell's "inhibit shortcut dialog" sets the permission to "GRANTED" if
+   * the user allowed for the keyboard shortcuts to be inhibited, check for that
+   * string value here.
+   */
+  *set = perms != NULL;
+  *granted = (perms != NULL) && g_ascii_strcasecmp (perms[0], "GRANTED") == 0;
+}
+
+static void
+set_shortcuts_allowed (CcApplicationsPanel *self,
+                       gboolean             granted)
+{
+  const gchar *perms[2];
+  g_autofree gchar *desktop_id = g_strconcat (self->current_app_id, ".desktop", NULL);
+
+  /* "GRANTED" and "DENIED" here match the values set by the "inhibit shortcut
+   * dialog" is GNOME Shell:
+   * https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/master/js/ui/inhibitShortcutsDialog.js
+   */
+  perms[0] = granted ? "GRANTED" : "DENIED";
+  perms[1] = NULL;
+
+  set_portal_permissions (self, "gnome", "shortcuts-inhibitor", desktop_id, perms);
+}
+
+static void
+shortcuts_cb (CcApplicationsPanel *self)
+{
+  if (self->current_app_id)
+    set_shortcuts_allowed (self, cc_toggle_row_get_allowed (self->shortcuts));
+}
+
 /* --- device (microphone, camera, speaker) permissions (flatpak) --- */
 
 static void
@@ -872,6 +917,18 @@ update_integration_section (CcApplicationsPanel *self,
   gtk_widget_set_visible (GTK_WIDGET (self->search), set && !disabled);
   gtk_widget_set_visible (GTK_WIDGET (self->no_search), set && disabled);
 
+  if (app_id != NULL)
+    {
+      g_autofree gchar *desktop_id = g_strconcat (app_id, ".desktop", NULL);
+      get_shortcuts_allowed (self, desktop_id, &set, &allowed);
+      gtk_widget_set_visible (GTK_WIDGET (self->shortcuts), set);
+      cc_toggle_row_set_allowed (self->shortcuts, allowed);
+    }
+  else
+    {
+      gtk_widget_hide (GTK_WIDGET (self->shortcuts));
+    }
+
   if (portal_app_id != NULL)
     {
       g_clear_object (&self->notification_settings);
@@ -1930,6 +1987,7 @@ cc_applications_panel_class_init (CcApplicationsPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, notification);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, background);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, wallpaper);
+  gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, shortcuts);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, permission_section);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, permission_list);
   gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, sidebar_box);
@@ -1954,6 +2012,7 @@ cc_applications_panel_class_init (CcApplicationsPanelClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, notification_cb);
   gtk_widget_class_bind_template_callback (widget_class, background_cb);
   gtk_widget_class_bind_template_callback (widget_class, wallpaper_cb);
+  gtk_widget_class_bind_template_callback (widget_class, shortcuts_cb);
   gtk_widget_class_bind_template_callback (widget_class, privacy_link_cb);
   gtk_widget_class_bind_template_callback (widget_class, sound_cb);
   gtk_widget_class_bind_template_callback (widget_class, permission_row_activated_cb);
diff --git a/panels/applications/cc-applications-panel.ui b/panels/applications/cc-applications-panel.ui
index 3ab565ddd4..7a08465bfd 100644
--- a/panels/applications/cc-applications-panel.ui
+++ b/panels/applications/cc-applications-panel.ui
@@ -262,6 +262,12 @@
                                 <property name="info" translatable="yes">Disabled</property>
                               </object>
                             </child>
+                            <child>
+                              <object class="CcToggleRow" id="shortcuts">
+                                <property name="title" translatable="yes">Inhibit system keyboard 
shortcuts</property>
+                                <signal name="notify::allowed" handler="shortcuts_cb" swapped="yes"/>
+                              </object>
+                            </child>
                             <style>
                               <class name="view"/>
                               <class name="frame"/>


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