sync and not

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@740 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
Nishi 2025-11-16 08:02:31 +00:00
commit e3ca305245

View file

@ -70,9 +70,7 @@ static void sync_move(MwLL handle, int x, int y) {
MwLLSetXY(handle, x, y); MwLLSetXY(handle, x, y);
} }
static void wait_map(MwLL handle) { static void wait_map(MwLL handle, int sync) {
XEvent* queue = NULL;
XEvent ev;
XWindowAttributes xwa; XWindowAttributes xwa;
XGetWindowAttributes(handle->x11.display, handle->x11.window, &xwa); XGetWindowAttributes(handle->x11.display, handle->x11.window, &xwa);
@ -81,22 +79,28 @@ static void wait_map(MwLL handle) {
XMapWindow(handle->x11.display, handle->x11.window); XMapWindow(handle->x11.display, handle->x11.window);
if(!sync) return;
do {
XSync(handle->x11.display, False);
XGetWindowAttributes(handle->x11.display, handle->x11.window, &xwa);
} while(xwa.map_state != IsViewable);
}
}
static void wait_unmap(MwLL handle, int sync) {
XWindowAttributes xwa;
XGetWindowAttributes(handle->x11.display, handle->x11.window, &xwa);
if(xwa.map_state == IsViewable) {
XSync(handle->x11.display, False); XSync(handle->x11.display, False);
while(1) { XUnmapWindow(handle->x11.display, handle->x11.window);
XNextEvent(handle->x11.display, &ev);
if(ev.type == MapNotify && ev.xmap.window == handle->x11.window) {
break;
} else {
arrput(queue, ev);
}
}
while(arrlen(queue) > 0) { if(!sync) return;
XPutBackEvent(handle->x11.display, &queue[0]); do {
arrdel(queue, 0); XSync(handle->x11.display, False);
} XGetWindowAttributes(handle->x11.display, handle->x11.window, &xwa);
arrfree(queue); } while(xwa.map_state == IsViewable);
} }
} }
@ -211,13 +215,11 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
XSelectInput(r->x11.display, r->x11.window, mask); XSelectInput(r->x11.display, r->x11.window, mask);
wait_map(r); wait_map(r, 0);
if(x != MwDEFAULT || y != MwDEFAULT) { if(x != MwDEFAULT || y != MwDEFAULT) {
unsigned int dummy; unsigned int dummy;
XUnmapWindow(r->x11.display, r->x11.window);
MwLLGetXYWH(r, &px, &py, &dummy, &dummy); MwLLGetXYWH(r, &px, &py, &dummy, &dummy);
if(x == MwDEFAULT) x = px; if(x == MwDEFAULT) x = px;
@ -228,8 +230,6 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
} else { } else {
MwLLSetXY(r, x, y); MwLLSetXY(r, x, y);
} }
wait_map(r);
} }
return r; return r;
@ -852,11 +852,11 @@ static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
static void MwLLShowImpl(MwLL handle, int show) { static void MwLLShowImpl(MwLL handle, int show) {
if(show) { if(show) {
wait_map(handle); wait_map(handle, 1);
XSetInputFocus(handle->x11.display, handle->x11.window, RevertToNone, CurrentTime); XSetInputFocus(handle->x11.display, handle->x11.window, RevertToNone, CurrentTime);
} else { } else {
XUnmapWindow(handle->x11.display, handle->x11.window); wait_unmap(handle, 1);
} }
} }