From b60252e330afe1332fa1607eea099e09736a9714 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 10 Jan 2020 16:59:48 -0500 Subject: [PATCH] emul/hw/(ti|sms): detect window being closed Previously, it would never get out of the event loop. --- emul/hw/sms/sms.c | 10 ++++++++++ emul/hw/ti/ti84.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/emul/hw/sms/sms.c b/emul/hw/sms/sms.c index 99cb393..25c414a 100644 --- a/emul/hw/sms/sms.c +++ b/emul/hw/sms/sms.c @@ -99,6 +99,7 @@ void draw_pixels() int innerh = psize * VDP_SCREENH; int innerx = (geom->width - innerw) / 2; int innery = (geom->height - innerh) / 2; + free(geom); int drawcnt = 0; for (int i=0; iwidth - innerw) / 2; int innery = (geom->height - innerh) / 2; + free(geom); int drawcnt = 0; for (int i=0; i<96; i++) { for (int j=0; j<64; j++) { @@ -231,6 +232,15 @@ void event_loop() emul_steps(100); 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); if (!e) { continue;