We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4995

Summary: SDL2 lacks joystick capture (grab) support
Product: SDL Reporter: SD-Snatcher <sdsnatcheralpha>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: cameron.gutman
Version: 2.0.10   
Hardware: All   
OS: All   

Description SD-Snatcher 2020-02-18 14:07:10 UTC
In SDL1, joystick events were received even when the window had no focus. This behaviour was explicitly changed on SDL2 to receive/ignore the events based on the windows focus state:

static SDL_bool
SDL_PrivateJoystickShouldIgnoreEvent()
{
    if (SDL_joystick_allows_background_events) {
        return SDL_FALSE;
    }

    if (SDL_HasWindows() && SDL_GetKeyboardFocus() == NULL) {
        /* We have windows but we don't have focus, ignore the event. */
        return SDL_TRUE;
    }
    return SDL_FALSE;
}

But when developing games, usually the IDE is an external program. This means that step-by-step debugging of a game with joystick support got quite more convoluted.

A simple solution to this problem would be to implement a SDL_CaptureJoystick function, similar (but not identical) to the existing SDL_CaptureMouse.

The idea would be just to be able to change the behaviour of the SDL_PrivateJoystickShouldIgnoreEvent to keep receiving joystick events without windows focus, or ignore them.
Comment 1 Cameron Gutman 2020-02-21 20:49:37 UTC
This sounds like what SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS does. Does that not work for your scenario?
Comment 2 Sam Lantinga 2020-03-02 23:25:17 UTC
SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS is what you want here.
Comment 3 Sam Lantinga 2020-03-02 23:25:46 UTC
Whoops, meant to mark this as not a bug.