quit properly

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@60 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
Nishi 2025-09-29 07:05:09 +00:00
commit 40aabee23a
6 changed files with 27 additions and 5 deletions

View file

@ -31,6 +31,7 @@ struct _MwLLHandler {
void (*up)(MwLL handle); void (*up)(MwLL handle);
void (*down)(MwLL handle); void (*down)(MwLL handle);
void (*resize)(MwLL handle); void (*resize)(MwLL handle);
void (*close)(MwLL handle);
}; };
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -61,6 +61,7 @@ struct _MwWidget {
MwClass widget_class; MwClass widget_class;
int pressed; int pressed;
int close;
MwIntegerKeyValue* integer; MwIntegerKeyValue* integer;
MwTextKeyValue* text; MwTextKeyValue* text;

View file

@ -19,6 +19,7 @@ struct _MwLL {
GC gc; GC gc;
Colormap colormap; Colormap colormap;
void* user; void* user;
Atom wm_delete;
MwLLHandler handler; MwLLHandler handler;
}; };

View file

@ -26,6 +26,12 @@ static void llresizehandler(MwLL handle) {
MwDispatchUserHandler(h, MwNresizeHandler, NULL); MwDispatchUserHandler(h, MwNresizeHandler, NULL);
} }
static void llclosehandler(MwLL handle) {
MwWidget h = (MwWidget)handle->user;
h->close = 1;
}
MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) { MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) {
MwWidget h = malloc(sizeof(*h)); MwWidget h = malloc(sizeof(*h));
@ -37,12 +43,14 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->lowlevel = MwLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height); h->lowlevel = MwLLCreate(parent == NULL ? NULL : parent->lowlevel, x, y, width, height);
h->widget_class = widget_class; h->widget_class = widget_class;
h->pressed = 0; h->pressed = 0;
h->close = 0;
h->lowlevel->user = h; h->lowlevel->user = h;
h->lowlevel->handler->draw = lldrawhandler; h->lowlevel->handler->draw = lldrawhandler;
h->lowlevel->handler->up = lluphandler; h->lowlevel->handler->up = lluphandler;
h->lowlevel->handler->down = lldownhandler; h->lowlevel->handler->down = lldownhandler;
h->lowlevel->handler->resize = llresizehandler; h->lowlevel->handler->resize = llresizehandler;
h->lowlevel->handler->close = llclosehandler;
if(parent != NULL) arrput(parent->children, h); if(parent != NULL) arrput(parent->children, h);
@ -133,7 +141,7 @@ int MwPending(MwWidget handle) {
} }
void MwLoop(MwWidget handle) { void MwLoop(MwWidget handle) {
while(1) { while(!handle->close) {
MwStep(handle); MwStep(handle);
MwDispatchUserHandler(handle, MwNtickHandler, NULL); MwDispatchUserHandler(handle, MwNtickHandler, NULL);

View file

@ -47,6 +47,11 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
} else if(msg == WM_ERASEBKGND) { } else if(msg == WM_ERASEBKGND) {
} else if(msg == WM_NCHITTEST) { } else if(msg == WM_NCHITTEST) {
return HTCLIENT; return HTCLIENT;
} else if(msg == WM_DESTROY) {
MwLLDispatch(u->ll, close);
PostQuitMessage(0);
} else if(msg == WM_CLOSE) {
DestroyWindow(hWnd);
} else { } else {
return (u->old == NULL) ? DefWindowProc(hWnd, msg, wp, lp) : CallWindowProc(u->old, hWnd, msg, wp, lp); return (u->old == NULL) ? DefWindowProc(hWnd, msg, wp, lp) : CallWindowProc(u->old, hWnd, msg, wp, lp);
} }

View file

@ -18,8 +18,10 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
r->display = parent->display; r->display = parent->display;
p = parent->window; p = parent->window;
} }
r->window = XCreateSimpleWindow(r->display, p, x, y, width, height, 0, 0, WhitePixel(r->display, XDefaultScreen(r->display))); r->window = XCreateSimpleWindow(r->display, p, x, y, width, height, 0, 0, WhitePixel(r->display, XDefaultScreen(r->display)));
r->colormap = DefaultColormap(r->display, XDefaultScreen(r->display)); r->colormap = DefaultColormap(r->display, XDefaultScreen(r->display));
r->wm_delete = XInternAtom(r->display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(r->display, r->window, &r->wm_delete, 1);
r->gc = XCreateGC(r->display, r->window, 0, 0); r->gc = XCreateGC(r->display, r->window, 0, 0);
@ -96,7 +98,7 @@ void MwLLFreeColor(MwLLColor color) {
int MwLLPending(MwLL handle) { int MwLLPending(MwLL handle) {
XEvent ev; XEvent ev;
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) { if(XCheckTypedWindowEvent(handle->display, handle->window, ClientMessage, &ev) || XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
XPutBackEvent(handle->display, &ev); XPutBackEvent(handle->display, &ev);
return 1; return 1;
} }
@ -105,7 +107,7 @@ int MwLLPending(MwLL handle) {
void MwLLNextEvent(MwLL handle) { void MwLLNextEvent(MwLL handle) {
XEvent ev; XEvent ev;
while(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) { while(XCheckTypedWindowEvent(handle->display, handle->window, ClientMessage, &ev) || XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
if(ev.type == Expose) { if(ev.type == Expose) {
MwLLDispatch(handle, draw); MwLLDispatch(handle, draw);
} else if(ev.type == ButtonPress) { } else if(ev.type == ButtonPress) {
@ -120,6 +122,10 @@ void MwLLNextEvent(MwLL handle) {
} }
} else if(ev.type == ConfigureNotify) { } else if(ev.type == ConfigureNotify) {
MwLLDispatch(handle, resize); MwLLDispatch(handle, resize);
} else if(ev.type == ClientMessage) {
if(ev.xclient.data.l[0] == (long)handle->wm_delete) {
MwLLDispatch(handle, close);
}
} }
} }
} }