Only check for keyboard focus if the video subsystem was initialized.
Check the hint at initialization time, as an optimization. This isn't something we expect the application to change at runtime, and if it is we should add an API for it.
This commit is contained in:
parent
66328f31b9
commit
563185f19c
1 changed files with 21 additions and 7 deletions
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
/* This is the joystick API for Simple DirectMedia Layer */
|
/* This is the joystick API for Simple DirectMedia Layer */
|
||||||
|
|
||||||
|
#include "SDL.h"
|
||||||
#include "SDL_events.h"
|
#include "SDL_events.h"
|
||||||
#include "SDL_sysjoystick.h"
|
#include "SDL_sysjoystick.h"
|
||||||
#include "SDL_assert.h"
|
#include "SDL_assert.h"
|
||||||
|
@ -31,14 +32,22 @@
|
||||||
#include "../events/SDL_events_c.h"
|
#include "../events/SDL_events_c.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static SDL_bool SDL_joystick_allows_background_events = SDL_FALSE;
|
||||||
static SDL_Joystick *SDL_joysticks = NULL;
|
static SDL_Joystick *SDL_joysticks = NULL;
|
||||||
static SDL_Joystick *SDL_updating_joystick = NULL;
|
static SDL_Joystick *SDL_updating_joystick = NULL;
|
||||||
|
|
||||||
int
|
int
|
||||||
SDL_JoystickInit(void)
|
SDL_JoystickInit(void)
|
||||||
{
|
{
|
||||||
|
const char *hint;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
/* Check to see if we should allow joystick events while in the background */
|
||||||
|
hint = SDL_GetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);
|
||||||
|
if (hint && *hint == '1') {
|
||||||
|
SDL_joystick_allows_background_events = SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
status = SDL_SYS_JoystickInit();
|
status = SDL_SYS_JoystickInit();
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
status = 0;
|
status = 0;
|
||||||
|
@ -455,17 +464,22 @@ SDL_JoystickQuit(void)
|
||||||
static SDL_bool
|
static SDL_bool
|
||||||
SDL_PrivateJoystickShouldIgnoreEvent()
|
SDL_PrivateJoystickShouldIgnoreEvent()
|
||||||
{
|
{
|
||||||
const char *hint;
|
if (SDL_joystick_allows_background_events)
|
||||||
if (SDL_GetKeyboardFocus() != NULL) {
|
{
|
||||||
return SDL_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
hint = SDL_GetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);
|
|
||||||
if (hint && *hint == '1') {
|
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SDL_WasInit(SDL_INIT_VIDEO)) {
|
||||||
|
if (SDL_GetKeyboardFocus() == NULL) {
|
||||||
|
// Video is initialized and we don't have focus, ignore the event.
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
|
} else {
|
||||||
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Video subsystem wasn't initialized, always allow the event
|
||||||
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* These are global for SDL_sysjoystick.c and SDL_events.c */
|
/* These are global for SDL_sysjoystick.c and SDL_events.c */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue