From 866d82ac753fee0949118ea72cca9f4f0420d9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Wed, 30 Jun 2021 07:48:12 +0200 Subject: [PATCH] screenshot: Play shutter sound We currently rely on Screenshot to play the shutter sound. This means that it needs pulseaudio permissions in Flatpak and depending on the app taking the screenshot you might not get a sound when a screenshot is taken. In addition, no sound was played when a screenshot was copied directly to the clipboard. Play the shutter sound in Gala to avoid this problems. --- src/ScreenshotManager.vala | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ScreenshotManager.vala b/src/ScreenshotManager.vala index 9f43c2f2..072dfa80 100644 --- a/src/ScreenshotManager.vala +++ b/src/ScreenshotManager.vala @@ -90,6 +90,10 @@ namespace Gala { } success = yield save_image (image, filename, out filename_used); + + if (success) { + play_shutter_sound (); + } } public async void screenshot_area (int x, int y, int width, int height, bool flash, string filename, out bool success, out string filename_used) throws DBusError, IOError { @@ -109,8 +113,12 @@ namespace Gala { } success = yield save_image (image, filename, out filename_used); - if (!success) + + if (success) { + play_shutter_sound (); + } else { throw new DBusError.FAILED ("Failed to save image"); + } } public async void screenshot_window (bool include_frame, bool include_cursor, bool flash, string filename, out bool success, out string filename_used) throws DBusError, IOError { @@ -146,6 +154,10 @@ namespace Gala { } success = yield save_image (image, filename, out filename_used); + + if (success) { + play_shutter_sound (); + } } public async void select_area (out int x, out int y, out int width, out int height) throws DBusError, IOError { @@ -312,6 +324,20 @@ namespace Gala { return true; } + private void play_shutter_sound () { + Canberra.Context context; + Canberra.Proplist props; + + Canberra.Context.create (out context); + Canberra.Proplist.create (out props); + + props.sets (Canberra.PROP_EVENT_ID, "screen-capture"); + props.sets (Canberra.PROP_EVENT_DESCRIPTION, _("Screenshot taken")); + props.sets (Canberra.PROP_CANBERRA_CACHE_CONTROL, "permanent"); + + context.play_full (0, props, null); + } + Cairo.ImageSurface take_screenshot (int x, int y, int width, int height, bool include_cursor) { Cairo.ImageSurface image; #if HAS_MUTTER338