diff options
-rw-r--r-- | src/mac.m | 5 | ||||
-rw-r--r-- | src/win.c | 5 | ||||
-rw-r--r-- | src/x11.c | 30 | ||||
-rw-r--r-- | src/x11.h | 1 |
4 files changed, 37 insertions, 4 deletions
@@ -1347,6 +1347,11 @@ puglSendEvent(PuglView* view, const PuglEvent* event) return PUGL_SUCCESS; } + if (event->type == PUGL_CLOSE) { + [view->impl->window close]; + return PUGL_SUCCESS; + } + return PUGL_UNSUPPORTED; } @@ -887,6 +887,11 @@ puglStopTimer(PuglView* view, uintptr_t id) PuglStatus puglSendEvent(PuglView* view, const PuglEvent* event) { + if (event->type == PUGL_CLOSE) { + PostMessage(view->impl->hwnd, WM_CLOSE, 0, 0); + return PUGL_SUCCESS; + } + if (event->type == PUGL_CLIENT) { PostMessage(view->impl->hwnd, PUGL_LOCAL_CLIENT_MSG, @@ -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; } @@ -24,6 +24,7 @@ typedef struct { Atom WM_PROTOCOLS; Atom WM_DELETE_WINDOW; Atom PUGL_CLIENT_MSG; + Atom NET_CLOSE_WINDOW; Atom NET_WM_NAME; Atom NET_WM_STATE; Atom NET_WM_STATE_DEMANDS_ATTENTION; |