Repository: libsdl-org/SDL
File: src/events/SDL_mouse.c (C)

Code before:
    SDL_RemoveHintCallback(SDL_HINT_MOUSE_TOUCH_EVENTS,
                        SDL_MouseTouchEventsChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_PEN_MOUSE_EVENTS,
                        SDL_PenMouseEventsChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_PEN_TOUCH_EVENTS,
                        SDL_PenTouchEventsChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_MOUSE_AUTO_CAPTURE,
                        SDL_MouseAutoCaptureChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_MOUSE_RELATIVE_WARP_MOTION,
                        SDL_MouseRelativeWarpMotionChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_MOUSE_RELATIVE_CURSOR_VISIBLE,
                        SDL_MouseRelativeCursorVisibleChanged, mouse);

    for (int i = SDL_mouse_count; i--; ) {
        SDL_RemoveMouse(SDL_mice[i].instance_id, false);
    }
    SDL_free(SDL_mice);
    SDL_mice = NULL;
}

void SDL_SetRelativeMouseTransform(SDL_MouseMotionTransformCallback transform, void *userdata)
{
    SDL_Mouse *mouse = SDL_GetMouse();
    mouse->InputTransform = transform;
    mouse->input_transform_data = userdata;
}

SDL_MouseButtonFlags SDL_GetMouseState(float *x, float *y)
{
    SDL_Mouse *mouse = SDL_GetMouse();

    if (x) {
        *x = mouse->x;
    }
    if (y) {
        *y = mouse->y;
    }
    return SDL_GetMouseButtonState(mouse, SDL_GLOBAL_MOUSE_ID, true);
}

SDL_MouseButtonFlags SDL_GetRelativeMouseState(float *x, float *y)
{
    SDL_Mouse *mouse = SDL_GetMouse();

    if (x) {
        *x = mouse->x_accu;

Review comment (suggestion):
@slouken I’m inexperienced with synchronization considerations, what would happen if this function is called while relative mode is active? It essentially swaps out two pointers that is constantly referenced by a different thread. 

(Though I don’t seem to see any extra measures taken when updating other data used by relative mode thread, so maybe it’s ok? But then this one in particular is a function pointer so I’m not sure)

Code after:
    SDL_RemoveHintCallback(SDL_HINT_MOUSE_TOUCH_EVENTS,
                        SDL_MouseTouchEventsChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_PEN_MOUSE_EVENTS,
                        SDL_PenMouseEventsChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_PEN_TOUCH_EVENTS,
                        SDL_PenTouchEventsChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_MOUSE_AUTO_CAPTURE,
                        SDL_MouseAutoCaptureChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_MOUSE_RELATIVE_WARP_MOTION,
                        SDL_MouseRelativeWarpMotionChanged, mouse);

    SDL_RemoveHintCallback(SDL_HINT_MOUSE_RELATIVE_CURSOR_VISIBLE,
                        SDL_MouseRelativeCursorVisibleChanged, mouse);

    for (int i = SDL_mouse_count; i--; ) {
        SDL_RemoveMouse(SDL_mice[i].instance_id, false);
    }
    SDL_free(SDL_mice);
    SDL_mice = NULL;
}

bool SDL_SetRelativeMouseTransform(SDL_MouseMotionTransformCallback transform, void *userdata)
{
    SDL_Mouse *mouse = SDL_GetMouse();
    if (mouse->relative_mode) {
        return SDL_SetError("Can't set mouse transform while relative mode is active");
    }
    mouse->InputTransform = transform;
    mouse->input_transform_data = userdata;
    return true;
}

SDL_MouseButtonFlags SDL_GetMouseState(float *x, float *y)
{
    SDL_Mouse *mouse = SDL_GetMouse();

    if (x) {
        *x = mouse->x;
    }
    if (y) {
        *y = mouse->y;
    }
    return SDL_GetMouseButtonState(mouse, SDL_GLOBAL_MOUSE_ID, true);
}

SDL_MouseButtonFlags SDL_GetRelativeMouseState(float *x, float *y)
{