From 0ee72be63745f70a0b277602bed002a85f82326e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 8 May 2024 14:10:32 -0700 Subject: [PATCH] Add Screenshot button --- meson.build | 1 + src/PopoverWidget.vala | 37 +++++++++++++++++++++++++++++++++++++ src/meson.build | 3 ++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index c6d5ab2..5be8107 100644 --- a/meson.build +++ b/meson.build @@ -20,6 +20,7 @@ gtk_dep = dependency('gtk+-3.0') handy_dep = dependency('libhandy-1', version: '>=1.0') wingpanel_dep = dependency('wingpanel') wingpanel_indicatorsdir = wingpanel_dep.get_pkgconfig_variable('indicatorsdir', define_variable: ['libdir', libdir]) +portal_dep = dependency('libportal') subdir('data') subdir('po') diff --git a/src/PopoverWidget.vala b/src/PopoverWidget.vala index 8e33db2..e7f2957 100644 --- a/src/PopoverWidget.vala +++ b/src/PopoverWidget.vala @@ -52,6 +52,11 @@ public class QuickSettings.PopoverWidget : Gtk.Box { }; settings_button.get_style_context ().add_class ("circular"); + var screenshot_button = new Gtk.Button.from_icon_name ("accessories-screenshot-tool-symbolic") { + tooltip_text = _("Take Screenshot…") + }; + screenshot_button.get_style_context ().add_class ("circular"); + var session_box = new SessionBox (server_type) { halign = END, hexpand = true, @@ -60,6 +65,7 @@ public class QuickSettings.PopoverWidget : Gtk.Box { var bottom_box = new Gtk.Box (HORIZONTAL, 0); bottom_box.add (settings_button); + bottom_box.add (screenshot_button); bottom_box.add (session_box); bottom_box.get_style_context ().add_class ("togglebox"); @@ -73,6 +79,7 @@ public class QuickSettings.PopoverWidget : Gtk.Box { if (server_type == GREETER) { bottom_box.remove (settings_button); + bottom_box.remove (screenshot_button); } setup_accounts_services.begin ((obj, res) => { @@ -109,6 +116,36 @@ public class QuickSettings.PopoverWidget : Gtk.Box { } }); + screenshot_button.clicked.connect (() => { + popover.popdown (); + + var portal = new Xdp.Portal (); + portal.take_screenshot.begin (null, INTERACTIVE, null, (obj, res) => { + try { + var file_uri = portal.take_screenshot.end (res); + + var file_icon = new FileIcon (File.new_for_uri (file_uri)); + + var folder_dir = Environment.get_user_special_dir (PICTURES) + "%c".printf (Path.DIR_SEPARATOR) + _("Screenshots"); + + var readable_path = folder_dir.replace (Environment.get_home_dir () + "%c".printf (Path.DIR_SEPARATOR), ""); + + var notification = new Notification (_("Screenshot taken")); + // notification.add_button ( + // _("Open"), + // Action.print_detailed_name ("app.open", new Variant ("s", file_uri)) + // ); + notification.set_body (_("Saved to “%s”").printf (readable_path)); + notification.set_icon (file_icon); + notification.set_priority (LOW); + + GLib.Application.get_default ().send_notification ("screenshot", notification); + } catch (Error e) { + critical (e.message); + } + }); + }); + var applications_settings = new Settings ("org.gnome.desktop.a11y.applications"); applications_settings.bind ("screen-keyboard-enabled", onscreen_keyboard, "active", DEFAULT); applications_settings.bind ("screen-reader-enabled", screen_reader, "active", DEFAULT); diff --git a/src/meson.build b/src/meson.build index 9f2e790..a14c6bb 100644 --- a/src/meson.build +++ b/src/meson.build @@ -35,7 +35,8 @@ shared_module( granite_dep, gtk_dep, handy_dep, - wingpanel_dep + wingpanel_dep, + portal_dep ], install: true, install_dir : wingpanel_indicatorsdir