From cf6beee9e23b2445160b1aecf04df21ea7613ad7 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 6 Nov 2019 00:48:25 +0100 Subject: [PATCH] screenshot: Allow saving to clipboard If no target file is specified (i.e. filename is an empty string), the screenshot will be stored on the clipboard instead. https://gitlab.gnome.org/GNOME/mutter/issues/789 https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/810 --- js/ui/screenshot.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js index c50c4a363..11f8afa44 100644 --- a/js/ui/screenshot.js +++ b/js/ui/screenshot.js @@ -86,6 +86,9 @@ var ScreenshotService = class { } _createStream(filename) { + if (filename == '') + return [Gio.MemoryOutputStream.new_resizable(), null]; + if (GLib.path_is_absolute(filename)) { try { let file = Gio.File.new_for_path(filename); @@ -123,7 +126,15 @@ var ScreenshotService = class { stream.close(null); - let filenameUsed = file.get_path(); + let filenameUsed = ''; + if (file) { + filenameUsed = file.get_path(); + } else { + let bytes = stream.steal_as_bytes(); + let clipboard = St.Clipboard.get_default(); + clipboard.set_content(St.ClipboardType.CLIPBOARD, 'image/png', bytes); + } + let retval = GLib.Variant.new('(bs)', [result, filenameUsed]); invocation.return_value(retval); }