Added SDL_HINT_IOS_HIDE_HOME_INDICATOR to determine how the home indicator on the iPhone X is handled.
authorSam Lantinga <slouken@libsdl.org>
Thu, 01 Feb 2018 15:21:01 -0800
changeset 11841fe303e78ea49
parent 11840 4d52395a8dba
child 11842 9577835e5809
Added SDL_HINT_IOS_HIDE_HOME_INDICATOR to determine how the home indicator on the iPhone X is handled.

This variable can be set to the following values:
"0" - The indicator bar is not hidden (default for windowed applications)
"1" - The indicator bar is hidden and is shown when the screen is touched (useful for movie playback applications)
"2" - The indicator bar is dim and the first swipe makes it visible and the second swipe performs the "home" action (default for fullscreen applications)
include/SDL_hints.h
src/video/uikit/SDL_uikitmessagebox.m
src/video/uikit/SDL_uikitviewcontroller.h
src/video/uikit/SDL_uikitviewcontroller.m
     1.1 --- a/include/SDL_hints.h	Tue Jan 30 18:12:25 2018 -0800
     1.2 +++ b/include/SDL_hints.h	Thu Feb 01 15:21:01 2018 -0800
     1.3 @@ -366,6 +366,17 @@
     1.4  #define SDL_HINT_APPLE_TV_REMOTE_SWIPES_AS_ARROW_KEYS "SDL_APPLE_TV_REMOTE_SWIPES_AS_ARROW_KEYS"
     1.5  
     1.6  /**
     1.7 + * \brief  A variable controlling whether the home indicator bar on iPhone X
     1.8 + *         should be hidden.
     1.9 + *
    1.10 + *  This variable can be set to the following values:
    1.11 + *    "0"       - The indicator bar is not hidden (default for windowed applications)
    1.12 + *    "1"       - The indicator bar is hidden and is shown when the screen is touched (useful for movie playback applications)
    1.13 + *    "2"       - The indicator bar is dim and the first swipe makes it visible and the second swipe performs the "home" action (default for fullscreen applications)
    1.14 + */
    1.15 +#define SDL_HINT_IOS_HIDE_HOME_INDICATOR "SDL_IOS_HIDE_HOME_INDICATOR"
    1.16 +
    1.17 +/**
    1.18   *  \brief  A variable controlling whether the Android / iOS built-in
    1.19   *  accelerometer should be listed as a joystick device, rather than listing
    1.20   *  actual joysticks only.
    1.21 @@ -775,7 +786,7 @@
    1.22   *   "0"       - SDL will generate a window-close event when it sees Alt+F4.
    1.23   *   "1"       - SDL will only do normal key handling for Alt+F4.
    1.24   */
    1.25 -#define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4	"SDL_WINDOWS_NO_CLOSE_ON_ALT_F4"
    1.26 +#define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 "SDL_WINDOWS_NO_CLOSE_ON_ALT_F4"
    1.27  
    1.28  /**
    1.29   *  \brief Prevent SDL from using version 4 of the bitmap header when saving BMPs.
     2.1 --- a/src/video/uikit/SDL_uikitmessagebox.m	Tue Jan 30 18:12:25 2018 -0800
     2.2 +++ b/src/video/uikit/SDL_uikitmessagebox.m	Thu Feb 01 15:21:01 2018 -0800
     2.3 @@ -109,6 +109,18 @@
     2.4          alertwindow.hidden = YES;
     2.5      }
     2.6  
     2.7 +    /* Force the main SDL window to re-evaluate home indicator state */
     2.8 +    SDL_Window *focus = SDL_GetFocusWindow();
     2.9 +    if (focus) {
    2.10 +        SDL_WindowData *data = (__bridge SDL_WindowData *) focus->driverdata;
    2.11 +        if (data != nil) {
    2.12 +            if (@available(iOS 11.0, *)) {
    2.13 +                [data.viewcontroller performSelectorOnMainThread:@selector(setNeedsUpdateOfHomeIndicatorAutoHidden) withObject:nil waitUntilDone:NO];
    2.14 +                [data.viewcontroller performSelectorOnMainThread:@selector(setNeedsUpdateOfScreenEdgesDeferringSystemGestures) withObject:nil waitUntilDone:NO];
    2.15 +            }
    2.16 +        }
    2.17 +    }
    2.18 +
    2.19      *buttonid = messageboxdata->buttons[clickedindex].buttonid;
    2.20      return YES;
    2.21  #else
     3.1 --- a/src/video/uikit/SDL_uikitviewcontroller.h	Tue Jan 30 18:12:25 2018 -0800
     3.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.h	Thu Feb 01 15:21:01 2018 -0800
     3.3 @@ -58,6 +58,10 @@
     3.4  #if !TARGET_OS_TV
     3.5  - (NSUInteger)supportedInterfaceOrientations;
     3.6  - (BOOL)prefersStatusBarHidden;
     3.7 +- (BOOL)prefersHomeIndicatorAutoHidden;
     3.8 +- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures;
     3.9 +
    3.10 +@property (nonatomic, assign) int homeIndicatorHidden;
    3.11  #endif
    3.12  
    3.13  #if SDL_IPHONE_KEYBOARD
     4.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Tue Jan 30 18:12:25 2018 -0800
     4.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Thu Feb 01 15:21:01 2018 -0800
     4.3 @@ -50,6 +50,21 @@
     4.4  }
     4.5  #endif
     4.6  
     4.7 +#if !TARGET_OS_TV
     4.8 +static void SDLCALL
     4.9 +SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    4.10 +{
    4.11 +    @autoreleasepool {
    4.12 +        SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata;
    4.13 +        viewcontroller.homeIndicatorHidden = (hint && *hint) ? SDL_atoi(hint) : -1;
    4.14 +        if (@available(iOS 11.0, *)) {
    4.15 +            [viewcontroller setNeedsUpdateOfHomeIndicatorAutoHidden];
    4.16 +            [viewcontroller setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
    4.17 +        }
    4.18 +    }
    4.19 +}
    4.20 +#endif
    4.21 +
    4.22  @implementation SDL_uikitviewcontroller {
    4.23      CADisplayLink *displayLink;
    4.24      int animationInterval;
    4.25 @@ -79,7 +94,13 @@
    4.26                              SDL_AppleTVControllerUIHintChanged,
    4.27                              (__bridge void *) self);
    4.28  #endif
    4.29 +
    4.30 +#if !TARGET_OS_TV
    4.31 +        SDL_AddHintCallback(SDL_HINT_IOS_HIDE_HOME_INDICATOR,
    4.32 +                            SDL_HideHomeIndicatorHintChanged,
    4.33 +                            (__bridge void *) self);
    4.34      }
    4.35 +#endif
    4.36      return self;
    4.37  }
    4.38  
    4.39 @@ -94,6 +115,12 @@
    4.40                          SDL_AppleTVControllerUIHintChanged,
    4.41                          (__bridge void *) self);
    4.42  #endif
    4.43 +
    4.44 +#if !TARGET_OS_TV
    4.45 +    SDL_DelHintCallback(SDL_HINT_IOS_HIDE_HOME_INDICATOR,
    4.46 +                        SDL_HideHomeIndicatorHintChanged,
    4.47 +                        (__bridge void *) self);
    4.48 +#endif
    4.49  }
    4.50  
    4.51  - (void)setAnimationCallback:(int)interval
    4.52 @@ -179,7 +206,35 @@
    4.53  
    4.54  - (BOOL)prefersStatusBarHidden
    4.55  {
    4.56 -    return (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) != 0;
    4.57 +    BOOL hidden = (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) != 0;
    4.58 +    return hidden;
    4.59 +}
    4.60 +
    4.61 +- (BOOL)prefersHomeIndicatorAutoHidden
    4.62 +{
    4.63 +    BOOL hidden = NO;
    4.64 +    if (self.homeIndicatorHidden == 1) {
    4.65 +        hidden = YES;
    4.66 +    }
    4.67 +    return hidden;
    4.68 +}
    4.69 +
    4.70 +- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
    4.71 +{
    4.72 +    if (self.homeIndicatorHidden >= 0) {
    4.73 +        if (self.homeIndicatorHidden == 2) {
    4.74 +            return UIRectEdgeAll;
    4.75 +        } else {
    4.76 +            return UIRectEdgeNone;
    4.77 +        }
    4.78 +    }
    4.79 +
    4.80 +    /* By default, fullscreen and borderless windows get all screen gestures */
    4.81 +    if ((window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) != 0) {
    4.82 +        return UIRectEdgeAll;
    4.83 +    } else {
    4.84 +        return UIRectEdgeNone;
    4.85 +    }
    4.86  }
    4.87  #endif
    4.88