Skip to content

Commit

Permalink
inline the single-instance function
Browse files Browse the repository at this point in the history
  • Loading branch information
expikr committed Jan 13, 2025
1 parent 1f8f659 commit 17d9c59
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 48 deletions.
85 changes: 40 additions & 45 deletions src/events/SDL_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,50 +1110,6 @@ SDL_MouseButtonFlags SDL_GetGlobalMouseState(float *x, float *y)
}
}

void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, bool ignore_relative_mode)
{
SDL_Mouse *mouse = SDL_GetMouse();

if (!window) {
window = mouse->focus;
}

if (!window) {
return;
}

if ((window->flags & SDL_WINDOW_MINIMIZED) == SDL_WINDOW_MINIMIZED) {
return;
}

// Ignore the previous position when we warp
mouse->last_x = x;
mouse->last_y = y;
mouse->has_position = false;

if (mouse->relative_mode && !ignore_relative_mode) {
/* 2.0.22 made warping in relative mode actually functional, which
* surprised many applications that weren't expecting the additional
* mouse motion.
*
* So for now, warping in relative mode adjusts the absolution position
* but doesn't generate motion events, unless SDL_HINT_MOUSE_RELATIVE_WARP_MOTION is set.
*/
if (!mouse->relative_mode_warp_motion) {
mouse->x = x;
mouse->y = y;
mouse->has_position = true;
return;
}
}

if (mouse->WarpMouse && !mouse->relative_mode) {
mouse->WarpMouse(window, x, y);
} else {
SDL_PrivateSendMouseMotion(0, window, SDL_GLOBAL_MOUSE_ID, false, x, y);
}
}

void SDL_DisableMouseWarpEmulation(void)
{
SDL_Mouse *mouse = SDL_GetMouse();
Expand Down Expand Up @@ -1202,7 +1158,46 @@ void SDL_WarpMouseInWindow(SDL_Window *window, float x, float y)
SDL_Mouse *mouse = SDL_GetMouse();
SDL_MaybeEnableWarpEmulation(window, x, y);

SDL_PerformWarpMouseInWindow(window, x, y, mouse->warp_emulation_active);
// previously SDL_PerformWarpMouseInWindow(window, x, y, mouse->warp_emulation_active);
bool ignore_relative_mode = mouse->warp_emulation_active;
if (!window) {
window = mouse->focus;
}

if (!window) {
return;
}

if ((window->flags & SDL_WINDOW_MINIMIZED) == SDL_WINDOW_MINIMIZED) {
return;
}

// Ignore the previous position when we warp
mouse->last_x = x;
mouse->last_y = y;
mouse->has_position = false;

if (mouse->relative_mode && !ignore_relative_mode) {
/* 2.0.22 made warping in relative mode actually functional, which
* surprised many applications that weren't expecting the additional
* mouse motion.
*
* So for now, warping in relative mode adjusts the absolution position
* but doesn't generate motion events, unless SDL_HINT_MOUSE_RELATIVE_WARP_MOTION is set.
*/
if (!mouse->relative_mode_warp_motion) {
mouse->x = x;
mouse->y = y;
mouse->has_position = true;
return;
}
}

if (mouse->WarpMouse && !mouse->relative_mode) {
mouse->WarpMouse(window, x, y);
} else {
SDL_PrivateSendMouseMotion(0, window, SDL_GLOBAL_MOUSE_ID, false, x, y);
}
}

bool SDL_WarpMouseGlobal(float x, float y)
Expand Down
3 changes: 0 additions & 3 deletions src/events/SDL_mouse_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ extern void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_
// Send a mouse wheel event
extern void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction);

// Warp the mouse within the window, potentially overriding relative mode
extern void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, bool ignore_relative_mode);

// Relative mouse mode
extern bool SDL_SetRelativeMouseMode(bool enabled);
extern bool SDL_GetRelativeMouseMode(void);
Expand Down

0 comments on commit 17d9c59

Please sign in to comment.