summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sdl2-macos-mouse-scrolling.diff (renamed from sdl2-macos-mouse-scrolling-patch.diff)14
-rw-r--r--src/ui/documentwidget.c37
2 files changed, 35 insertions, 16 deletions
diff --git a/sdl2-macos-mouse-scrolling-patch.diff b/sdl2-macos-mouse-scrolling.diff
index 633243ed..e2f30c24 100644
--- a/sdl2-macos-mouse-scrolling-patch.diff
+++ b/sdl2-macos-mouse-scrolling.diff
@@ -1,6 +1,6 @@
1diff -r 4f06c06b6d19 src/events/SDL_mouse.c 1diff -r 4f06c06b6d19 src/events/SDL_mouse.c
2--- a/src/events/SDL_mouse.c Wed Aug 05 15:28:51 2020 +0200 2--- a/src/events/SDL_mouse.c Wed Aug 05 15:28:51 2020 +0200
3+++ b/src/events/SDL_mouse.c Tue Sep 15 07:54:17 2020 +0300 3+++ b/src/events/SDL_mouse.c Tue Nov 10 12:16:06 2020 +0200
4@@ -642,8 +642,8 @@ 4@@ -642,8 +642,8 @@
5 event.wheel.preciseX = x; 5 event.wheel.preciseX = x;
6 event.wheel.preciseY = y; 6 event.wheel.preciseY = y;
@@ -14,8 +14,8 @@ diff -r 4f06c06b6d19 src/events/SDL_mouse.c
14 } 14 }
15diff -r 4f06c06b6d19 src/video/cocoa/SDL_cocoamouse.m 15diff -r 4f06c06b6d19 src/video/cocoa/SDL_cocoamouse.m
16--- a/src/video/cocoa/SDL_cocoamouse.m Wed Aug 05 15:28:51 2020 +0200 16--- a/src/video/cocoa/SDL_cocoamouse.m Wed Aug 05 15:28:51 2020 +0200
17+++ b/src/video/cocoa/SDL_cocoamouse.m Tue Sep 15 07:54:17 2020 +0300 17+++ b/src/video/cocoa/SDL_cocoamouse.m Tue Nov 10 12:16:06 2020 +0200
18@@ -424,8 +424,8 @@ 18@@ -424,10 +424,16 @@
19 } 19 }
20 20
21 SDL_MouseID mouseID = mouse->mouseID; 21 SDL_MouseID mouseID = mouse->mouseID;
@@ -25,4 +25,12 @@ diff -r 4f06c06b6d19 src/video/cocoa/SDL_cocoamouse.m
25+ CGFloat y = [event scrollingDeltaY]; 25+ CGFloat y = [event scrollingDeltaY];
26 SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL; 26 SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL;
27 27
28+ /* HACK: Make a distinction between precise and imprecise scrolling.
29+ Trackpad seems to be mouseID 0. */
30+ if (![event hasPreciseScrollingDeltas]) {
31+ mouseID = 1;
32+ }
33+
28 if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) { 34 if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) {
35 if ([event isDirectionInvertedFromDevice] == YES) {
36 direction = SDL_MOUSEWHEEL_FLIPPED;
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index a4bf38dc..c71758be 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -1891,21 +1891,32 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1891 } 1891 }
1892 } 1892 }
1893#if defined (iPlatformApple) 1893#if defined (iPlatformApple)
1894 /* Momentum scrolling. */ 1894 /* On macOS, we handle both trackpad and mouse events. We expect SDL to identify
1895 stop_Anim(&d->scrollY); 1895 which device is sending the event. */
1896 scroll_DocumentWidget_(d, -ev->wheel.y * get_Window()->pixelRatio * acceleration); 1896 if (ev->wheel.which == 0) { /* Trackpad with precise scrolling w/inertia. */
1897#else 1897 stop_Anim(&d->scrollY);
1898 if (keyMods_Sym(SDL_GetModState()) == KMOD_PRIMARY) { 1898 scroll_DocumentWidget_(d, -ev->wheel.y * get_Window()->pixelRatio * acceleration);
1899 postCommandf_App("zoom.delta arg:%d", ev->wheel.y > 0 ? 10 : -10);
1900 return iTrue;
1901 } 1899 }
1902 smoothScroll_DocumentWidget_( 1900 else
1903 d, 1901#endif
1904 -3 * ev->wheel.y * lineHeight_Text(paragraph_FontId) * acceleration, 1902 /* Traditional mouse wheel. */ {
1905 smoothDuration_DocumentWidget_ * 1903#if defined (iPlatformApple)
1906 (!isFinished_Anim(&d->scrollY) && pos_Anim(&d->scrollY) < 0.25f ? 0.5f : 1.0f)); 1904 /* Disregard wheel acceleration applied by the OS. */
1907 /* accelerated speed for repeated wheelings */ 1905 const int amount = iSign(ev->wheel.y);
1906#else
1907 const int amount = ev->wheel.y;
1908#endif 1908#endif
1909 if (keyMods_Sym(SDL_GetModState()) == KMOD_PRIMARY) {
1910 postCommandf_App("zoom.delta arg:%d", amount > 0 ? 10 : -10);
1911 return iTrue;
1912 }
1913 smoothScroll_DocumentWidget_(
1914 d,
1915 -3 * amount * lineHeight_Text(paragraph_FontId) * acceleration,
1916 smoothDuration_DocumentWidget_ *
1917 (!isFinished_Anim(&d->scrollY) && pos_Anim(&d->scrollY) < 0.25f ? 0.5f : 1.0f));
1918 /* accelerated speed for repeated wheelings */
1919 }
1909 iChangeFlags(d->flags, noHoverWhileScrolling_DocumentWidgetFlag, iTrue); 1920 iChangeFlags(d->flags, noHoverWhileScrolling_DocumentWidgetFlag, iTrue);
1910 return iTrue; 1921 return iTrue;
1911 } 1922 }