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
This commit is contained in:
Carlos Garnacho 2019-11-06 00:48:25 +01:00 committed by Florian Müllner
parent be5f5ec9d4
commit cf6beee9e2

View File

@ -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);
}