git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@393 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-17 03:47:54 +00:00
parent ec86f5297e
commit 5862e59b63
5 changed files with 29 additions and 15 deletions

View File

@@ -58,7 +58,9 @@ int main() {
reshape(400, 400);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
MwAddUserHandler(window, MwNtickHandler, tick, NULL);
MwAddUserHandler(opengl, MwNtickHandler, tick, NULL);
MwAddTickList(opengl);
MwAddUserHandler(opengl, MwNkeyHandler, key_pressed, NULL);

View File

@@ -16,7 +16,7 @@
* %param y Handler name
*/
#define MwDispatch(x, y) \
if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x)
if(!x->destroyed && x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x)
/*!
* %warning Used internally
@@ -26,7 +26,7 @@
* %return `0` for success, otherwise failed
*/
#define MwDispatch2(x, y) \
((x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x) : 0)
((!x->destroyed && x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x) : 0)
/*!
* %warning Used internally
@@ -36,7 +36,7 @@
* %param z Argument
*/
#define MwDispatch3(x, y, z) \
if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x, z)
if(!x->destroyed && x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x, z)
#define MwWaitMS 10

View File

@@ -106,6 +106,8 @@ struct _MwWidget {
MwWidget* destroy_queue;
MwWidget* tick_list;
int destroyed;
};
#endif

View File

@@ -132,14 +132,15 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
void MwLLDestroy(MwLL handle) {
MwLLDestroyCommon(handle);
XDestroyIC(handle->xic);
XCloseIM(handle->xim);
if(handle->xic) XDestroyIC(handle->xic);
if(handle->xim) XCloseIM(handle->xim);
destroy_pixmap(handle);
XFree(handle->visual);
XFreeGC(handle->display, handle->gc);
XUnmapWindow(handle->display, handle->window);
XDestroyWindow(handle->display, handle->window);
XFlush(handle->display);
free(handle);
}

View File

@@ -113,6 +113,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
h->prop_event = 1;
h->draw_inject = NULL;
h->tick_list = NULL;
h->destroyed = 0;
if(parent == NULL) arrput(h->tick_list, h);
@@ -211,17 +212,11 @@ void MwDestroyWidget(MwWidget handle) {
if(handle->parent != NULL) {
arrput(handle->parent->destroy_queue, handle);
}
handle->destroyed = 1;
}
void MwStep(MwWidget handle) {
static void clean_destroy_queue(MwWidget handle) {
int i, j;
if(setjmp(handle->before_step)) return;
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
handle->prop_event = 0;
if(handle->lowlevel != NULL) MwLLNextEvent(handle->lowlevel);
handle->prop_event = 1;
for(i = 0; i < arrlen(handle->destroy_queue); i++) {
MwWidget w = handle->destroy_queue[i];
@@ -238,12 +233,24 @@ void MwStep(MwWidget handle) {
arrfree(handle->destroy_queue);
}
void MwStep(MwWidget handle) {
int i;
if(setjmp(handle->before_step)) return;
for(i = 0; i < arrlen(handle->children); i++) MwStep(handle->children[i]);
handle->prop_event = 0;
if(handle->lowlevel != NULL && MwLLPending(handle->lowlevel)) MwLLNextEvent(handle->lowlevel);
handle->prop_event = 1;
clean_destroy_queue(handle);
}
int MwPending(MwWidget handle) {
int i;
for(i = 0; i < arrlen(handle->children); i++) {
if(MwPending(handle->children[i])) return 1;
}
return MwLLPending(handle->lowlevel);
return (arrlen(handle->destroy_queue) > 0 ? 1 : 0) || MwLLPending(handle->lowlevel);
}
void MwLoop(MwWidget handle) {
@@ -255,6 +262,7 @@ void MwLoop(MwWidget handle) {
for(i = 0; i < arrlen(handle->tick_list); i++) {
MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL);
}
tick = MwWaitMS - (MwLLGetTick() - tick);
if(tick > 0) MwLLSleep(tick);
tick = MwLLGetTick();
@@ -394,6 +402,7 @@ void MwSetDefault(MwWidget handle) {
void MwDispatchUserHandler(MwWidget handle, const char* key, void* handler_data) {
int ind = shgeti(handle->handler, key);
if(ind == -1) return;
if(handle->destroyed) return;
handle->handler[ind].value(handle, handle->handler[ind].user_data, handler_data);
}