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



commit cf6beee9e23b2445160b1aecf04df21ea7613ad7
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 | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js
index c50c4a3639..11f8afa445 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);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]