Joystick events send a bogus XWarpPointer event to prevent screensaver / dpms launch

This commit is contained in:
Greg Kennedy 2019-09-12 21:45:38 -05:00
parent 2971fbb39b
commit 6c8f0c004f
No known key found for this signature in database
GPG Key ID: 45B25739949112C6
2 changed files with 31 additions and 4 deletions

View File

@ -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);

View File

@ -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;