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.
This commit is contained in:
Olivier Fourdan 2020-03-05 15:10:47 +01:00
parent a810088d5b
commit 6428355436
2 changed files with 65 additions and 0 deletions

View file

@ -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);

View file

@ -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"/>