From 892094fa91f064e24d9017d84228f6c781add428 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 7 Mar 2021 10:24:58 +0200 Subject: Processing per-pixel scroll events Do platform-specific processing of scroll events up front so widgets can support both types of scrolls everywhere. IssueID #166 --- src/app.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'src/app.c') diff --git a/src/app.c b/src/app.c index ada142f0..6a3dc00b 100644 --- a/src/app.c +++ b/src/app.c @@ -901,14 +901,40 @@ void processEvents_App(enum iAppEventMode eventMode) { d->isIdling = iFalse; #endif gotEvents = iTrue; - /* Keyboard modifier mapping. */ { - if (ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP) { - /* Track Caps Lock state as a modifier. */ - if (ev.key.keysym.sym == SDLK_CAPSLOCK) { - setCapsLockDown_Keys(ev.key.state == SDL_PRESSED); + /* Keyboard modifier mapping. */ + if (ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP) { + /* Track Caps Lock state as a modifier. */ + if (ev.key.keysym.sym == SDLK_CAPSLOCK) { + setCapsLockDown_Keys(ev.key.state == SDL_PRESSED); + } + ev.key.keysym.mod = mapMods_Keys(ev.key.keysym.mod & ~KMOD_CAPS); + } + /* Scroll events may be per-pixel or mouse wheel steps. */ + if (ev.type == SDL_MOUSEWHEEL) { +#if defined (iPlatformAppleDesktop) + /* On macOS, we handle both trackpad and mouse events. We expect SDL to identify + which device is sending the event. */ + if (ev.wheel.which == 0) { + /* Trackpad with precise scrolling w/inertia (points). */ + setPerPixel_MouseWheelEvent(&ev.wheel, iTrue); + ev.wheel.x *= -d->window->pixelRatio; + ev.wheel.y *= d->window->pixelRatio; + /* Only scroll on one axis at a time. */ + if (iAbs(ev.wheel.x) > iAbs(ev.wheel.y)) { + ev.wheel.y = 0; + } + else { + ev.wheel.x = 0; } - ev.key.keysym.mod = mapMods_Keys(ev.key.keysym.mod & ~KMOD_CAPS); } + else { + /* Disregard wheel acceleration applied by the OS. */ + ev.wheel.y = iSign(ev.wheel.y); + } +#endif +#if defined (iPlatformMsys) +// ev.wheel.x = -ev.wheel.x; +#endif } iBool wasUsed = processEvent_Window(d->window, &ev); if (!wasUsed) { -- cgit v1.2.3