[gnome-shell/wip/carlosg/screenshots-to-clipboard: 2/2] screenshot: Allow saving to clipboard
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/carlosg/screenshots-to-clipboard: 2/2] screenshot: Allow saving to clipboard
- Date: Wed, 6 Nov 2019 13:21:20 +0000 (UTC)
commit 341b26260773ddc0799a725defbff7f4a93e1e35
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Nov 6 00:48:25 2019 +0100
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 | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js
index 24fc896fcf..b836232df4 100644
--- a/js/ui/screenshot.js
+++ b/js/ui/screenshot.js
@@ -122,7 +122,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);
}
@@ -158,7 +166,11 @@ var ScreenshotService = class {
if (!screenshot)
return;
- let [stream, file] = this._createFileStream(filename);
+ let stream, file;
+ if (filename != '')
+ [stream, file] = this._createFileStream(filename);
+ else
+ stream = Gio.MemoryOutputStream.new_resizable();
screenshot.screenshot_area (x, y, width, height, stream,
(o, res) => {
@@ -179,7 +191,11 @@ var ScreenshotService = class {
if (!screenshot)
return;
- let [stream, file] = this._createFileStream(filename);
+ let stream, file;
+ if (filename != '')
+ [stream, file] = this._createFileStream(filename);
+ else
+ stream = Gio.MemoryOutputStream.new_resizable();
screenshot.screenshot_window (includeFrame, includeCursor, stream,
(o, res) => {
@@ -200,7 +216,11 @@ var ScreenshotService = class {
if (!screenshot)
return;
- let [stream, file] = this._createFileStream(filename);
+ let stream, file;
+ if (filename != '')
+ [stream, file] = this._createFileStream(filename);
+ else
+ stream = Gio.MemoryOutputStream.new_resizable();
screenshot.screenshot(includeCursor, stream,
(o, res) => {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]