[xdg-desktop-portal-gnome/gbsneto/screenshot-portal-v3-2] screenshot: Implement version 2




commit b9f4fcfd51629db2b70fb5ee7f00872b049ce308
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Aug 5 20:55:09 2022 -0300

    screenshot: Implement version 2
    
    xdg-desktop-portal 1.15.0 has an update to the Screenshot portal
    D-Bus API for frontends, with a version bump. This new version
    also contains a behavioural change where, if the frontend implements
    version 2, it'll request the 'screenshot' permission. This allows
    us to skip the permission dialog in this case.
    
    Implement version 2 of org.freedesktop.portal.impl.Screenshot, and
    skip the screenshot dialog when we know that a permission has been
    granted, and when the screenshot is non-interactive.

 .gitlab-ci.yml         |  4 ++--
 src/meson.build        |  2 +-
 src/screenshot.c       |  9 ++++++++-
 src/screenshotdialog.c | 15 +++++++++++++--
 src/screenshotdialog.h |  1 +
 5 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1992e1e..092db49 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -23,7 +23,7 @@ build-fedora:
       meson . _build --prefix /usr -Ddesktop_docs=false &&
       ninja -C _build install &&
       cd ..
-    - git clone -b 1.14.0 https://github.com/flatpak/xdg-desktop-portal.git &&
+    - git clone -b 1.15.0 https://github.com/flatpak/xdg-desktop-portal.git &&
       cd xdg-desktop-portal &&
       ./autogen.sh --sysconfdir=/etc --prefix=/usr --disable-dependency-tracking --disable-libportal &&
       make -j $(getconf _NPROCESSORS_ONLN) &&
@@ -46,7 +46,7 @@ build-ubuntu:
       meson . _build --prefix /usr -Ddesktop_docs=false &&
       ninja -C _build install &&
       cd ..
-    - git clone -b 1.14.0 https://github.com/flatpak/xdg-desktop-portal.git &&
+    - git clone -b 1.15.0 https://github.com/flatpak/xdg-desktop-portal.git &&
       cd xdg-desktop-portal &&
       ./autogen.sh --sysconfdir=/etc --prefix=/usr --disable-dependency-tracking --disable-libportal &&
       make -j $(getconf _NPROCESSORS_ONLN) &&
diff --git a/src/meson.build b/src/meson.build
index f70f904..c472f98 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,7 +1,7 @@
 gnome = import('gnome')
 pkg = import('pkgconfig')
 
-xdg_desktop_portal_dep = dependency('xdg-desktop-portal', version: '>= 1.14.0')
+xdg_desktop_portal_dep = dependency('xdg-desktop-portal', version: '>= 1.15.0')
 
 # Desktop Portal D-Bus interfaces
 desktop_portal_interfaces_dir = xdg_desktop_portal_dep.get_pkgconfig_variable('interfaces_dir')
diff --git a/src/screenshot.c b/src/screenshot.c
index 73314b6..4622a2f 100644
--- a/src/screenshot.c
+++ b/src/screenshot.c
@@ -154,6 +154,7 @@ handle_screenshot (XdpImplScreenshot *object,
   g_autoptr(Request) request = NULL;
   const char *sender;
   ScreenshotDialogHandle *handle;
+  gboolean permission_store_checked;
   gboolean modal;
   gboolean interactive;
   GtkWindow *dialog;
@@ -171,6 +172,8 @@ handle_screenshot (XdpImplScreenshot *object,
 
   if (!g_variant_lookup (arg_options, "interactive", "b", &interactive))
     interactive = FALSE;
+  if (!g_variant_lookup (arg_options, "permission_store_checked", "b", &permission_store_checked))
+    permission_store_checked = FALSE;
 
   if (arg_parent_window)
     {
@@ -190,7 +193,10 @@ handle_screenshot (XdpImplScreenshot *object,
                               NULL);
   g_object_ref_sink (fake_parent);
 
-  dialog = GTK_WINDOW (screenshot_dialog_new (arg_app_id, interactive, shell));
+  dialog = GTK_WINDOW (screenshot_dialog_new (arg_app_id,
+                                              permission_store_checked,
+                                              interactive,
+                                              shell));
   gtk_window_set_transient_for (dialog, GTK_WINDOW (fake_parent));
   gtk_window_set_modal (dialog, modal);
 
@@ -297,6 +303,7 @@ screenshot_init (GDBusConnection *bus,
   GDBusInterfaceSkeleton *helper;
 
   helper = G_DBUS_INTERFACE_SKELETON (xdp_impl_screenshot_skeleton_new ());
+  xdp_impl_screenshot_set_version (XDP_IMPL_SCREENSHOT (helper), 2);
 
   g_signal_connect (helper, "handle-screenshot", G_CALLBACK (handle_screenshot), NULL);
   g_signal_connect (helper, "handle-pick-color", G_CALLBACK (handle_pick_color), NULL);
diff --git a/src/screenshotdialog.c b/src/screenshotdialog.c
index 665994b..1ab4cc9 100644
--- a/src/screenshotdialog.c
+++ b/src/screenshotdialog.c
@@ -32,6 +32,7 @@ struct _ScreenshotDialog {
 
   OrgGnomeShellScreenshot *shell;
   GCancellable *cancellable;
+  gboolean skip_dialog;
 };
 
 struct _ScreenshotDialogClass {
@@ -140,8 +141,16 @@ static void
 maybe_show_screenshot (ScreenshotDialog *dialog,
                        const char       *filename)
 {
-  show_screenshot (dialog, filename);
-  gtk_widget_show (GTK_WIDGET (dialog));
+  if (dialog->skip_dialog)
+    {
+      gtk_widget_hide (GTK_WIDGET (dialog));
+      g_signal_emit (dialog, signals[DONE], 0, GTK_RESPONSE_OK, filename);
+    }
+  else
+    {
+      show_screenshot (dialog, filename);
+      gtk_widget_show (GTK_WIDGET (dialog));
+    }
 }
 
 static void
@@ -407,6 +416,7 @@ screenshot_dialog_class_init (ScreenshotDialogClass *class)
 
 ScreenshotDialog *
 screenshot_dialog_new (const char *app_id,
+                       gboolean permission_store_checked,
                        gboolean interactive,
                        OrgGnomeShellScreenshot *shell)
 {
@@ -431,6 +441,7 @@ screenshot_dialog_new (const char *app_id,
   gtk_label_set_label (GTK_LABEL (dialog->heading), heading);
 
   dialog->shell = g_object_ref (shell);
+  dialog->skip_dialog = permission_store_checked && !interactive;
 
   if (interactive)
     show_options (dialog);
diff --git a/src/screenshotdialog.h b/src/screenshotdialog.h
index 9cf7a8f..5afc38e 100644
--- a/src/screenshotdialog.h
+++ b/src/screenshotdialog.h
@@ -8,5 +8,6 @@ typedef struct _ScreenshotDialog ScreenshotDialog;
 typedef struct _ScreenshotDialogClass ScreenshotDialogClass;
 
 ScreenshotDialog * screenshot_dialog_new (const char *app_id,
+                                          gboolean permission_store_checked,
                                           gboolean interactive,
                                           OrgGnomeShellScreenshot *shell);


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