[gnome-settings-daemon/wip/carlosg/x11-clipboard-for-screenshots] media-keys: Use X11 display for clipboard



commit a8923056db3e220efd16a0057daf1f15b60567ed
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Nov 6 14:15:41 2019 +0100

    media-keys: Use X11 display for clipboard
    
    This daemon does not specify to be X11, and arguably "make it able
    to save to clipboard" is hardly a reason. Make it use a X11 display
    specifically for saving screenshots to clipboard, as it's got at
    least some guarantees of working there.
    
    Related: https://gitlab.gnome.org/GNOME/mutter/issues/789

 plugins/media-keys/gsd-screenshot-utils.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/plugins/media-keys/gsd-screenshot-utils.c b/plugins/media-keys/gsd-screenshot-utils.c
index 45f91096..2950ef2d 100644
--- a/plugins/media-keys/gsd-screenshot-utils.c
+++ b/plugins/media-keys/gsd-screenshot-utils.c
@@ -97,6 +97,7 @@ screenshot_save_to_recent (ScreenshotContext *ctx)
 static void
 screenshot_save_to_clipboard (ScreenshotContext *ctx)
 {
+  static GdkDisplay *x11_display = NULL;
   GdkPixbuf *screenshot;
   GtkClipboard *clipboard;
   GError *error = NULL;
@@ -111,8 +112,9 @@ screenshot_save_to_clipboard (ScreenshotContext *ctx)
     }
 
   screenshot_play_sound_effect ("screen-capture", _("Screenshot taken"));
-  clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
-                                             GDK_SELECTION_CLIPBOARD);
+  if (!x11_display)
+    x11_display = gdk_display_open (g_getenv ("DISPLAY"));
+  clipboard = gtk_clipboard_get_for_display (x11_display, GDK_SELECTION_CLIPBOARD);
   gtk_clipboard_set_image (clipboard, screenshot);
 
   /* remove the temporary file created by the shell */


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