From 6c8f0c004f2959bcd92b2850e13737bbf9f72e50 Mon Sep 17 00:00:00 2001 From: Greg Kennedy Date: Thu, 12 Sep 2019 21:45:38 -0500 Subject: [PATCH] Joystick events send a bogus XWarpPointer event to prevent screensaver / dpms launch --- unix/unix.cpp | 19 ++++++++++++++++--- unix/x11.cpp | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/unix/unix.cpp b/unix/unix.cpp index cef2ba94..82118950 100644 --- a/unix/unix.cpp +++ b/unix/unix.cpp @@ -166,7 +166,8 @@ static void * S9xProcessSound (void *); #endif #ifdef JOYSTICK_SUPPORT static void InitJoysticks (void); -static void ReadJoysticks (void); +static bool8 ReadJoysticks (void); +void S9xLatchJSEvent(); #endif @@ -1205,8 +1206,10 @@ static void InitJoysticks (void) #endif } -static void ReadJoysticks (void) +static bool8 ReadJoysticks (void) { + // track if ANY joystick event happened this frame + int js_latch = FALSE; #ifdef JSIOCGVERSION struct js_event js_ev; @@ -1220,6 +1223,7 @@ static void ReadJoysticks (void) { fprintf(stderr,"Joystick %d reconnected.\n",i); js_unplugged[i] = FALSE; + js_latch = TRUE; } } @@ -1233,12 +1237,14 @@ static void ReadJoysticks (void) case JS_EVENT_AXIS: S9xReportAxis(0x8000c000 | (i << 24) | js_ev.number, js_ev.value); S9xReportAxis(0x80008000 | (i << 24) | (js_mod[i] << 16) | js_ev.number, js_ev.value); + js_latch = TRUE; break; case JS_EVENT_BUTTON: case JS_EVENT_BUTTON | JS_EVENT_INIT: S9xReportButton(0x80004000 | (i << 24) | js_ev.number, js_ev.value); S9xReportButton(0x80000000 | (i << 24) | (js_mod[i] << 16) | js_ev.number, js_ev.value); + js_latch = TRUE; break; } } @@ -1260,9 +1266,12 @@ static void ReadJoysticks (void) S9xReportButton(0x80004000 | (i << 24) | j, 0); S9xReportButton(0x80000000 | (i << 24) | (js_mod[i] << 16) | j, 0); } + + js_latch = TRUE; } } #endif + return js_latch; } #endif @@ -1766,7 +1775,11 @@ int main (int argc, char **argv) #ifdef JOYSTICK_SUPPORT if (unixSettings.JoystickEnabled && (JoypadSkip++ & 1) == 0) - ReadJoysticks(); + { + if (ReadJoysticks() == TRUE) { + S9xLatchJSEvent(); + } + } #endif S9xProcessEvents(FALSE); diff --git a/unix/x11.cpp b/unix/x11.cpp index c732a739..38f3e6bd 100644 --- a/unix/x11.cpp +++ b/unix/x11.cpp @@ -100,6 +100,7 @@ struct GUIData bool8 mod1_pressed; bool8 no_repeat; bool8 fullscreen; + bool8 js_event_latch; int x_offset; int y_offset; #ifdef USE_XVIDEO @@ -1452,7 +1453,7 @@ static void Repaint (bool8 isFrameBoundry) if (GUI.use_shared_memory) { XShmPutImage(GUI.display, GUI.window, GUI.gc, GUI.image->ximage, 0, 0, GUI.x_offset, GUI.y_offset, SNES_WIDTH * 2, SNES_HEIGHT_EXTENDED * 2, False); - XSync(GUI.display, False); + XSync(GUI.display, False); // Is this double-sync? See XQueryPointer below... } else #endif @@ -1511,8 +1512,21 @@ static bool8 CheckForPendingXEvents (Display *display) #endif } +void S9xLatchJSEvent () +{ + // record that a JS event happened and was reported to the engine + GUI.js_event_latch = TRUE; +} + void S9xProcessEvents (bool8 block) { + // Kick the screensaver if a joystick event occurred + if (GUI.js_event_latch == TRUE) { + XWarpPointer(GUI.display, None, None, 0, 0, 0, 0, 0, 0); + GUI.js_event_latch = FALSE; + } + + // Process all other X events while (block || CheckForPendingXEvents(GUI.display)) { XEvent event;