diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-29 13:45:32 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-29 14:18:39 +0100 |
| commit | d17db29f66214b478fca83c34eb96cc5e0fbdbe2 (patch) | |
| tree | 189a894ab8b762cf21694d45fd8c9f9ee367dc6f /src/input.c | |
| parent | 838d75bce98ca5a1f90f762e80d2aa649d4e0642 (diff) | |
Support SDL 3.2
Diffstat (limited to 'src/input.c')
| -rw-r--r-- | src/input.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/input.c b/src/input.c index 0cc2f78..f85c63c 100644 --- a/src/input.c +++ b/src/input.c @@ -1,6 +1,7 @@ #include <SDL3/SDL_clipboard.h> #include <SDL3/SDL_log.h> #include <SDL3/SDL_mouse.h> +#include <SDL3/SDL_version.h> #include "input.h" @@ -297,10 +298,30 @@ static int32_t saturating_add(int32_t a, int32_t b) { } static bool handle_wheel(struct pw_input *input, SDL_MouseWheelEvent *wheel) { +#if SDL_VERSION_ATLEAST(3, 2, 12) input->mouse.wheel.dx = saturating_add(input->mouse.wheel.dx, wheel->integer_x); input->mouse.wheel.dy = saturating_add(input->mouse.wheel.dy, wheel->integer_y); +#else + // We approximate wheel movement for older SDL versions that do not support + // the integer event values. This is slightly wrong (as we lose fractional + // movement across frames), but good enough: this will likely only affect + // homebrew versions with older SDL 3 ports that don't have mouse wheels + // anyway. If this becomes a problem, we can change mouse wheel deltas to + // be floats and report full ticks (similar to how we handle relative mouse + // positions). + if (!SDL_isnanf(wheel->x)) { + input->mouse.wheel.dx = saturating_add( + input->mouse.wheel.dx, + (int32_t)SDL_clamp(wheel->x, -PW_MAX_SAFE_INT, PW_MAX_SAFE_INT)); + } + if (!SDL_isnanf(wheel->y)) { + input->mouse.wheel.dy = saturating_add( + input->mouse.wheel.dy, + (int32_t)SDL_clamp(wheel->y, -PW_MAX_SAFE_INT, PW_MAX_SAFE_INT)); + } +#endif return true; } |
