src/joystick/SDL_joystick.c
changeset 7337 5ba1fafc6a94
parent 7307 5d6b7b9432d3
child 7360 b86947ea2749
equal deleted inserted replaced
7336:b0ef4d043c7b 7337:5ba1fafc6a94
    20 */
    20 */
    21 #include "SDL_config.h"
    21 #include "SDL_config.h"
    22 
    22 
    23 /* This is the joystick API for Simple DirectMedia Layer */
    23 /* This is the joystick API for Simple DirectMedia Layer */
    24 
    24 
       
    25 #include "SDL.h"
    25 #include "SDL_events.h"
    26 #include "SDL_events.h"
    26 #include "SDL_sysjoystick.h"
    27 #include "SDL_sysjoystick.h"
    27 #include "SDL_assert.h"
    28 #include "SDL_assert.h"
    28 #include "SDL_hints.h"
    29 #include "SDL_hints.h"
    29 
    30 
    30 #if !SDL_EVENTS_DISABLED
    31 #if !SDL_EVENTS_DISABLED
    31 #include "../events/SDL_events_c.h"
    32 #include "../events/SDL_events_c.h"
    32 #endif
    33 #endif
    33 
    34 
       
    35 static SDL_bool SDL_joystick_allows_background_events = SDL_FALSE;
    34 static SDL_Joystick *SDL_joysticks = NULL;
    36 static SDL_Joystick *SDL_joysticks = NULL;
    35 static SDL_Joystick *SDL_updating_joystick = NULL;
    37 static SDL_Joystick *SDL_updating_joystick = NULL;
    36 
    38 
    37 int
    39 int
    38 SDL_JoystickInit(void)
    40 SDL_JoystickInit(void)
    39 {
    41 {
       
    42     const char *hint;
    40     int status;
    43     int status;
       
    44 	
       
    45     /* Check to see if we should allow joystick events while in the background */
       
    46     hint = SDL_GetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);
       
    47     if (hint && *hint == '1') {
       
    48         SDL_joystick_allows_background_events = SDL_TRUE;
       
    49     }
    41 
    50 
    42     status = SDL_SYS_JoystickInit();
    51     status = SDL_SYS_JoystickInit();
    43     if (status >= 0) {
    52     if (status >= 0) {
    44       status = 0;
    53         status = 0;
    45     }
    54     }
    46     return (status);
    55     return (status);
    47 }
    56 }
    48 
    57 
    49 /*
    58 /*
   453 
   462 
   454 
   463 
   455 static SDL_bool
   464 static SDL_bool
   456 SDL_PrivateJoystickShouldIgnoreEvent()
   465 SDL_PrivateJoystickShouldIgnoreEvent()
   457 {
   466 {
   458     const char *hint;
   467     if (SDL_joystick_allows_background_events)
   459     if (SDL_GetKeyboardFocus() != NULL) {
   468     {
   460         return SDL_FALSE;
   469         return SDL_FALSE;
   461     }
   470     }
   462 
   471 
   463     hint = SDL_GetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);
   472     if (SDL_WasInit(SDL_INIT_VIDEO)) {
   464     if (hint && *hint == '1') {
   473         if (SDL_GetKeyboardFocus() == NULL) {
   465         return SDL_FALSE;
   474             // Video is initialized and we don't have focus, ignore the event.
   466     }
   475             return SDL_TRUE;
   467 
   476         } else {
   468     return SDL_TRUE;
   477             return SDL_FALSE;
       
   478         }
       
   479     }
       
   480 
       
   481     // Video subsystem wasn't initialized, always allow the event
       
   482     return SDL_FALSE;
   469 }
   483 }
   470 
   484 
   471 /* These are global for SDL_sysjoystick.c and SDL_events.c */
   485 /* These are global for SDL_sysjoystick.c and SDL_events.c */
   472 
   486 
   473 int
   487 int