Skip to content

Commit

Permalink
applications: Add support for the screenshot permission
Browse files Browse the repository at this point in the history
Add support for managing the screenshot permission, used by apps
who request non-interactive screenshots from the portal.

See also flatpak/xdg-desktop-portal#851
  • Loading branch information
GeorgesStavracas committed Aug 8, 2022
1 parent 6fd7164 commit c6991bc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
40 changes: 40 additions & 0 deletions panels/applications/cc-applications-panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct _CcApplicationsPanel
CcToggleRow *notification;
CcToggleRow *background;
CcToggleRow *wallpaper;
CcToggleRow *screenshot;
CcToggleRow *sound;
CcInfoRow *no_sound;
CcToggleRow *search;
Expand Down Expand Up @@ -515,6 +516,37 @@ wallpaper_cb (CcApplicationsPanel *self)
set_wallpaper_allowed (self, cc_toggle_row_get_allowed (self->wallpaper));
}

/* --- screenshot --- */

static void
get_screenshot_allowed (CcApplicationsPanel *self,
const gchar *app_id,
gboolean *set,
gboolean *allowed)
{
g_auto(GStrv) perms = get_portal_permissions (self, "screenshot", "screenshot", app_id);

*set = perms != NULL;
*allowed = perms == NULL || strcmp (perms[0], "no") != 0;
}

static void
set_screenshot_allowed (CcApplicationsPanel *self,
gboolean allowed)
{
const gchar *perms[2] = { NULL, NULL };

perms[0] = allowed ? "yes" : "no";
set_portal_permissions (self, "screenshot", "screenshot", self->current_app_id, perms);
}

static void
screenshot_cb (CcApplicationsPanel *self)
{
if (self->current_app_id)
set_screenshot_allowed (self, cc_toggle_row_get_allowed (self->screenshot));
}

/* --- shortcuts permissions (flatpak) --- */

static void
Expand Down Expand Up @@ -894,6 +926,11 @@ update_integration_section (CcApplicationsPanel *self,
gtk_widget_set_visible (GTK_WIDGET (self->wallpaper), set);
has_any |= set;

get_screenshot_allowed (self, portal_app_id, &set, &allowed);
cc_toggle_row_set_allowed (self->screenshot, allowed);
gtk_widget_set_visible (GTK_WIDGET (self->screenshot), set);
has_any |= set;

disabled = g_settings_get_boolean (self->privacy_settings, "disable-sound-output");
get_device_allowed (self, "speakers", portal_app_id, &set, &allowed);
cc_toggle_row_set_allowed (self->sound, allowed);
Expand Down Expand Up @@ -935,6 +972,7 @@ update_integration_section (CcApplicationsPanel *self,

gtk_widget_hide (GTK_WIDGET (self->background));
gtk_widget_hide (GTK_WIDGET (self->wallpaper));
gtk_widget_hide (GTK_WIDGET (self->screenshot));
gtk_widget_hide (GTK_WIDGET (self->sound));
gtk_widget_hide (GTK_WIDGET (self->no_sound));
gtk_widget_hide (GTK_WIDGET (self->camera));
Expand Down Expand Up @@ -1744,6 +1782,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, screenshot);
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, shortcuts);
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, sidebar_box);
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, sidebar_listbox);
Expand All @@ -1765,6 +1804,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, screenshot_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);
Expand Down
7 changes: 7 additions & 0 deletions panels/applications/cc-applications-panel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@
<signal name="notify::allowed" handler="background_cb" swapped="yes"/>
</object>
</child>
<child>
<object class="CcToggleRow" id="screenshot">
<property name="title" translatable="yes">Screenshots</property>
<property name="subtitle" translatable="yes">Take screenshots of the desktop.</property>
<signal name="notify::allowed" handler="screenshot_cb" object="CcApplicationsPanel" swapped="yes"/>
</object>
</child>
<child>
<object class="CcToggleRow" id="wallpaper">
<property name="title" translatable="yes">Change Wallpaper</property>
Expand Down

0 comments on commit c6991bc

Please sign in to comment.