[xdg-desktop-portal-gnome/gbsneto/screenshot-portal-v3-2: 3/3] screenshotdialog: Skip dialog for non-interactive screenshots




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

    screenshotdialog: Skip dialog for non-interactive screenshots
    
    But only when the screenshot portal is version 3 or greater.
    Before version 3, no portal-sided permissions were asked for
    non-interactive screenshots, so we still have to show some
    indication that the screen content was grabbed; but starting
    from version 3, xdg-desktop-portal queries the user using the
    access portal, so we don't have to do it again.

 src/screenshot.c       |  5 ++++-
 src/screenshotdialog.c | 15 +++++++++++++--
 src/screenshotdialog.h |  1 +
 3 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/src/screenshot.c b/src/screenshot.c
index fe1ea88..1dca27d 100644
--- a/src/screenshot.c
+++ b/src/screenshot.c
@@ -192,7 +192,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,
+                                              screenshot_portal_version,
+                                              interactive,
+                                              shell));
   gtk_window_set_transient_for (dialog, GTK_WINDOW (fake_parent));
   gtk_window_set_modal (dialog, modal);
 
diff --git a/src/screenshotdialog.c b/src/screenshotdialog.c
index 665994b..b42251c 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,
+                       uint32_t screenshot_portal_version,
                        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 = screenshot_portal_version >= 3 && !interactive;
 
   if (interactive)
     show_options (dialog);
diff --git a/src/screenshotdialog.h b/src/screenshotdialog.h
index 9cf7a8f..98b336c 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,
+                                          uint32_t screenshot_portal_version,
                                           gboolean interactive,
                                           OrgGnomeShellScreenshot *shell);


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