Merge pull request #64 from aduros/2021-11-13-patch

Handle the X11 WM_DELETE_WINDOW protocol for closing windows.
This commit is contained in:
Carlos Aragonés 2021-11-15 10:07:26 +01:00 committed by GitHub
commit 23b1a10f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,8 @@
#include <gl/MiniFB_GL.h> #include <gl/MiniFB_GL.h>
#endif #endif
static Atom s_delete_window_atom;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void init_keycodes(SWindowData_X11 *window_data_x11); void init_keycodes(SWindowData_X11 *window_data_x11);
@ -185,6 +187,9 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
sizeHints.max_height = height; sizeHints.max_height = height;
} }
s_delete_window_atom = XInternAtom(window_data_x11->display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(window_data_x11->display, window_data_x11->window, &s_delete_window_atom, 1);
#if defined(USE_OPENGL_API) #if defined(USE_OPENGL_API)
if(create_GL_context(window_data) == false) { if(create_GL_context(window_data) == false) {
return 0x0; return 0x0;
@ -315,6 +320,15 @@ processEvent(SWindowData *window_data, XEvent *event) {
window_data->close = true; window_data->close = true;
return; return;
break; break;
case ClientMessage:
{
if ((Atom)event->xclient.data.l[0] == s_delete_window_atom) {
window_data->close = true;
return;
}
}
break;
} }
} }