mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2025-12-31 06:30:52 +00:00
quit properly
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@60 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -31,6 +31,7 @@ struct _MwLLHandler {
|
||||
void (*up)(MwLL handle);
|
||||
void (*down)(MwLL handle);
|
||||
void (*resize)(MwLL handle);
|
||||
void (*close)(MwLL handle);
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -61,6 +61,7 @@ struct _MwWidget {
|
||||
MwClass widget_class;
|
||||
|
||||
int pressed;
|
||||
int close;
|
||||
|
||||
MwIntegerKeyValue* integer;
|
||||
MwTextKeyValue* text;
|
||||
|
||||
@@ -19,6 +19,7 @@ struct _MwLL {
|
||||
GC gc;
|
||||
Colormap colormap;
|
||||
void* user;
|
||||
Atom wm_delete;
|
||||
|
||||
MwLLHandler handler;
|
||||
};
|
||||
|
||||
10
src/core.c
10
src/core.c
@@ -26,6 +26,12 @@ static void llresizehandler(MwLL handle) {
|
||||
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 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->widget_class = widget_class;
|
||||
h->pressed = 0;
|
||||
h->close = 0;
|
||||
|
||||
h->lowlevel->user = h;
|
||||
h->lowlevel->handler->draw = lldrawhandler;
|
||||
h->lowlevel->handler->up = lluphandler;
|
||||
h->lowlevel->handler->down = lldownhandler;
|
||||
h->lowlevel->handler->resize = llresizehandler;
|
||||
h->lowlevel->handler->close = llclosehandler;
|
||||
|
||||
if(parent != NULL) arrput(parent->children, h);
|
||||
|
||||
@@ -133,7 +141,7 @@ int MwPending(MwWidget handle) {
|
||||
}
|
||||
|
||||
void MwLoop(MwWidget handle) {
|
||||
while(1) {
|
||||
while(!handle->close) {
|
||||
MwStep(handle);
|
||||
|
||||
MwDispatchUserHandler(handle, MwNtickHandler, NULL);
|
||||
|
||||
@@ -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_NCHITTEST) {
|
||||
return HTCLIENT;
|
||||
} else if(msg == WM_DESTROY) {
|
||||
MwLLDispatch(u->ll, close);
|
||||
PostQuitMessage(0);
|
||||
} else if(msg == WM_CLOSE) {
|
||||
DestroyWindow(hWnd);
|
||||
} else {
|
||||
return (u->old == NULL) ? DefWindowProc(hWnd, msg, wp, lp) : CallWindowProc(u->old, hWnd, msg, wp, lp);
|
||||
}
|
||||
|
||||
14
src/x11.c
14
src/x11.c
@@ -18,8 +18,10 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
|
||||
r->display = parent->display;
|
||||
p = parent->window;
|
||||
}
|
||||
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->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->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);
|
||||
|
||||
@@ -96,7 +98,7 @@ void MwLLFreeColor(MwLLColor color) {
|
||||
|
||||
int MwLLPending(MwLL handle) {
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
@@ -105,7 +107,7 @@ int MwLLPending(MwLL handle) {
|
||||
|
||||
void MwLLNextEvent(MwLL handle) {
|
||||
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) {
|
||||
MwLLDispatch(handle, draw);
|
||||
} else if(ev.type == ButtonPress) {
|
||||
@@ -120,6 +122,10 @@ void MwLLNextEvent(MwLL handle) {
|
||||
}
|
||||
} else if(ev.type == ConfigureNotify) {
|
||||
MwLLDispatch(handle, resize);
|
||||
} else if(ev.type == ClientMessage) {
|
||||
if(ev.xclient.data.l[0] == (long)handle->wm_delete) {
|
||||
MwLLDispatch(handle, close);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user