| Summary: | Cannot poll joystick button when window is not in focus | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Alan <aychen> |
| Component: | joystick | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | aychen, icculus |
| Version: | 2.0.3 | ||
| Hardware: | x86 | ||
| OS: | Mac OS X 10.8 | ||
|
Description
Alan
2014-05-16 20:07:32 UTC
(In reply to Alan from comment #0) > What I've noticed is that when the window is not in focus, the buttons for > the joystick no longer work. The hat and axes still work. Oddly enough, if > I don't ever call SDL_PollEvent, then the joystick button works when the > window is not in focus. Not giving joystick events when an SDL window doesn't have focus is intentional (although I would argue incorrect) behavior. Never calling SDL_PollEvent() "works" because SDL doesn't know the window lost focus until the OS event queue is processed, which happens under SDL_PollEvent(), even if the OS has already taken focus from the window. I'm surprised you get hat and axes events, though; they should be protected by the same check as the buttons. Anyhow, to get joystick events even if the window doesn't have focus, call this sometime after SDL_Init()... SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); (That probably fixes your concern, but I'm marking this bug ASSIGNED for now, so I can see why the hats and axes still come through.) --ryan. Hey Ryan, That worked great, thank you. Alan I fixed the bug where you got axis and hat events if the application didn't have focus. https://hg.libsdl.org/SDL/rev/8e09eceea61e |