From ece75922d1d1dfaa184e8ce43afcc1017af3aead Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 18 Jan 2025 12:22:02 +0300 Subject: [PATCH 1/9] ScreenshotManager: avoid making it static --- src/DBus.vala | 4 ++-- src/ScreenshotManager.vala | 19 +++++-------------- src/WindowManager.vala | 9 ++++----- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/DBus.vala b/src/DBus.vala index 6f92c8ddc..8892e694c 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -11,7 +11,7 @@ public class Gala.DBus { private static WindowManagerGala wm; [DBus (visible = false)] - public static void init (WindowManagerGala _wm) { + public static void init (WindowManagerGala _wm, ScreenshotManager screenshot_manager) { wm = _wm; Bus.own_name (BusType.SESSION, "org.pantheon.gala", BusNameOwnerFlags.NONE, @@ -34,7 +34,7 @@ public class Gala.DBus { (connection) => { try { connection.register_object ("/org/gnome/Shell", DBusAccelerator.init (wm.get_display ())); - connection.register_object ("/org/gnome/Shell/Screenshot", ScreenshotManager.init (wm)); + connection.register_object ("/org/gnome/Shell/Screenshot", screenshot_manager); } catch (Error e) { warning (e.message); } }, () => {}, diff --git a/src/ScreenshotManager.vala b/src/ScreenshotManager.vala index 0ffe44cc0..640cf1a55 100644 --- a/src/ScreenshotManager.vala +++ b/src/ScreenshotManager.vala @@ -21,16 +21,6 @@ namespace Gala { [DBus (name="org.gnome.Shell.Screenshot")] public class ScreenshotManager : Object { - private static ScreenshotManager? instance; - - [DBus (visible = false)] - public static unowned ScreenshotManager init (WindowManager wm) { - if (instance == null) - instance = new ScreenshotManager (wm); - - return instance; - } - private WindowManager wm; private Settings desktop_settings; @@ -39,12 +29,13 @@ namespace Gala { private string prev_font_mono; private uint conceal_timeout; - construct { - desktop_settings = new Settings ("org.gnome.desktop.interface"); + [DBus (visible = false)] + public ScreenshotManager (WindowManager _wm) { + wm = _wm; } - private ScreenshotManager (WindowManager _wm) { - wm = _wm; + construct { + desktop_settings = new Settings ("org.gnome.desktop.interface"); } public void flash_area (int x, int y, int width, int height) throws DBusError, IOError { diff --git a/src/WindowManager.vala b/src/WindowManager.vala index d2e834e16..bf81f5d20 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -71,6 +71,8 @@ namespace Gala { public WindowTracker? window_tracker { get; private set; } + private ScreenshotManager screenshot_manager; + /** * Allow to zoom in/out the entire desktop. */ @@ -187,7 +189,8 @@ namespace Gala { private void show_stage () { unowned Meta.Display display = get_display (); - DBus.init (this); + screenshot_manager = new ScreenshotManager (this); + DBus.init (this, screenshot_manager); DBusAccelerator.init (display); MediaFeedback.init (); @@ -2317,7 +2320,6 @@ namespace Gala { string filename = clipboard ? "" : generate_screenshot_filename (); bool success = false; string filename_used = ""; - unowned var screenshot_manager = ScreenshotManager.init (this); yield screenshot_manager.screenshot_window (true, false, true, filename, out success, out filename_used); } catch (Error e) { // Ignore this error @@ -2330,8 +2332,6 @@ namespace Gala { bool success = false; string filename_used = ""; - unowned var screenshot_manager = ScreenshotManager.init (this); - int x, y, w, h; yield screenshot_manager.select_area (out x, out y, out w, out h); yield screenshot_manager.screenshot_area (x, y, w, h, true, filename, out success, out filename_used); @@ -2345,7 +2345,6 @@ namespace Gala { string filename = clipboard ? "" : generate_screenshot_filename (); bool success = false; string filename_used = ""; - unowned var screenshot_manager = ScreenshotManager.init (this); yield screenshot_manager.screenshot (false, true, filename, out success, out filename_used); } catch (Error e) { // Ignore this error From 38577d7ff1bac106de247e37ddd88d98e2b31698 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 18 Jan 2025 12:31:09 +0300 Subject: [PATCH 2/9] Avoid making DBusAccelerator static --- src/DBus.vala | 4 ++-- src/DBusAccelerator.vala | 13 +------------ src/WindowManager.vala | 6 ++++-- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/DBus.vala b/src/DBus.vala index 8892e694c..a6d1700e7 100644 --- a/src/DBus.vala +++ b/src/DBus.vala @@ -11,7 +11,7 @@ public class Gala.DBus { private static WindowManagerGala wm; [DBus (visible = false)] - public static void init (WindowManagerGala _wm, ScreenshotManager screenshot_manager) { + public static void init (WindowManagerGala _wm, DBusAccelerator dbus_accelerator, ScreenshotManager screenshot_manager) { wm = _wm; Bus.own_name (BusType.SESSION, "org.pantheon.gala", BusNameOwnerFlags.NONE, @@ -33,7 +33,7 @@ public class Gala.DBus { Bus.own_name (BusType.SESSION, "org.gnome.Shell", BusNameOwnerFlags.NONE, (connection) => { try { - connection.register_object ("/org/gnome/Shell", DBusAccelerator.init (wm.get_display ())); + connection.register_object ("/org/gnome/Shell", dbus_accelerator); connection.register_object ("/org/gnome/Shell/Screenshot", screenshot_manager); } catch (Error e) { warning (e.message); } }, diff --git a/src/DBusAccelerator.vala b/src/DBusAccelerator.vala index cae78bb9f..4168c5550 100644 --- a/src/DBusAccelerator.vala +++ b/src/DBusAccelerator.vala @@ -72,23 +72,12 @@ namespace Gala { [DBus (name="org.gnome.Shell")] public class DBusAccelerator { - private static DBusAccelerator? instance; - - [DBus (visible = false)] - public static unowned DBusAccelerator init (Meta.Display display) { - if (instance == null) { - instance = new DBusAccelerator (display); - } - - return instance; - } - public signal void accelerator_activated (uint action, GLib.HashTable parameters); private Meta.Display display; private GLib.HashTable grabbed_accelerators; - private DBusAccelerator (Meta.Display _display) { + public DBusAccelerator (Meta.Display _display) { display = _display; grabbed_accelerators = new HashTable (str_hash, str_equal); display.accelerator_activated.connect (on_accelerator_activated); diff --git a/src/WindowManager.vala b/src/WindowManager.vala index bf81f5d20..abcbba3e9 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -71,6 +71,8 @@ namespace Gala { public WindowTracker? window_tracker { get; private set; } + private DBusAccelerator dbus_accelerator; + private ScreenshotManager screenshot_manager; /** @@ -190,8 +192,8 @@ namespace Gala { unowned Meta.Display display = get_display (); screenshot_manager = new ScreenshotManager (this); - DBus.init (this, screenshot_manager); - DBusAccelerator.init (display); + dbus_accelerator = new DBusAccelerator (display); + DBus.init (this, dbus_accelerator, screenshot_manager); MediaFeedback.init (); WindowListener.init (display); From 7576880f555c113511444c3a4e51ee5e418e0768 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 18 Jan 2025 12:37:43 +0300 Subject: [PATCH 3/9] Introduce NotificationsManager --- src/DBusAccelerator.vala | 20 +++++- src/MediaFeedback.vala | 107 ------------------------------ src/NotificationsManager.vala | 121 ++++++++++++++++++++++++++++++++++ src/WindowManager.vala | 6 +- src/meson.build | 2 +- 5 files changed, 144 insertions(+), 112 deletions(-) delete mode 100644 src/MediaFeedback.vala create mode 100644 src/NotificationsManager.vala diff --git a/src/DBusAccelerator.vala b/src/DBusAccelerator.vala index 4168c5550..a42a19061 100644 --- a/src/DBusAccelerator.vala +++ b/src/DBusAccelerator.vala @@ -72,13 +72,17 @@ namespace Gala { [DBus (name="org.gnome.Shell")] public class DBusAccelerator { + private const string NOTIFICATION_COMPONENT_NAME = "DBusAccelerator"; + public signal void accelerator_activated (uint action, GLib.HashTable parameters); private Meta.Display display; + private NotificationsManager notifications_manager; private GLib.HashTable grabbed_accelerators; - public DBusAccelerator (Meta.Display _display) { + public DBusAccelerator (Meta.Display _display, NotificationsManager _notifications_manager) { display = _display; + notifications_manager = _notifications_manager; grabbed_accelerators = new HashTable (str_hash, str_equal); display.accelerator_activated.connect (on_accelerator_activated); } @@ -165,7 +169,19 @@ namespace Gala { level = (int)(double_level * 100); } - MediaFeedback.send (icon, level); + var hints = new GLib.HashTable (null, null); + hints.set ("x-canonical-private-synchronous", new Variant.string ("gala-feedback")); + hints.set ("value", new Variant.int32 (level)); + + notifications_manager.send ( + new NotificationsManager.NotificationData ( + NOTIFICATION_COMPONENT_NAME, + label, + "", + icon, + hints + ) + ); } } } diff --git a/src/MediaFeedback.vala b/src/MediaFeedback.vala deleted file mode 100644 index b3ec11216..000000000 --- a/src/MediaFeedback.vala +++ /dev/null @@ -1,107 +0,0 @@ -// -// Copyright (C) 2016 Rico Tzschichholz -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -namespace Gala { - [DBus (name = "org.freedesktop.Notifications")] - interface DBusNotifications : GLib.Object { - public abstract uint32 notify (string app_name, uint32 replaces_id, string app_icon, string summary, - string body, string[] actions, HashTable hints, int32 expire_timeout) throws DBusError, IOError; - } - - public class MediaFeedback : GLib.Object { - [Compact] - class Feedback { - public string icon; - public int32 level; - - public Feedback (string _icon, int32 _level) { - icon = _icon; - level = _level; - } - } - - private static MediaFeedback? instance = null; - private static ThreadPool? pool = null; - - public static void init () { - if (instance == null) - instance = new MediaFeedback (); - } - - public static void send (string icon, int val) - requires (instance != null && pool != null) { - try { - pool.add (new Feedback (icon, val)); - } catch (ThreadError e) { - } - } - - private DBusNotifications? notifications = null; - private uint32 notification_id = 0; - - private MediaFeedback () { - Object (); - } - - construct { - try { - pool = new ThreadPool.with_owned_data (send_feedback, 1, false); - } catch (ThreadError e) { - critical ("%s", e.message); - pool = null; - } - - try { - Bus.watch_name (BusType.SESSION, "org.freedesktop.Notifications", BusNameWatcherFlags.NONE, on_watch, on_unwatch); - } catch (IOError e) { - debug (e.message); - } - } - - private void on_watch (DBusConnection conn) { - conn.get_proxy.begin ("org.freedesktop.Notifications", - "/org/freedesktop/Notifications", DBusProxyFlags.NONE, null, (obj, res) => { - try { - notifications = ((DBusConnection) obj).get_proxy.end (res); - } catch (Error e) { - debug (e.message); - notifications = null; - } - }); - } - - private void on_unwatch (DBusConnection conn) { - notifications = null; - } - - private void send_feedback (owned Feedback feedback) { - if (notifications == null) { - return; - } - - var hints = new GLib.HashTable (null, null); - hints.set ("x-canonical-private-synchronous", new Variant.string ("gala-feedback")); - hints.set ("value", new Variant.int32 (feedback.level)); - - try { - notification_id = notifications.notify ("gala-feedback", notification_id, feedback.icon, "", "", {}, hints, 2000); - } catch (Error e) { - critical ("%s", e.message); - } - } - } -} diff --git a/src/NotificationsManager.vala b/src/NotificationsManager.vala new file mode 100644 index 000000000..861369ed0 --- /dev/null +++ b/src/NotificationsManager.vala @@ -0,0 +1,121 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2016 Rico Tzschichholz + * 2025 elementary, Inc. (https://elementary.io) + */ + +/** + * Gala.NotificationsManager can be used to send notifications to org.freedesktop.Notifications + */ + public class Gala.NotificationsManager : GLib.Object { + [DBus (name = "org.freedesktop.Notifications")] + private interface DBusNotifications : GLib.Object { + public abstract uint32 notify (string app_name, uint32 replaces_id, string app_icon, string summary, + string body, string[] actions, HashTable hints, int32 expire_timeout) throws DBusError, IOError; + } + + private const int EXPIRE_TIMEOUT = 2000; + + /** + * Data structure to hold notification data. Component name is used to correctly replace notifications. + */ + [Compact] + public class NotificationData { + public string component_name; + public string summary; + public string body; + public string icon; + public GLib.HashTable hints; + + public NotificationData ( + string _component_name, + string _summary, + string _body, + string _icon, + GLib.HashTable _hints + ) { + component_name = _component_name; + summary = _summary; + body = _body; + icon = _icon; + hints = _hints; + } + } + + private ThreadPool? pool = null; + private DBusNotifications? notifications = null; + private GLib.HashTable replaces_id_table = new GLib.HashTable (str_hash, str_equal); + + construct { + try { + pool = new ThreadPool.with_owned_data (send_feedback, 1, false); + } catch (ThreadError e) { + warning (e.message); + pool = null; + } + + try { + Bus.watch_name (BusType.SESSION, "org.freedesktop.Notifications", BusNameWatcherFlags.NONE, on_watch, on_unwatch); + } catch (IOError e) { + warning (e.message); + } + } + + private void on_watch (DBusConnection conn) { + conn.get_proxy.begin ( + "org.freedesktop.Notifications", "/org/freedesktop/Notifications", DBusProxyFlags.NONE, null, + (obj, res) => { + try { + notifications = ((DBusConnection) obj).get_proxy.end (res); + } catch (Error e) { + warning (e.message); + notifications = null; + } + } + ); + } + + private void on_unwatch (DBusConnection conn) { + notifications = null; + } + + public void send (owned NotificationData notification_data) { + if (pool == null) { + return; + } + + try { + pool.add ((owned) notification_data); + } catch (ThreadError e) { + warning ("NotificationsManager: could't add notificationData: %s", e.message); + } + } + + private void send_feedback (owned NotificationData notification_data) { + if (notifications == null) { + return; + } + + uint32? replaces_id = replaces_id_table.get (notification_data.component_name); + if (replaces_id == null) { + replaces_id = 0; + } + + try { + var notification_id = notifications.notify ( + "gala-feedback", + replaces_id, + notification_data.icon, + notification_data.summary, + notification_data.body, + {}, + notification_data.hints, + EXPIRE_TIMEOUT + ); + + replaces_id_table.insert (notification_data.component_name, notification_id); + } catch (Error e) { + critical (e.message); + } + } +} \ No newline at end of file diff --git a/src/WindowManager.vala b/src/WindowManager.vala index abcbba3e9..1fa0c8641 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -71,6 +71,8 @@ namespace Gala { public WindowTracker? window_tracker { get; private set; } + private NotificationsManager notifications_manager; + private DBusAccelerator dbus_accelerator; private ScreenshotManager screenshot_manager; @@ -191,10 +193,10 @@ namespace Gala { private void show_stage () { unowned Meta.Display display = get_display (); + notifications_manager = new NotificationsManager (); screenshot_manager = new ScreenshotManager (this); - dbus_accelerator = new DBusAccelerator (display); + dbus_accelerator = new DBusAccelerator (display, notifications_manager); DBus.init (this, dbus_accelerator, screenshot_manager); - MediaFeedback.init (); WindowListener.init (display); KeyboardManager.init (display); diff --git a/src/meson.build b/src/meson.build index 9660dd2b8..974b561f5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -7,7 +7,7 @@ gala_bin_sources = files( 'InternalUtils.vala', 'KeyboardManager.vala', 'Main.vala', - 'MediaFeedback.vala', + 'NotificationsManager.vala', 'NotificationStack.vala', 'PantheonShell.vala', 'PluginManager.vala', From 92a01f30308e3e936cc49704bc27d1a0d8f6ad3a Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 18 Jan 2025 12:43:49 +0300 Subject: [PATCH 4/9] Send notification on screenshot --- src/ScreenshotManager.vala | 21 ++++++++++++++++++++- src/WindowManager.vala | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/ScreenshotManager.vala b/src/ScreenshotManager.vala index 640cf1a55..7597a9491 100644 --- a/src/ScreenshotManager.vala +++ b/src/ScreenshotManager.vala @@ -21,7 +21,10 @@ namespace Gala { [DBus (name="org.gnome.Shell.Screenshot")] public class ScreenshotManager : Object { + private const string NOTIFICATION_COMPONENT_NAME = "ScreenshotManager"; + private WindowManager wm; + private NotificationsManager notifications_manager; private Settings desktop_settings; private string prev_font_regular; @@ -30,8 +33,9 @@ namespace Gala { private uint conceal_timeout; [DBus (visible = false)] - public ScreenshotManager (WindowManager _wm) { + public ScreenshotManager (WindowManager _wm, NotificationsManager _notifications_manager) { wm = _wm; + notifications_manager = _notifications_manager; } construct { @@ -93,6 +97,7 @@ namespace Gala { if (success) { play_shutter_sound (); + send_notification (filename == ""); } } @@ -124,6 +129,7 @@ namespace Gala { if (success) { play_shutter_sound (); + send_notification (filename == ""); } else { throw new DBusError.FAILED ("Failed to save image"); } @@ -182,6 +188,7 @@ namespace Gala { if (success) { play_shutter_sound (); + send_notification (filename == ""); } } @@ -382,6 +389,18 @@ namespace Gala { context.play_full (0, props, null); } + private void send_notification (bool clipboard) { + notifications_manager.send ( + new NotificationsManager.NotificationData ( + NOTIFICATION_COMPONENT_NAME, + "Screenshot taken", + clipboard ? _("Screenshot is saved to clipboard") : _("Screenshot saved to screenshots folder"), + "image-x-generic", + new GLib.HashTable (null, null) + ) + ); + } + private Cairo.ImageSurface take_screenshot (int x, int y, int width, int height, bool include_cursor) { Cairo.ImageSurface image; int image_width, image_height; diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 1fa0c8641..a579f51f1 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -194,7 +194,7 @@ namespace Gala { unowned Meta.Display display = get_display (); notifications_manager = new NotificationsManager (); - screenshot_manager = new ScreenshotManager (this); + screenshot_manager = new ScreenshotManager (this, notifications_manager); dbus_accelerator = new DBusAccelerator (display, notifications_manager); DBus.init (this, dbus_accelerator, screenshot_manager); From 191e43cb43c1c8566489c1573020d1d9de55c5c2 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 18 Jan 2025 12:46:53 +0300 Subject: [PATCH 5/9] Fix lint --- src/NotificationsManager.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NotificationsManager.vala b/src/NotificationsManager.vala index 861369ed0..96cf5dd07 100644 --- a/src/NotificationsManager.vala +++ b/src/NotificationsManager.vala @@ -118,4 +118,4 @@ critical (e.message); } } -} \ No newline at end of file +} From 437fbb8daac31ededd8999ce0860796445d39c0f Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 18 Jan 2025 13:12:30 +0300 Subject: [PATCH 6/9] Send notification only when using shortcuts --- src/ScreenshotManager.vala | 17 ----------------- src/WindowManager.vala | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/ScreenshotManager.vala b/src/ScreenshotManager.vala index 7597a9491..dbc44b61e 100644 --- a/src/ScreenshotManager.vala +++ b/src/ScreenshotManager.vala @@ -21,8 +21,6 @@ namespace Gala { [DBus (name="org.gnome.Shell.Screenshot")] public class ScreenshotManager : Object { - private const string NOTIFICATION_COMPONENT_NAME = "ScreenshotManager"; - private WindowManager wm; private NotificationsManager notifications_manager; private Settings desktop_settings; @@ -97,7 +95,6 @@ namespace Gala { if (success) { play_shutter_sound (); - send_notification (filename == ""); } } @@ -129,7 +126,6 @@ namespace Gala { if (success) { play_shutter_sound (); - send_notification (filename == ""); } else { throw new DBusError.FAILED ("Failed to save image"); } @@ -188,7 +184,6 @@ namespace Gala { if (success) { play_shutter_sound (); - send_notification (filename == ""); } } @@ -389,18 +384,6 @@ namespace Gala { context.play_full (0, props, null); } - private void send_notification (bool clipboard) { - notifications_manager.send ( - new NotificationsManager.NotificationData ( - NOTIFICATION_COMPONENT_NAME, - "Screenshot taken", - clipboard ? _("Screenshot is saved to clipboard") : _("Screenshot saved to screenshots folder"), - "image-x-generic", - new GLib.HashTable (null, null) - ) - ); - } - private Cairo.ImageSurface take_screenshot (int x, int y, int width, int height, bool include_cursor) { Cairo.ImageSurface image; int image_width, image_height; diff --git a/src/WindowManager.vala b/src/WindowManager.vala index a579f51f1..3db7343ff 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -2325,6 +2325,10 @@ namespace Gala { bool success = false; string filename_used = ""; yield screenshot_manager.screenshot_window (true, false, true, filename, out success, out filename_used); + + if (success) { + send_screenshot_notification (clipboard); + } } catch (Error e) { // Ignore this error } @@ -2339,6 +2343,10 @@ namespace Gala { int x, y, w, h; yield screenshot_manager.select_area (out x, out y, out w, out h); yield screenshot_manager.screenshot_area (x, y, w, h, true, filename, out success, out filename_used); + + if (success) { + send_screenshot_notification (clipboard); + } } catch (Error e) { // Ignore this error } @@ -2350,9 +2358,25 @@ namespace Gala { bool success = false; string filename_used = ""; yield screenshot_manager.screenshot (false, true, filename, out success, out filename_used); + + if (success) { + send_screenshot_notification (clipboard); + } } catch (Error e) { // Ignore this error } } + + private void send_screenshot_notification (bool clipboard) { + notifications_manager.send ( + new NotificationsManager.NotificationData ( + "ScreenshotManager", + "Screenshot taken", + clipboard ? _("Screenshot is saved to clipboard") : _("Screenshot saved to screenshots folder"), + "image-x-generic", + new GLib.HashTable (null, null) + ) + ); + } } } From 3c0731cb6d587a05014065f8fce7467ca366eb1b Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 25 Jan 2025 18:20:36 +0300 Subject: [PATCH 7/9] Fix build and lint --- src/WindowManager.vala | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 74c6eb15b..3088c5134 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -2341,7 +2341,7 @@ namespace Gala { int x, y, w, h; yield screenshot_manager.select_area (out x, out y, out w, out h); yield screenshot_manager.screenshot_area (x, y, w, h, true, filename, out success, out filename_used); - + if (success) { send_screenshot_notification (clipboard); } @@ -2356,7 +2356,7 @@ namespace Gala { bool success = false; string filename_used = ""; yield screenshot_manager.screenshot (false, true, filename, out success, out filename_used); - + if (success) { send_screenshot_notification (clipboard); } @@ -2366,14 +2366,12 @@ namespace Gala { } private void send_screenshot_notification (bool clipboard) { - notifications_manager.send ( - new NotificationsManager.NotificationData ( - "ScreenshotManager", - "Screenshot taken", - clipboard ? _("Screenshot is saved to clipboard") : _("Screenshot saved to screenshots folder"), - "image-x-generic", - new GLib.HashTable (null, null) - ) + notifications_manager.send.begin ( + "ScreenshotManager", + "image-x-generic", + "Screenshot taken", + clipboard ? _("Screenshot is saved to clipboard") : _("Screenshot saved to screenshots folder"), + new GLib.HashTable (null, null) ); } } From 62fcd55c494b86351aa38abb2ab2e8f506b1c3d1 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 25 Jan 2025 18:52:33 +0300 Subject: [PATCH 8/9] Remove notifications_manager for now --- src/ScreenshotManager.vala | 4 +--- src/WindowManager.vala | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ScreenshotManager.vala b/src/ScreenshotManager.vala index 041f295c7..64b56d966 100644 --- a/src/ScreenshotManager.vala +++ b/src/ScreenshotManager.vala @@ -23,7 +23,6 @@ namespace Gala { [DBus (name="org.gnome.Shell.Screenshot")] public class ScreenshotManager : Object { private WindowManager wm; - private NotificationsManager notifications_manager; private Settings desktop_settings; private string prev_font_regular; @@ -32,9 +31,8 @@ namespace Gala { private uint conceal_timeout; [DBus (visible = false)] - public ScreenshotManager (WindowManager _wm, NotificationsManager _notifications_manager) { + public ScreenshotManager (WindowManager _wm) { wm = _wm; - notifications_manager = _notifications_manager; } construct { diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 3088c5134..e984d5438 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -193,7 +193,7 @@ namespace Gala { unowned Meta.Display display = get_display (); notifications_manager = new NotificationsManager (); - screenshot_manager = new ScreenshotManager (this, notifications_manager); + screenshot_manager = new ScreenshotManager (this); DBus.init (this, notifications_manager, screenshot_manager); WindowListener.init (display); From e81d05ae782f60039548facae6141418d74bc7ac Mon Sep 17 00:00:00 2001 From: lenemter Date: Sat, 25 Jan 2025 20:18:33 +0300 Subject: [PATCH 9/9] Translate notification title --- src/WindowManager.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 02dd2c79e..5c836e39b 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -2371,7 +2371,7 @@ namespace Gala { notifications_manager.send.begin ( "ScreenshotManager", "image-x-generic", - "Screenshot taken", + _("Screenshot taken"), clipboard ? _("Screenshot is saved to clipboard") : _("Screenshot saved to screenshots folder"), new GLib.HashTable (null, null) );