diff options
-rw-r--r-- | pugl/pugl_x11.c | 19 | ||||
-rw-r--r-- | pugl/pugl_x11.h | 5 |
2 files changed, 16 insertions, 8 deletions
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); diff --git a/pugl/pugl_x11.h b/pugl/pugl_x11.h index 9c53c49..f33d8de 100644 --- a/pugl/pugl_x11.h +++ b/pugl/pugl_x11.h @@ -29,4 +29,9 @@ struct PuglInternalsImpl { XIC xic; PuglDrawContext ctx; PuglSurface* surface; + + struct { + Atom WM_PROTOCOLS; + Atom WM_DELETE_WINDOW; + } atoms; }; |