From ba425fa4038580fa71bb944e55fedb04238d7197 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Wed, 19 May 2021 10:43:15 +0300 Subject: iOS: Updated SDL patch The SDL patch now contains the macOS scroll event change and, as a new addition, iOS status bar appearance control via the SDL view controller. --- README.md | 2 +- sdl2-macos-ios.diff | 85 +++++++++++++++++++++++++++++++++++++++++ sdl2-macos-mouse-scrolling.diff | 36 ----------------- 3 files changed, 86 insertions(+), 37 deletions(-) create mode 100644 sdl2-macos-ios.diff delete mode 100644 sdl2-macos-mouse-scrolling.diff diff --git a/README.md b/README.md index 3d5ec5ac..f1a62578 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ When using OpenSSL 1.1.1 from Homebrew, you must add its pkgconfig path to your export PKG_CONFIG_PATH=/opt/homebrew/Cellar/openssl@1.1/1.1.1i/lib/pkgconfig -Also, SDL's trackpad scrolling behavior on macOS is not optimal for regular GUI apps because it emulates a physical mouse wheel. This may change in a future release of SDL, but at least in 2.0.14 (and earlier) a [small patch](https://git.skyjake.fi/gemini/lagrange/raw/branch/dev/sdl2-macos-mouse-scrolling.diff) is required to allow momentum scrolling to come through as single-pixel mouse wheel events. Note that SDL comes with an Xcode project; use the "Shared Library" target and check that you are doing a Release build. +Also, SDL's trackpad scrolling behavior on macOS is not optimal for regular GUI apps because it emulates a physical mouse wheel. This may change in a future release of SDL, but at least in 2.0.14 (and earlier) a [small patch](https://git.skyjake.fi/gemini/lagrange/raw/branch/dev/sdl2-macos-ios.diff) is required to allow momentum scrolling to come through as single-pixel mouse wheel events. Note that SDL comes with an Xcode project; use the "Shared Library" target and check that you are doing a Release build. ### Compiling on Windows diff --git a/sdl2-macos-ios.diff b/sdl2-macos-ios.diff new file mode 100644 index 00000000..04d0f2e5 --- /dev/null +++ b/sdl2-macos-ios.diff @@ -0,0 +1,85 @@ +Only in SDL2-2.0.14/src: .DS_Store +diff -ru SDL2-2.0.14-original/src/events/SDL_mouse.c SDL2-2.0.14/src/events/SDL_mouse.c +--- SDL2-2.0.14-original/src/events/SDL_mouse.c 2020-12-21 19:44:36.000000000 +0200 ++++ SDL2-2.0.14/src/events/SDL_mouse.c 2021-01-06 18:31:18.000000000 +0200 +@@ -647,8 +647,8 @@ + event.wheel.preciseX = x; + event.wheel.preciseY = y; + #endif +- event.wheel.x = integral_x; +- event.wheel.y = integral_y; ++ event.wheel.x = x; //integral_x; ++ event.wheel.y = y; //integral_y; + event.wheel.direction = (Uint32)direction; + posted = (SDL_PushEvent(&event) > 0); + } +Only in SDL2-2.0.14/src/video: .DS_Store +diff -ru SDL2-2.0.14-original/src/video/cocoa/SDL_cocoamouse.m SDL2-2.0.14/src/video/cocoa/SDL_cocoamouse.m +--- SDL2-2.0.14-original/src/video/cocoa/SDL_cocoamouse.m 2020-12-21 19:44:36.000000000 +0200 ++++ SDL2-2.0.14/src/video/cocoa/SDL_cocoamouse.m 2021-01-06 18:31:18.000000000 +0200 +@@ -423,10 +423,16 @@ + } + + SDL_MouseID mouseID = mouse->mouseID; +- CGFloat x = -[event deltaX]; +- CGFloat y = [event deltaY]; ++ CGFloat x = -[event scrollingDeltaX]; ++ CGFloat y = [event scrollingDeltaY]; + SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL; + ++ /* HACK: Make a distinction between precise and imprecise scrolling. ++ Trackpad seems to be mouseID 0. */ ++ if (![event hasPreciseScrollingDeltas]) { ++ mouseID = 1; ++ } ++ + if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) { + if ([event isDirectionInvertedFromDevice] == YES) { + direction = SDL_MOUSEWHEEL_FLIPPED; +Only in SDL2-2.0.14/src/video/cocoa: SDL_cocoamouse.m.orig +diff -ru SDL2-2.0.14-original/src/video/uikit/SDL_uikitviewcontroller.h SDL2-2.0.14/src/video/uikit/SDL_uikitviewcontroller.h +--- SDL2-2.0.14-original/src/video/uikit/SDL_uikitviewcontroller.h 2020-12-21 19:44:36.000000000 +0200 ++++ SDL2-2.0.14/src/video/uikit/SDL_uikitviewcontroller.h 2021-05-17 13:11:13.000000000 +0300 +@@ -58,10 +58,13 @@ + #if !TARGET_OS_TV + - (NSUInteger)supportedInterfaceOrientations; + - (BOOL)prefersStatusBarHidden; ++- (void)setStatusStyle:(UIStatusBarStyle)style; ++- (UIStatusBarStyle)preferredStatusBarStyle; + - (BOOL)prefersHomeIndicatorAutoHidden; + - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures; + + @property (nonatomic, assign) int homeIndicatorHidden; ++@property (nonatomic, assign) UIStatusBarStyle statusBarStyle; + #endif + + #if SDL_IPHONE_KEYBOARD +diff -ru SDL2-2.0.14-original/src/video/uikit/SDL_uikitviewcontroller.m SDL2-2.0.14/src/video/uikit/SDL_uikitviewcontroller.m +--- SDL2-2.0.14-original/src/video/uikit/SDL_uikitviewcontroller.m 2020-12-21 19:44:36.000000000 +0200 ++++ SDL2-2.0.14/src/video/uikit/SDL_uikitviewcontroller.m 2021-05-17 13:11:58.000000000 +0300 +@@ -104,6 +104,7 @@ + #endif + + #if !TARGET_OS_TV ++ self.statusBarStyle = UIStatusBarStyleDefault; + SDL_AddHintCallback(SDL_HINT_IOS_HIDE_HOME_INDICATOR, + SDL_HideHomeIndicatorHintChanged, + (__bridge void *) self); +@@ -229,6 +230,17 @@ + return hidden; + } + ++- (void)setStatusStyle:(UIStatusBarStyle)style ++{ ++ self.statusBarStyle = style; ++ [self setNeedsStatusBarAppearanceUpdate]; ++} ++ ++- (UIStatusBarStyle)preferredStatusBarStyle ++{ ++ return self.statusBarStyle; ++} ++ + - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures + { + if (self.homeIndicatorHidden >= 0) { diff --git a/sdl2-macos-mouse-scrolling.diff b/sdl2-macos-mouse-scrolling.diff deleted file mode 100644 index e2f30c24..00000000 --- a/sdl2-macos-mouse-scrolling.diff +++ /dev/null @@ -1,36 +0,0 @@ -diff -r 4f06c06b6d19 src/events/SDL_mouse.c ---- a/src/events/SDL_mouse.c Wed Aug 05 15:28:51 2020 +0200 -+++ b/src/events/SDL_mouse.c Tue Nov 10 12:16:06 2020 +0200 -@@ -642,8 +642,8 @@ - event.wheel.preciseX = x; - event.wheel.preciseY = y; - #endif -- event.wheel.x = integral_x; -- event.wheel.y = integral_y; -+ event.wheel.x = x; //integral_x; -+ event.wheel.y = y; //integral_y; - event.wheel.direction = (Uint32)direction; - posted = (SDL_PushEvent(&event) > 0); - } -diff -r 4f06c06b6d19 src/video/cocoa/SDL_cocoamouse.m ---- a/src/video/cocoa/SDL_cocoamouse.m Wed Aug 05 15:28:51 2020 +0200 -+++ b/src/video/cocoa/SDL_cocoamouse.m Tue Nov 10 12:16:06 2020 +0200 -@@ -424,10 +424,16 @@ - } - - SDL_MouseID mouseID = mouse->mouseID; -- CGFloat x = -[event deltaX]; -- CGFloat y = [event deltaY]; -+ CGFloat x = -[event scrollingDeltaX]; -+ CGFloat y = [event scrollingDeltaY]; - SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL; - -+ /* HACK: Make a distinction between precise and imprecise scrolling. -+ Trackpad seems to be mouseID 0. */ -+ if (![event hasPreciseScrollingDeltas]) { -+ mouseID = 1; -+ } -+ - if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) { - if ([event isDirectionInvertedFromDevice] == YES) { - direction = SDL_MOUSEWHEEL_FLIPPED; -- cgit v1.2.3