From 4eb6cf6f9ebd1633c57edfc2f6f0667fa7a83912 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 10 Jul 2019 22:24:11 +0900 Subject: [PATCH] Make SetMouse timeout after 2 seconds This makes sure that some unchecked event doesn't cause a lockup. However, blocking input is really not the way to go: need to implement a state machine and use non-blocking event reads. --- libs/video/targets/context_x11.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/video/targets/context_x11.c b/libs/video/targets/context_x11.c index 5a6556ce0..614f83ebd 100644 --- a/libs/video/targets/context_x11.c +++ b/libs/video/targets/context_x11.c @@ -354,7 +354,14 @@ X11_SetMouse (void) XWarpPointer (x_disp, None, x_win, 0, 0, 0, 0, 0, 0); XWarpPointer (x_disp, None, x_win, 0, 0, 0, 0, viddef.width / 2, viddef.height / 2); - XPeekIfEvent (x_disp, &ev, check_mouse_event, 0); + //FIXME this should be done in a state machine that handles events without + //blocking + double start = Sys_DoubleTime (); + while (!XCheckIfEvent (x_disp, &ev, check_mouse_event, 0)) { + if (Sys_DoubleTime () - start > 2) { + break; + } + } x_mouse_time = ev.xmotion.time; }