From 59f07023d489bee32764a12c6e9af1a182c6aa70 Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Mon, 22 Jun 2020 17:20:34 +0200 Subject: [PATCH] app/internal: [X11] implement Window.Close Signed-off-by: Sebastien Binet --- app/internal/window/os_x11.go | 19 +++++++++++++++++-- app/window.go | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/internal/window/os_x11.go b/app/internal/window/os_x11.go index a0ece140..42749b03 100644 --- a/app/internal/window/os_x11.go +++ b/app/internal/window/os_x11.go @@ -110,8 +110,23 @@ func (w *x11Window) WriteClipboard(s string) { func (w *x11Window) ShowTextInput(show bool) {} -// Close the window. Not implemented for X11. -func (w *x11Window) Close() {} +// Close the window. +func (w *x11Window) Close() { + w.mu.Lock() + defer w.mu.Unlock() + + ev := C.XClientMessageEvent{ + _type: C.ClientMessage, + display: w.x, + window: w.xw, + message_type: w.atom("WM_PROTOCOLS", true), + format: 32, + } + arr := (*[5]C.long)(unsafe.Pointer(&ev.data)) + arr[0] = C.long(w.atoms.evDelWindow) + arr[1] = C.CurrentTime + C.XSendEvent(w.x, w.xw, C.False, C.NoEventMask, (*C.XEvent)(unsafe.Pointer(&ev))) +} var x11OneByte = make([]byte, 1) diff --git a/app/window.go b/app/window.go index 6b665112..2c9860cb 100644 --- a/app/window.go +++ b/app/window.go @@ -211,7 +211,7 @@ func (w *Window) WriteClipboard(s string) { // Close the window. The window's event loop should exit when it receives // system.DestroyEvent. // -// Currently, only macOS and Windows driver implements this functionality, +// Currently, only macOS, Windows and X11 drivers implement this functionality, // all others are stubbed. func (w *Window) Close() { w.driverDo(func() {