From f5c9d2725c7bbb7a86410527402bdd918f9f399c Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sat, 11 Dec 2021 14:28:51 -0500 Subject: [PATCH] app: X11 clipboard: write to primary selection This change is to augment the X11 clipboard write behaviour. When writing to the clipboard both the primary and clipboard selections are published so that non-GIO applications that read the primary selection (i.e. such as terminal emulators using middle-mouse clicks) can read the data from a GIO app. Signed-off-by: Jeff Williams --- app/os_x11.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/os_x11.go b/app/os_x11.go index 79a063d5..56b4822b 100644 --- a/app/os_x11.go +++ b/app/os_x11.go @@ -70,6 +70,8 @@ type x11Window struct { targets C.Atom // "CLIPBOARD". clipboard C.Atom + // "PRIMARY". + primary C.Atom // "CLIPBOARD_CONTENT", the clipboard destination property. clipboardContent C.Atom // "WM_DELETE_WINDOW" @@ -150,6 +152,7 @@ func (w *x11Window) ReadClipboard() { func (w *x11Window) WriteClipboard(s string) { w.clipboard.content = []byte(s) C.XSetSelectionOwner(w.x, w.atoms.clipboard, w.xw, C.CurrentTime) + C.XSetSelectionOwner(w.x, w.atoms.primary, w.xw, C.CurrentTime) } func (w *x11Window) Configure(options []Option) { @@ -603,7 +606,7 @@ func (h *x11EventHandler) handleEvents() bool { w.w.Event(clipboard.Event{Text: str}) case C.SelectionRequest: cevt := (*C.XSelectionRequestEvent)(unsafe.Pointer(xev)) - if cevt.selection != w.atoms.clipboard || cevt.property == C.None { + if (cevt.selection != w.atoms.clipboard && cevt.selection != w.atoms.primary) || cevt.property == C.None { // Unsupported clipboard or obsolete requestor. break } @@ -759,6 +762,7 @@ func newX11Window(gioWin *callbacks, options []Option) error { w.atoms.gtk_text_buffer_contents = w.atom("GTK_TEXT_BUFFER_CONTENTS", false) w.atoms.evDelWindow = w.atom("WM_DELETE_WINDOW", false) w.atoms.clipboard = w.atom("CLIPBOARD", false) + w.atoms.primary = w.atom("PRIMARY", false) w.atoms.clipboardContent = w.atom("CLIPBOARD_CONTENT", false) w.atoms.atom = w.atom("ATOM", false) w.atoms.targets = w.atom("TARGETS", false)