emul/hw/(ti|sms): detect window being closed

Previously, it would never get out of the event loop.
This commit is contained in:
Virgil Dupras 2020-01-10 16:59:48 -05:00
parent 9cddaf1b59
commit b60252e330
2 changed files with 20 additions and 0 deletions

View File

@ -99,6 +99,7 @@ void draw_pixels()
int innerh = psize * VDP_SCREENH; int innerh = psize * VDP_SCREENH;
int innerx = (geom->width - innerw) / 2; int innerx = (geom->width - innerw) / 2;
int innery = (geom->height - innerh) / 2; int innery = (geom->height - innerh) / 2;
free(geom);
int drawcnt = 0; int drawcnt = 0;
for (int i=0; i<VDP_SCREENW; i++) { for (int i=0; i<VDP_SCREENW; i++) {
for (int j=0; j<VDP_SCREENH; j++) { for (int j=0; j<VDP_SCREENH; j++) {
@ -131,6 +132,15 @@ void event_loop()
emul_steps(100); emul_steps(100);
draw_pixels(); draw_pixels();
} }
// A low tech way of checking when the window was closed. The proper way
// involving WM_DELETE is too complicated.
xcb_get_geometry_reply_t *geom;
geom = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, win), NULL);
if (geom == NULL) {
return; // window has been closed.
} else {
free(geom);
}
xcb_generic_event_t *e = xcb_poll_for_event(conn); xcb_generic_event_t *e = xcb_poll_for_event(conn);
if (!e) { if (!e) {
continue; continue;

View File

@ -199,6 +199,7 @@ void draw_pixels()
int innerh = psize * 64; int innerh = psize * 64;
int innerx = (geom->width - innerw) / 2; int innerx = (geom->width - innerw) / 2;
int innery = (geom->height - innerh) / 2; int innery = (geom->height - innerh) / 2;
free(geom);
int drawcnt = 0; int drawcnt = 0;
for (int i=0; i<96; i++) { for (int i=0; i<96; i++) {
for (int j=0; j<64; j++) { for (int j=0; j<64; j++) {
@ -231,6 +232,15 @@ void event_loop()
emul_steps(100); emul_steps(100);
draw_pixels(); draw_pixels();
} }
// A low tech way of checking when the window was closed. The proper way
// involving WM_DELETE is too complicated.
xcb_get_geometry_reply_t *geom;
geom = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, win), NULL);
if (geom == NULL) {
return; // window has been closed.
} else {
free(geom);
}
xcb_generic_event_t *e = xcb_poll_for_event(conn); xcb_generic_event_t *e = xcb_poll_for_event(conn);
if (!e) { if (!e) {
continue; continue;