aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-01-07 19:27:08 -0500
committerDavid Robillard <d@drobilla.net>2023-01-07 20:27:35 -0500
commit677e13dcbb5b64ce85093b9ea5c14025964e35b9 (patch)
tree9a96cf4188cdd709093d2c5fe987bcf253d12540 /src/x11.c
parentba11bb80c96fc9c9124ba2fa929425f558f86824 (diff)
downloadpugl-677e13dcbb5b64ce85093b9ea5c14025964e35b9.tar.gz
pugl-677e13dcbb5b64ce85093b9ea5c14025964e35b9.tar.bz2
pugl-677e13dcbb5b64ce85093b9ea5c14025964e35b9.zip
Support closing views by sending a close event
Diffstat (limited to 'src/x11.c')
-rw-r--r--src/x11.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/x11.c b/src/x11.c
index a6daf72..30a15be 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -161,6 +161,7 @@ puglInitWorldInternals(const PuglWorldType type, const PuglWorldFlags flags)
impl->atoms.WM_PROTOCOLS = XInternAtom(display, "WM_PROTOCOLS", 0);
impl->atoms.WM_DELETE_WINDOW = XInternAtom(display, "WM_DELETE_WINDOW", 0);
impl->atoms.PUGL_CLIENT_MSG = XInternAtom(display, "_PUGL_CLIENT_MSG", 0);
+ impl->atoms.NET_CLOSE_WINDOW = XInternAtom(display, "_NET_CLOSE_WINDOW", 0);
impl->atoms.NET_WM_NAME = XInternAtom(display, "_NET_WM_NAME", 0);
impl->atoms.NET_WM_STATE = XInternAtom(display, "_NET_WM_STATE", 0);
impl->atoms.NET_WM_STATE_DEMANDS_ATTENTION =
@@ -1162,15 +1163,36 @@ eventToX(PuglView* const view, const PuglEvent* const event)
PuglStatus
puglSendEvent(PuglView* const view, const PuglEvent* const event)
{
- XEvent xev = eventToX(view, event);
+ PuglInternals* const impl = view->impl;
+ Display* const display = view->world->impl->display;
+ XEvent xev = PUGL_INIT_STRUCT;
- if (xev.type) {
- return XSendEvent(
- view->world->impl->display, view->impl->win, False, 0, &xev)
+ if (event->type == PUGL_CLOSE) {
+ xev.xclient.type = ClientMessage;
+ xev.xclient.serial = 0;
+ xev.xclient.send_event = True;
+ xev.xclient.display = display;
+ xev.xclient.window = impl->win;
+ xev.xclient.message_type = view->world->impl->atoms.NET_CLOSE_WINDOW;
+ xev.xclient.format = 32;
+ xev.xclient.data.l[0] = CurrentTime;
+ xev.xclient.data.l[1] = 1;
+
+ return XSendEvent(display,
+ RootWindow(display, impl->screen),
+ False,
+ SubstructureNotifyMask | SubstructureRedirectMask,
+ &xev)
? PUGL_SUCCESS
: PUGL_UNKNOWN_ERROR;
}
+ xev = eventToX(view, event);
+ if (xev.type) {
+ return XSendEvent(display, impl->win, False, 0, &xev) ? PUGL_SUCCESS
+ : PUGL_UNKNOWN_ERROR;
+ }
+
return PUGL_UNSUPPORTED;
}