From 1c6851c3f0fd22da102bd411fd6ded048c5fca9f Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 10 Aug 2020 21:04:42 -0400 Subject: [PATCH] Bug fix for SDL joystick not working using SDL video driver. By default SDL joystick inputs are ignored if the SDL window does not have focus. Set SDL HINT to allow for background joystick inputs to accepted (i.e. joystick inputs come through even though window not in focus). --- src/drivers/Qt/fceuWrapper.cpp | 4 +++ src/drivers/sdl/sdl.cpp | 45 ++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index 5e2ea31d..886e08d4 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -438,6 +438,10 @@ int fceuWrapperInit( int argc, char *argv[] ) printf("Could not initialize SDL: %s.\n", SDL_GetError()); exit(-1); } + if ( SDL_SetHint( SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1" ) == SDL_FALSE ) + { + printf("Error setting SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS\n"); + } // Initialize the configuration system g_config = InitConfig(); diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index 21dfba68..59d2e6c1 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -355,6 +355,7 @@ FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) { + int blitDone = 0; extern int FCEUDnetplay; #ifdef CREATE_AVI @@ -381,8 +382,8 @@ FCEUD_Update(uint8 *XBuf, if (!mutecapture) if(Count > 0 && Buffer) WriteSound(Buffer,Count); } - if(inited & 2) - FCEUD_UpdateInput(); + // if(inited & 2) + // FCEUD_UpdateInput(); if(XBuf && (inited & 4)) BlitScreen(XBuf); //SpeedThrottle(); @@ -414,7 +415,9 @@ FCEUD_Update(uint8 *XBuf, // don't underflow when scaling fps if(g_fpsScale>1.0 || ((tmpcan < Count*0.90) && !uflow)) { if(XBuf && (inited&4) && !(NoWaiting & 2)) - BlitScreen(XBuf); + { + BlitScreen(XBuf); blitDone = 1; + } Buffer+=can; Count-=can; if(Count) { @@ -449,24 +452,23 @@ FCEUD_Update(uint8 *XBuf, } } else { - if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused())) - while (SpeedThrottle()) + //if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused())) + //while (SpeedThrottle()) + //{ + // FCEUD_UpdateInput(); + //} + if (XBuf && (inited&4)) { - FCEUD_UpdateInput(); - } - if(XBuf && (inited&4)) { - BlitScreen(XBuf); + BlitScreen(XBuf); blitDone = 1; + } + } + if ( !blitDone ) + { + if (XBuf && (inited&4)) + { + BlitScreen(XBuf); blitDone = 1; } } - FCEUD_UpdateInput(); - //if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE)) - // SpeedThrottle(); - //if(XBuf && (inited&4)) - //{ - // BlitScreen(XBuf); - //} - //if(Count) - // WriteSound(Buffer,Count,NoWaiting); //FCEUD_UpdateInput(); } @@ -564,6 +566,10 @@ int main(int argc, char *argv[]) printf("Could not initialize SDL: %s.\n", SDL_GetError()); return(-1); } + if ( SDL_SetHint( SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1" ) == SDL_FALSE ) + { + printf("Error setting SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS\n"); + } //#ifdef OPENGL // SDL_GL_LoadLibrary(0); @@ -914,8 +920,9 @@ int main(int argc, char *argv[]) } else { - SDL_Delay(1); + SDL_Delay(10); } + FCEUD_UpdateInput(); while(gtk_events_pending()) {