summaryrefslogtreecommitdiff
path: root/src/app.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-07 10:24:58 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-07 10:25:42 +0200
commit892094fa91f064e24d9017d84228f6c781add428 (patch)
tree45c21fa52f4742578947339f810e56036b306216 /src/app.c
parent237ea3e1a66b792c2258eebd39e7771002c5584b (diff)
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
Diffstat (limited to 'src/app.c')
-rw-r--r--src/app.c38
1 files changed, 32 insertions, 6 deletions
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) {
901 d->isIdling = iFalse; 901 d->isIdling = iFalse;
902#endif 902#endif
903 gotEvents = iTrue; 903 gotEvents = iTrue;
904 /* Keyboard modifier mapping. */ { 904 /* Keyboard modifier mapping. */
905 if (ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP) { 905 if (ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP) {
906 /* Track Caps Lock state as a modifier. */ 906 /* Track Caps Lock state as a modifier. */
907 if (ev.key.keysym.sym == SDLK_CAPSLOCK) { 907 if (ev.key.keysym.sym == SDLK_CAPSLOCK) {
908 setCapsLockDown_Keys(ev.key.state == SDL_PRESSED); 908 setCapsLockDown_Keys(ev.key.state == SDL_PRESSED);
909 }
910 ev.key.keysym.mod = mapMods_Keys(ev.key.keysym.mod & ~KMOD_CAPS);
911 }
912 /* Scroll events may be per-pixel or mouse wheel steps. */
913 if (ev.type == SDL_MOUSEWHEEL) {
914#if defined (iPlatformAppleDesktop)
915 /* On macOS, we handle both trackpad and mouse events. We expect SDL to identify
916 which device is sending the event. */
917 if (ev.wheel.which == 0) {
918 /* Trackpad with precise scrolling w/inertia (points). */
919 setPerPixel_MouseWheelEvent(&ev.wheel, iTrue);
920 ev.wheel.x *= -d->window->pixelRatio;
921 ev.wheel.y *= d->window->pixelRatio;
922 /* Only scroll on one axis at a time. */
923 if (iAbs(ev.wheel.x) > iAbs(ev.wheel.y)) {
924 ev.wheel.y = 0;
925 }
926 else {
927 ev.wheel.x = 0;
909 } 928 }
910 ev.key.keysym.mod = mapMods_Keys(ev.key.keysym.mod & ~KMOD_CAPS);
911 } 929 }
930 else {
931 /* Disregard wheel acceleration applied by the OS. */
932 ev.wheel.y = iSign(ev.wheel.y);
933 }
934#endif
935#if defined (iPlatformMsys)
936// ev.wheel.x = -ev.wheel.x;
937#endif
912 } 938 }
913 iBool wasUsed = processEvent_Window(d->window, &ev); 939 iBool wasUsed = processEvent_Window(d->window, &ev);
914 if (!wasUsed) { 940 if (!wasUsed) {