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 <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-02-21 14:31:02 +01:00
parent 2feec23561
commit 9d1e3370f4
+3
View File
@@ -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()))