From 4a03c76b436bf0fe27b33039b12f034b85b27341 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 6 Aug 2020 08:20:24 +0300 Subject: macOS: Smooth inertia scrolling with trackpad Requires a slightly tweaked SDL 2, though, when it comes to handling the scroll events. --- src/main.c | 3 +++ src/ui/documentwidget.c | 5 +++++ src/ui/macos.m | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index f6ff045d..a8f97d52 100644 --- a/src/main.c +++ b/src/main.c @@ -7,7 +7,10 @@ #include "app.h" +extern void enableWheel_MacOS(void); + int main(int argc, char **argv) { + enableWheel_MacOS(); #if defined (iPlatformMsys) /* MSYS runtime takes care of WinMain. */ SDL_SetMainReady(); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 48eb482f..6d3e7a9c 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -864,11 +864,16 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e } } else if (ev->type == SDL_MOUSEWHEEL) { +#if defined (iPlatformApple) + /* Momentum scrolling. */ + scroll_DocumentWidget_(d, -ev->wheel.y * get_Window()->pixelRatio); +#else if (keyMods_Sym(SDL_GetModState()) == KMOD_PRIMARY) { changeTextSize_DocumentWidget_(d, ev->wheel.y > 0 ? 10 : -10); return iTrue; } scroll_DocumentWidget_(d, -3 * ev->wheel.y * lineHeight_Text(default_FontId)); +#endif return iTrue; } else if (ev->type == SDL_MOUSEMOTION) { diff --git a/src/ui/macos.m b/src/ui/macos.m index b50fbf38..46d2bfa1 100644 --- a/src/ui/macos.m +++ b/src/ui/macos.m @@ -98,7 +98,7 @@ enum iTouchBarVariant { //- (NSTouchBar *)makeTouchBar; /* SDL needs to do its own thing. */ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename; -- (void)applicationDidFinishLaunching:(NSNotification *)notificatiosn; +- (void)applicationDidFinishLaunching:(NSNotification *)notifications; @end @implementation MyDelegate @@ -333,6 +333,11 @@ enum iTouchBarVariant { @end +void enableWheel_MacOS(void) { + [[NSUserDefaults standardUserDefaults] setBool: YES + forKey: @"AppleMomentumScrollSupported"]; +} + void setupApplication_MacOS(void) { NSApplication *app = [NSApplication sharedApplication]; /* Our delegate will override SDL's delegate. */ -- cgit v1.2.3