Skip to content

Commit

Permalink
wayland: Update for relative transformation function support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kontrabant committed Dec 20, 2024
1 parent 240fadf commit 3e3dd6d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/video/wayland/SDL_waylandevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -3042,17 +3042,25 @@ static void relative_pointer_handle_relative_motion(void *data,
struct SDL_WaylandInput *input = data;
SDL_VideoData *d = input->display;
SDL_WindowData *window = input->pointer_focus;
double dx_unaccel;
double dy_unaccel;
double dx;
double dy;

// Relative pointer event times are in microsecond granularity.
const Uint64 timestamp = SDL_US_TO_NS(((Uint64)time_hi << 32) | (Uint64)time_lo);

dx_unaccel = wl_fixed_to_double(dx_unaccel_w);
dy_unaccel = wl_fixed_to_double(dy_unaccel_w);
/* If the mouse scale function pointer is the system acceleration function,
* just return the accelerated data here. The transform function is a no-op.
*/
if (SDL_GetMouse()->ApplySystemScale != Wayland_ApplySystemScale) {
dx = wl_fixed_to_double(dx_unaccel_w);
dy = wl_fixed_to_double(dy_unaccel_w);
} else {
dx = wl_fixed_to_double(dx_w);
dy = wl_fixed_to_double(dy_w);
}

if (input->pointer_focus && d->relative_mouse_mode) {
SDL_SendMouseMotion(Wayland_GetEventTimestamp(timestamp), window->sdlwindow, input->pointer_id, true, (float)dx_unaccel, (float)dy_unaccel);
SDL_SendMouseMotion(Wayland_GetEventTimestamp(timestamp), window->sdlwindow, input->pointer_id, true, (float)dx, (float)dy);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/video/wayland/SDL_waylandmouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,11 @@ static SDL_MouseButtonFlags SDLCALL Wayland_GetGlobalMouseState(float *x, float
return result;
}

void Wayland_ApplySystemScale(void *internal, Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float *x, float *y)
{
// Wayland sends both unaccelerated and accelerated relative motion data, so this is just a flag/passthrough function.
}

#if 0 // TODO RECONNECT: See waylandvideo.c for more information!
static void Wayland_RecreateCursor(SDL_Cursor *cursor, SDL_VideoData *vdata)
{
Expand Down Expand Up @@ -973,6 +978,7 @@ void Wayland_InitMouse(void)
mouse->WarpMouseGlobal = Wayland_WarpMouseGlobal;
mouse->SetRelativeMouseMode = Wayland_SetRelativeMouseMode;
mouse->GetGlobalMouseState = Wayland_GetGlobalMouseState;
mouse->ApplySystemScale = Wayland_ApplySystemScale;

SDL_HitTestResult r = SDL_HITTEST_NORMAL;
while (r <= SDL_HITTEST_RESIZE_LEFT) {
Expand Down
1 change: 1 addition & 0 deletions src/video/wayland/SDL_waylandmouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
extern void Wayland_InitMouse(void);
extern void Wayland_FiniMouse(SDL_VideoData *data);
extern void Wayland_SetHitTestCursor(SDL_HitTestResult rc);
extern void Wayland_ApplySystemScale(void *internal, Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float *x, float *y);
#if 0 // TODO RECONNECT: See waylandvideo.c for more information!
extern void Wayland_RecreateCursors(void);
#endif // 0
Expand Down

0 comments on commit 3e3dd6d

Please sign in to comment.