diff options
author | David Robillard <d@drobilla.net> | 2019-07-21 18:38:43 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-07-21 21:31:00 +0200 |
commit | 081490898ed788a184eb74074130634ce9067174 (patch) | |
tree | fe0777f98f036a7f706dd4d80049f603bf6338bd /pugl | |
parent | a322ffa38b537e5e03c31ed7fe967cec9d468bb8 (diff) | |
download | pugl-081490898ed788a184eb74074130634ce9067174.tar.gz pugl-081490898ed788a184eb74074130634ce9067174.tar.bz2 pugl-081490898ed788a184eb74074130634ce9067174.zip |
Fix handling of WM_DELETE_WINDOW
Diffstat (limited to 'pugl')
-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; }; |