[gnome-shell/wip/carlosg/screenshots-to-clipboard: 3/3] screenshot: Allow saving to clipboard



commit 2cc74ce5d29d034f0a77b89387818c6e54a6ffd0
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

 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 d90890d484..07773e9733 100644
--- a/js/ui/screenshot.js
+++ b/js/ui/screenshot.js
@@ -121,7 +121,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);
     }
@@ -157,7 +165,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) => {
@@ -178,7 +190,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) => {
@@ -199,7 +215,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]