Fixed #331 with graceful x11 window closing
This commit is contained in:
parent
2e9c4ee0ab
commit
6b27c20231
@ -41,6 +41,7 @@ struct XWindow {
|
||||
XFont *font;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
Atom wm_delete_window;
|
||||
};
|
||||
|
||||
static void
|
||||
@ -128,6 +129,9 @@ main(void)
|
||||
xw.vis, CWEventMask | CWColormap, &xw.swa);
|
||||
XStoreName(xw.dpy, xw.win, "X11");
|
||||
XMapWindow(xw.dpy, xw.win);
|
||||
xw.wm_delete_window = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(xw.dpy, xw.win, &xw.wm_delete_window, 1);
|
||||
|
||||
XGetWindowAttributes(xw.dpy, xw.win, &xw.attr);
|
||||
xw.width = (unsigned int)xw.attr.width;
|
||||
xw.height = (unsigned int)xw.attr.height;
|
||||
@ -141,14 +145,15 @@ main(void)
|
||||
/*set_style(ctx, THEME_RED);*/
|
||||
/*set_style(ctx, THEME_BLUE);*/
|
||||
/*set_style(ctx, THEME_DARK);*/
|
||||
|
||||
while (running)
|
||||
{
|
||||
/* Input */
|
||||
XEvent evt;
|
||||
started = timestamp();
|
||||
nk_input_begin(ctx);
|
||||
while (XCheckWindowEvent(xw.dpy, xw.win, xw.swa.event_mask, &evt)){
|
||||
while (XPending(xw.dpy)) {
|
||||
XNextEvent(xw.dpy, &evt);
|
||||
if (evt.type == ClientMessage) goto cleanup;
|
||||
if (XFilterEvent(&evt, xw.win)) continue;
|
||||
nk_xlib_handle_event(xw.dpy, xw.screen, xw.win, &evt);
|
||||
}
|
||||
@ -157,8 +162,7 @@ main(void)
|
||||
/* GUI */
|
||||
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
|
||||
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
|
||||
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE|
|
||||
NK_WINDOW_SCALE_LEFT))
|
||||
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
|
||||
{
|
||||
enum {EASY, HARD};
|
||||
static int op = EASY;
|
||||
@ -193,6 +197,7 @@ main(void)
|
||||
sleep_for(DTIME - dt);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
nk_xfont_del(xw.dpy, xw.font);
|
||||
nk_xlib_shutdown();
|
||||
XUnmapWindow(xw.dpy, xw.win);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* nuklear - 1.32.0 - public domain */
|
||||
/* nuklear - v1.32.0 - public domain */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
@ -62,6 +62,7 @@ struct XWindow {
|
||||
XSetWindowAttributes swa;
|
||||
XWindowAttributes attr;
|
||||
GLXFBConfig fbc;
|
||||
Atom wm_delete_window;
|
||||
int width, height;
|
||||
};
|
||||
static int gl_err = FALSE;
|
||||
@ -177,6 +178,8 @@ int main(int argc, char **argv)
|
||||
XFree(win.vis);
|
||||
XStoreName(win.dpy, win.win, "Demo");
|
||||
XMapWindow(win.dpy, win.win);
|
||||
win.wm_delete_window = XInternAtom(win.dpy, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(win.dpy, win.win, &win.wm_delete_window, 1);
|
||||
}
|
||||
{
|
||||
/* create opengl context */
|
||||
@ -245,7 +248,9 @@ int main(int argc, char **argv)
|
||||
/* Input */
|
||||
XEvent evt;
|
||||
nk_input_begin(ctx);
|
||||
while (XCheckWindowEvent(win.dpy, win.win, win.swa.event_mask, &evt)){
|
||||
while (XPending(win.dpy)) {
|
||||
XNextEvent(win.dpy, &evt);
|
||||
if (evt.type == ClientMessage) goto cleanup;
|
||||
if (XFilterEvent(&evt, win.win)) continue;
|
||||
nk_x11_handle_event(&evt);
|
||||
}
|
||||
@ -308,6 +313,7 @@ int main(int argc, char **argv)
|
||||
glXSwapBuffers(win.dpy, win.win);}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
nk_x11_shutdown();
|
||||
glXMakeCurrent(win.dpy, 0, 0);
|
||||
glXDestroyContext(win.dpy, glContext);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* nuklear - v1.17 - public domain */
|
||||
/* nuklear - v1.32.0 - public domain */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
@ -60,6 +60,7 @@ struct XWindow {
|
||||
XSetWindowAttributes swa;
|
||||
XWindowAttributes attr;
|
||||
GLXFBConfig fbc;
|
||||
Atom wm_delete_window;
|
||||
int width, height;
|
||||
};
|
||||
static int gl_err = FALSE;
|
||||
@ -175,6 +176,8 @@ int main(int argc, char **argv)
|
||||
XFree(win.vis);
|
||||
XStoreName(win.dpy, win.win, "Demo");
|
||||
XMapWindow(win.dpy, win.win);
|
||||
win.wm_delete_window = XInternAtom(win.dpy, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(win.dpy, win.win, &win.wm_delete_window, 1);
|
||||
}
|
||||
{
|
||||
/* create opengl context */
|
||||
@ -242,7 +245,9 @@ int main(int argc, char **argv)
|
||||
/* Input */
|
||||
XEvent evt;
|
||||
nk_input_begin(ctx);
|
||||
while (XCheckWindowEvent(win.dpy, win.win, win.swa.event_mask, &evt)){
|
||||
while (XPending(win.dpy)) {
|
||||
XNextEvent(win.dpy, &evt);
|
||||
if (evt.type == ClientMessage) goto cleanup;
|
||||
if (XFilterEvent(&evt, win.win)) continue;
|
||||
nk_x11_handle_event(&evt);
|
||||
}
|
||||
@ -305,6 +310,7 @@ int main(int argc, char **argv)
|
||||
glXSwapBuffers(win.dpy, win.win);}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
nk_x11_shutdown();
|
||||
glXMakeCurrent(win.dpy, 0, 0);
|
||||
glXDestroyContext(win.dpy, glContext);
|
||||
|
Loading…
Reference in New Issue
Block a user