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).

This commit is contained in:
Matthew Budd 2020-08-10 21:04:42 -04:00
parent cd99eaecd3
commit 1c6851c3f0
2 changed files with 30 additions and 19 deletions

View File

@ -438,6 +438,10 @@ int fceuWrapperInit( int argc, char *argv[] )
printf("Could not initialize SDL: %s.\n", SDL_GetError()); printf("Could not initialize SDL: %s.\n", SDL_GetError());
exit(-1); 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 // Initialize the configuration system
g_config = InitConfig(); g_config = InitConfig();

View File

@ -355,6 +355,7 @@ FCEUD_Update(uint8 *XBuf,
int32 *Buffer, int32 *Buffer,
int Count) int Count)
{ {
int blitDone = 0;
extern int FCEUDnetplay; extern int FCEUDnetplay;
#ifdef CREATE_AVI #ifdef CREATE_AVI
@ -381,8 +382,8 @@ FCEUD_Update(uint8 *XBuf,
if (!mutecapture) if (!mutecapture)
if(Count > 0 && Buffer) WriteSound(Buffer,Count); if(Count > 0 && Buffer) WriteSound(Buffer,Count);
} }
if(inited & 2) // if(inited & 2)
FCEUD_UpdateInput(); // FCEUD_UpdateInput();
if(XBuf && (inited & 4)) BlitScreen(XBuf); if(XBuf && (inited & 4)) BlitScreen(XBuf);
//SpeedThrottle(); //SpeedThrottle();
@ -414,7 +415,9 @@ FCEUD_Update(uint8 *XBuf,
// don't underflow when scaling fps // don't underflow when scaling fps
if(g_fpsScale>1.0 || ((tmpcan < Count*0.90) && !uflow)) { if(g_fpsScale>1.0 || ((tmpcan < Count*0.90) && !uflow)) {
if(XBuf && (inited&4) && !(NoWaiting & 2)) if(XBuf && (inited&4) && !(NoWaiting & 2))
BlitScreen(XBuf); {
BlitScreen(XBuf); blitDone = 1;
}
Buffer+=can; Buffer+=can;
Count-=can; Count-=can;
if(Count) { if(Count) {
@ -449,24 +452,23 @@ FCEUD_Update(uint8 *XBuf,
} }
} else { } else {
if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused())) //if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused()))
while (SpeedThrottle()) //while (SpeedThrottle())
//{
// FCEUD_UpdateInput();
//}
if (XBuf && (inited&4))
{ {
FCEUD_UpdateInput(); BlitScreen(XBuf); blitDone = 1;
} }
if(XBuf && (inited&4)) { }
BlitScreen(XBuf); 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(); //FCEUD_UpdateInput();
} }
@ -564,6 +566,10 @@ int main(int argc, char *argv[])
printf("Could not initialize SDL: %s.\n", SDL_GetError()); printf("Could not initialize SDL: %s.\n", SDL_GetError());
return(-1); 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 //#ifdef OPENGL
// SDL_GL_LoadLibrary(0); // SDL_GL_LoadLibrary(0);
@ -914,8 +920,9 @@ int main(int argc, char *argv[])
} }
else else
{ {
SDL_Delay(1); SDL_Delay(10);
} }
FCEUD_UpdateInput();
while(gtk_events_pending()) while(gtk_events_pending())
{ {