From 081490898ed788a184eb74074130634ce9067174 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 21 Jul 2019 18:38:43 +0200 Subject: Fix handling of WM_DELETE_WINDOW --- pugl/pugl_x11.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'pugl/pugl_x11.c') diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index 9fadc41..8bfcf17 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -77,6 +77,10 @@ puglCreateWindow(PuglView* view, const char* title) impl->display = display; impl->screen = DefaultScreen(display); + // Intern the various atoms we will need + impl->atoms.WM_PROTOCOLS = XInternAtom(display, "WM_PROTOCOLS", 0); + impl->atoms.WM_DELETE_WINDOW = XInternAtom(display, "WM_DELETE_WINDOW", 0); + if (view->ctx_type == PUGL_GL) { #ifdef PUGL_HAVE_GL impl->ctx = puglGetX11GlDrawContext(); @@ -153,8 +157,7 @@ puglCreateWindow(PuglView* view, const char* title) } if (!view->parent) { - Atom wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True); - XSetWMProtocols(display, win, &wmDelete, 1); + XSetWMProtocols(display, win, &view->impl->atoms.WM_DELETE_WINDOW, 1); } if (view->transient_parent) { @@ -301,14 +304,14 @@ translateEvent(PuglView* view, XEvent xevent) } switch (xevent.type) { - case ClientMessage: { - char* type = XGetAtomName(view->impl->display, - xevent.xclient.message_type); - if (!strcmp(type, "WM_PROTOCOLS")) { - event.type = PUGL_CLOSE; + case ClientMessage: + if (xevent.xclient.message_type == view->impl->atoms.WM_PROTOCOLS) { + const Atom protocol = xevent.xclient.data.l[0]; + if (protocol == view->impl->atoms.WM_DELETE_WINDOW) { + event.type = PUGL_CLOSE; + } } break; - } case MapNotify: { XWindowAttributes attrs = {0}; XGetWindowAttributes(view->impl->display, view->impl->win, &attrs); -- cgit v1.2.1