Skip to content

Commit

Permalink
Send notification only when using shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter committed Jan 18, 2025
1 parent 191e43c commit 437fbb8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
17 changes: 0 additions & 17 deletions src/ScreenshotManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,7 +95,6 @@ namespace Gala {

if (success) {
play_shutter_sound ();
send_notification (filename == "");
}
}

Expand Down Expand Up @@ -129,7 +126,6 @@ namespace Gala {

if (success) {
play_shutter_sound ();
send_notification (filename == "");
} else {
throw new DBusError.FAILED ("Failed to save image");
}
Expand Down Expand Up @@ -188,7 +184,6 @@ namespace Gala {

if (success) {
play_shutter_sound ();
send_notification (filename == "");
}
}

Expand Down Expand Up @@ -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<string, Variant> (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;
Expand Down
24 changes: 24 additions & 0 deletions src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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<string, Variant> (null, null)
)
);
}
}
}

0 comments on commit 437fbb8

Please sign in to comment.