From 9d1e3370f4ece1e8781456d776788296cc155598 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 21 Feb 2021 14:31:02 +0100 Subject: [PATCH] app/internal/window: fix Wayland clipboard reading The Wayland protocol implicitly dup(2)s the pipe write end descriptor passed to wl_data_offer_receive. As long as we also have an open descriptor for the write end, the pipe will not close and signal the completion of the clipboard read. This change explicitly and immediately closes our write descriptor. Before this change, reading the Wayland clipboard worked with some delay because the Go garbage collector closed the write end of the transfer pipe after some time. Signed-off-by: Elias Naur --- app/internal/window/os_wayland.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/internal/window/os_wayland.go b/app/internal/window/os_wayland.go index cee2128c..0bc37c23 100644 --- a/app/internal/window/os_wayland.go +++ b/app/internal/window/os_wayland.go @@ -282,6 +282,9 @@ func (d *wlDisplay) readClipboard() (io.ReadCloser, error) { if err != nil { return nil, err } + // wl_data_offer_receive performs and implicit dup(2) of the write end + // of the pipe. Close our version. + defer w.Close() cmimeType := C.CString(s.mimeType) defer C.free(unsafe.Pointer(cmimeType)) C.wl_data_offer_receive(s.clipboard, cmimeType, C.int(w.Fd()))