forked from Green-Sky/tomato
update sdl Merge commit '4d48f9d23713d94b861da7b5d41baf2a41334994'
This commit is contained in:
@ -79,7 +79,7 @@ int SDL_RunApp(int argc, char* argv[], SDL_main_func mainFunction, void * reserv
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
/* Load a launch image using the old UILaunchImageFile-era naming rules. */
|
||||
static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
||||
{
|
||||
@ -142,8 +142,10 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
||||
self.storyboardViewController.view.frame = self.view.bounds;
|
||||
[self.storyboardViewController didMoveToParentViewController:self];
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
UIApplication.sharedApplication.statusBarHidden = self.prefersStatusBarHidden;
|
||||
UIApplication.sharedApplication.statusBarStyle = self.preferredStatusBarStyle;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden
|
||||
@ -210,11 +212,18 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
||||
NSArray *launchimages = [bundle objectForInfoDictionaryKey:@"UILaunchImages"];
|
||||
NSString *imagename = nil;
|
||||
UIImage *image = nil;
|
||||
|
||||
|
||||
#if TARGET_OS_XR
|
||||
int screenw = SDL_XR_SCREENWIDTH;
|
||||
int screenh = SDL_XR_SCREENHEIGHT;
|
||||
#else
|
||||
int screenw = (int)([UIScreen mainScreen].bounds.size.width + 0.5);
|
||||
int screenh = (int)([UIScreen mainScreen].bounds.size.height + 0.5);
|
||||
#endif
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
|
||||
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
|
||||
|
||||
/* We always want portrait-oriented size, to match UILaunchImageSize. */
|
||||
@ -244,7 +253,7 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
||||
}
|
||||
}
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
|
||||
NSString *orientstring = dict[@"UILaunchImageOrientation"];
|
||||
|
||||
@ -273,7 +282,7 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
||||
image = [UIImage imageNamed:imagename];
|
||||
}
|
||||
}
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
else {
|
||||
imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"];
|
||||
|
||||
@ -288,10 +297,15 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
||||
#endif
|
||||
|
||||
if (image) {
|
||||
UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
||||
#if TARGET_OS_XR
|
||||
CGRect viewFrame = CGRectMake(0, 0, screenw, screenh);
|
||||
#else
|
||||
CGRect viewFrame = [UIScreen mainScreen].bounds;
|
||||
#endif
|
||||
UIImageView *view = [[UIImageView alloc] initWithFrame:viewFrame];
|
||||
UIImageOrientation imageorient = UIImageOrientationUp;
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
/* Bugs observed / workaround tested in iOS 8.3. */
|
||||
if (UIInterfaceOrientationIsLandscape(curorient)) {
|
||||
if (image.size.width < image.size.height) {
|
||||
@ -420,7 +434,7 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
||||
NSString *screenname = nil;
|
||||
|
||||
/* tvOS only uses a plain launch image. */
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
|
||||
|
||||
if (screenname) {
|
||||
@ -443,7 +457,12 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
||||
}
|
||||
|
||||
if (vc.view) {
|
||||
launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
||||
#if TARGET_OS_XR
|
||||
CGRect viewFrame = CGRectMake(0, 0, SDL_XR_SCREENWIDTH, SDL_XR_SCREENHEIGHT);
|
||||
#else
|
||||
CGRect viewFrame = [UIScreen mainScreen].bounds;
|
||||
#endif
|
||||
launchWindow = [[UIWindow alloc] initWithFrame:viewFrame];
|
||||
|
||||
/* We don't want the launch window immediately hidden when a real SDL
|
||||
* window is shown - we fade it out ourselves when we're ready. */
|
||||
|
@ -57,7 +57,7 @@ static BOOL UIKit_EventPumpEnabled = YES;
|
||||
[notificationCenter addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
|
||||
[notificationCenter addObserver:self selector:@selector(applicationWillTerminate) name:UIApplicationWillTerminateNotification object:nil];
|
||||
[notificationCenter addObserver:self selector:@selector(applicationDidReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
[notificationCenter addObserver:self
|
||||
selector:@selector(applicationDidChangeStatusBarOrientation)
|
||||
name:UIApplicationDidChangeStatusBarOrientationNotification
|
||||
@ -99,7 +99,7 @@ static BOOL UIKit_EventPumpEnabled = YES;
|
||||
SDL_OnApplicationDidReceiveMemoryWarning();
|
||||
}
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
- (void)applicationDidChangeStatusBarOrientation
|
||||
{
|
||||
SDL_OnApplicationDidChangeStatusBarOrientation();
|
||||
|
@ -98,7 +98,11 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag
|
||||
}
|
||||
|
||||
if (window == nil || window.rootViewController == nil) {
|
||||
#if TARGET_OS_XR
|
||||
alertwindow = [[UIWindow alloc] init];
|
||||
#else
|
||||
alertwindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
||||
#endif
|
||||
alertwindow.rootViewController = [UIViewController new];
|
||||
alertwindow.windowLevel = UIWindowLevelAlert;
|
||||
|
||||
|
@ -81,6 +81,7 @@ SDL_MetalView UIKit_Metal_CreateView(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
CGFloat scale = 1.0;
|
||||
SDL_uikitmetalview *metalview;
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
|
||||
/* Set the scale to the natural scale factor of the screen - then
|
||||
* the backing dimensions of the Metal view will match the pixel
|
||||
@ -89,6 +90,7 @@ SDL_MetalView UIKit_Metal_CreateView(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
*/
|
||||
scale = data.uiwindow.screen.nativeScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
metalview = [[SDL_uikitmetalview alloc] initWithFrame:data.uiwindow.bounds
|
||||
scale:scale];
|
||||
|
@ -27,26 +27,39 @@
|
||||
|
||||
@interface SDL_UIKitDisplayData : NSObject
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
- (instancetype)initWithScreen:(UIScreen *)screen;
|
||||
|
||||
@property(nonatomic, strong) UIScreen *uiscreen;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
@interface SDL_UIKitDisplayModeData : NSObject
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
@property(nonatomic, strong) UIScreenMode *uiscreenmode;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
extern SDL_bool UIKit_IsDisplayLandscape(UIScreen *uiscreen);
|
||||
#endif
|
||||
|
||||
extern int UIKit_InitModes(SDL_VideoDevice *_this);
|
||||
#if !TARGET_OS_XR
|
||||
extern int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event);
|
||||
extern void UIKit_DelDisplay(UIScreen *uiscreen);
|
||||
#endif
|
||||
extern int UIKit_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
|
||||
extern int UIKit_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
|
||||
extern void UIKit_QuitModes(SDL_VideoDevice *_this);
|
||||
extern int UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
|
||||
// because visionOS does not have a screen
|
||||
// we create a fake 1080p display to maintain compatibility.
|
||||
#if TARGET_OS_XR
|
||||
#define SDL_XR_SCREENWIDTH 1920
|
||||
#define SDL_XR_SCREENHEIGHT 1080
|
||||
#endif
|
||||
|
||||
#endif /* SDL_uikitmodes_h_ */
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
@implementation SDL_UIKitDisplayData
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
- (instancetype)initWithScreen:(UIScreen *)screen
|
||||
{
|
||||
if (self = [super init]) {
|
||||
@ -37,20 +38,23 @@
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize uiscreen;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
@implementation SDL_UIKitDisplayModeData
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
@synthesize uiscreenmode;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
@interface SDL_DisplayWatch : NSObject
|
||||
@end
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
@implementation SDL_DisplayWatch
|
||||
|
||||
+ (void)start
|
||||
@ -92,7 +96,9 @@
|
||||
}
|
||||
|
||||
@end
|
||||
#endif
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode,
|
||||
UIScreenMode *uiscreenmode)
|
||||
{
|
||||
@ -112,6 +118,7 @@ static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void UIKit_FreeDisplayModeData(SDL_DisplayMode *mode)
|
||||
{
|
||||
@ -121,6 +128,7 @@ static void UIKit_FreeDisplayModeData(SDL_DisplayMode *mode)
|
||||
}
|
||||
}
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
static float UIKit_GetDisplayModeRefreshRate(UIScreen *uiscreen)
|
||||
{
|
||||
#ifdef __IPHONE_10_3
|
||||
@ -235,7 +243,11 @@ int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
|
||||
display.desktop_mode = mode;
|
||||
|
||||
/* Allocate the display data */
|
||||
#if TARGET_OS_XR
|
||||
SDL_UIKitDisplayData *data = [[SDL_UIKitDisplayData alloc] init];
|
||||
#else
|
||||
SDL_UIKitDisplayData *data = [[SDL_UIKitDisplayData alloc] initWithScreen:uiscreen];
|
||||
#endif
|
||||
if (!data) {
|
||||
UIKit_FreeDisplayModeData(&display.desktop_mode);
|
||||
return SDL_OutOfMemory();
|
||||
@ -247,6 +259,41 @@ int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_XR
|
||||
int UIKit_AddDisplay(SDL_bool send_event){
|
||||
CGSize size = CGSizeMake(SDL_XR_SCREENWIDTH, SDL_XR_SCREENHEIGHT);
|
||||
SDL_VideoDisplay display;
|
||||
SDL_DisplayMode mode;
|
||||
|
||||
SDL_zero(mode);
|
||||
mode.w = (int)size.width;
|
||||
mode.h = (int)size.height;
|
||||
mode.pixel_density = 1;
|
||||
mode.format = SDL_PIXELFORMAT_ABGR8888;
|
||||
mode.refresh_rate = 60;
|
||||
|
||||
display.natural_orientation = SDL_ORIENTATION_LANDSCAPE;
|
||||
|
||||
display.desktop_mode = mode;
|
||||
|
||||
SDL_UIKitDisplayData *data = [[SDL_UIKitDisplayData alloc] init];
|
||||
|
||||
if (!data) {
|
||||
UIKit_FreeDisplayModeData(&display.desktop_mode);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
display.driverdata = (SDL_DisplayData *)CFBridgingRetain(data);
|
||||
if (SDL_AddVideoDisplay(&display, send_event) == 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
|
||||
void UIKit_DelDisplay(UIScreen *uiscreen)
|
||||
{
|
||||
@ -281,20 +328,27 @@ SDL_bool UIKit_IsDisplayLandscape(UIScreen *uiscreen)
|
||||
return (size.width > size.height);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
int UIKit_InitModes(SDL_VideoDevice *_this)
|
||||
{
|
||||
@autoreleasepool {
|
||||
#if TARGET_OS_XR
|
||||
UIKit_AddDisplay(SDL_FALSE);
|
||||
#else
|
||||
for (UIScreen *uiscreen in [UIScreen screens]) {
|
||||
if (UIKit_AddDisplay(uiscreen, SDL_FALSE) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#if !TARGET_OS_TV
|
||||
#endif
|
||||
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
SDL_OnApplicationDidChangeStatusBarOrientation();
|
||||
#endif
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
[SDL_DisplayWatch start];
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -302,6 +356,7 @@ int UIKit_InitModes(SDL_VideoDevice *_this)
|
||||
|
||||
int UIKit_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
|
||||
{
|
||||
#if !TARGET_OS_XR
|
||||
@autoreleasepool {
|
||||
SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->driverdata;
|
||||
|
||||
@ -331,11 +386,13 @@ int UIKit_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
|
||||
UIKit_AddDisplayMode(display, w, h, data.uiscreen, uimode, addRotation);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int UIKit_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
|
||||
{
|
||||
#if !TARGET_OS_XR
|
||||
@autoreleasepool {
|
||||
SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->driverdata;
|
||||
|
||||
@ -359,7 +416,7 @@ int UIKit_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -367,7 +424,11 @@ int UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ
|
||||
{
|
||||
@autoreleasepool {
|
||||
SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->driverdata;
|
||||
#if TARGET_OS_XR
|
||||
CGRect frame = CGRectMake(0, 0, SDL_XR_SCREENWIDTH, SDL_XR_SCREENHEIGHT);
|
||||
#else
|
||||
CGRect frame = data.uiscreen.bounds;
|
||||
#endif
|
||||
|
||||
/* the default function iterates displays to make a fake offset,
|
||||
as if all the displays were side-by-side, which is fine for iOS. */
|
||||
@ -386,13 +447,15 @@ int UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ
|
||||
|
||||
void UIKit_QuitModes(SDL_VideoDevice *_this)
|
||||
{
|
||||
#if !TARGET_OS_XR
|
||||
[SDL_DisplayWatch stop];
|
||||
#endif
|
||||
|
||||
/* Release Objective-C objects, so higher level doesn't free() them. */
|
||||
int i, j;
|
||||
@autoreleasepool {
|
||||
for (i = 0; i < _this->num_displays; i++) {
|
||||
SDL_VideoDisplay *display = &_this->displays[i];
|
||||
SDL_VideoDisplay *display = _this->displays[i];
|
||||
|
||||
UIKit_FreeDisplayModeData(&display->desktop_mode);
|
||||
for (j = 0; j < display->num_fullscreen_modes; j++) {
|
||||
@ -408,7 +471,7 @@ void UIKit_QuitModes(SDL_VideoDevice *_this)
|
||||
}
|
||||
}
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
void SDL_OnApplicationDidChangeStatusBarOrientation(void)
|
||||
{
|
||||
BOOL isLandscape = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
|
||||
|
@ -33,7 +33,11 @@
|
||||
|
||||
@end
|
||||
|
||||
#if TARGET_OS_XR
|
||||
CGRect UIKit_ComputeViewFrame(SDL_Window *window);
|
||||
#else
|
||||
CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen);
|
||||
#endif
|
||||
|
||||
#endif /* __OBJC__ */
|
||||
|
||||
|
@ -52,7 +52,9 @@ static void UIKit_VideoQuit(SDL_VideoDevice *_this);
|
||||
static void UIKit_DeleteDevice(SDL_VideoDevice *device)
|
||||
{
|
||||
@autoreleasepool {
|
||||
CFRelease(device->driverdata);
|
||||
if (device->driverdata){
|
||||
CFRelease(device->driverdata);
|
||||
}
|
||||
SDL_free(device);
|
||||
}
|
||||
}
|
||||
@ -183,6 +185,7 @@ SDL_bool UIKit_IsSystemVersionAtLeast(double version)
|
||||
|
||||
SDL_SystemTheme UIKit_GetSystemTheme(void)
|
||||
{
|
||||
#if !TARGET_OS_XR
|
||||
if (@available(iOS 12.0, tvOS 10.0, *)) {
|
||||
switch ([UIScreen mainScreen].traitCollection.userInterfaceStyle) {
|
||||
case UIUserInterfaceStyleDark:
|
||||
@ -193,9 +196,15 @@ SDL_SystemTheme UIKit_GetSystemTheme(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return SDL_SYSTEM_THEME_UNKNOWN;
|
||||
}
|
||||
|
||||
#if TARGET_OS_XR
|
||||
CGRect UIKit_ComputeViewFrame(SDL_Window *window){
|
||||
return CGRectMake(window->x, window->y, window->w, window->h);
|
||||
}
|
||||
#else
|
||||
CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
|
||||
{
|
||||
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
|
||||
@ -234,6 +243,8 @@ CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
|
||||
return frame;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void UIKit_ForceUpdateHomeIndicator(void)
|
||||
{
|
||||
#if !TARGET_OS_TV
|
||||
|
12
external/sdl/SDL/src/video/uikit/SDL_uikitview.m
vendored
12
external/sdl/SDL/src/video/uikit/SDL_uikitview.m
vendored
@ -417,6 +417,9 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
||||
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_PRESSED, scancode);
|
||||
}
|
||||
}
|
||||
if (SDL_TextInputActive()) {
|
||||
[super pressesBegan:presses withEvent:event];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
|
||||
@ -427,6 +430,9 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
||||
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_RELEASED, scancode);
|
||||
}
|
||||
}
|
||||
if (SDL_TextInputActive()) {
|
||||
[super pressesEnded:presses withEvent:event];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
|
||||
@ -437,11 +443,17 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
||||
SDL_SendKeyboardKey(UIKit_GetEventTimestamp([event timestamp]), SDL_RELEASED, scancode);
|
||||
}
|
||||
}
|
||||
if (SDL_TextInputActive()) {
|
||||
[super pressesCancelled:presses withEvent:event];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
|
||||
{
|
||||
/* This is only called when the force of a press changes. */
|
||||
if (SDL_TextInputActive()) {
|
||||
[super pressesChanged:presses withEvent:event];
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* TARGET_OS_TV || defined(__IPHONE_9_1) */
|
||||
|
@ -63,11 +63,11 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
@implementation SDLUITextField : UITextField
|
||||
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
|
||||
{
|
||||
if (action == @selector(paste:)) {
|
||||
return NO;
|
||||
}
|
||||
if (action == @selector(paste:)) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
return [super canPerformAction:action withSender:sender];
|
||||
return [super canPerformAction:action withSender:sender];
|
||||
}
|
||||
@end
|
||||
|
||||
@ -82,6 +82,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
SDLUITextField *textField;
|
||||
BOOL hardwareKeyboard;
|
||||
BOOL showingKeyboard;
|
||||
BOOL hidingKeyboard;
|
||||
BOOL rotatingOrientation;
|
||||
NSString *committedText;
|
||||
NSString *obligateForBackspace;
|
||||
@ -99,6 +100,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
[self initKeyboard];
|
||||
hardwareKeyboard = NO;
|
||||
showingKeyboard = NO;
|
||||
hidingKeyboard = NO;
|
||||
rotatingOrientation = NO;
|
||||
#endif
|
||||
|
||||
@ -160,7 +162,9 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
{
|
||||
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
|
||||
|
||||
#ifdef __IPHONE_10_3
|
||||
#if TARGET_OS_XR
|
||||
displayLink.preferredFramesPerSecond = 90 / animationInterval; //TODO: Get frame max frame rate on visionOS
|
||||
#elif defined(__IPHONE_10_3)
|
||||
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
|
||||
|
||||
if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)] && data != nil && data.uiwindow != nil && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
|
||||
@ -292,7 +296,18 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
selector:@selector(keyboardWillShow:)
|
||||
name:UIKeyboardWillShowNotification
|
||||
object:nil];
|
||||
[center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
||||
[center addObserver:self
|
||||
selector:@selector(keyboardDidShow:)
|
||||
name:UIKeyboardDidShowNotification
|
||||
object:nil];
|
||||
[center addObserver:self
|
||||
selector:@selector(keyboardWillHide:)
|
||||
name:UIKeyboardWillHideNotification
|
||||
object:nil];
|
||||
[center addObserver:self
|
||||
selector:@selector(keyboardDidHide:)
|
||||
name:UIKeyboardDidHideNotification
|
||||
object:nil];
|
||||
#endif
|
||||
[center addObserver:self
|
||||
selector:@selector(textFieldTextDidChange:)
|
||||
@ -363,7 +378,15 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
[center removeObserver:self
|
||||
name:UIKeyboardWillShowNotification
|
||||
object:nil];
|
||||
[center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
|
||||
[center removeObserver:self
|
||||
name:UIKeyboardDidShowNotification
|
||||
object:nil];
|
||||
[center removeObserver:self
|
||||
name:UIKeyboardWillHideNotification
|
||||
object:nil];
|
||||
[center removeObserver:self
|
||||
name:UIKeyboardDidHideNotification
|
||||
object:nil];
|
||||
#endif
|
||||
[center removeObserver:self
|
||||
name:UITextFieldTextDidChangeNotification
|
||||
@ -373,23 +396,40 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
/* reveal onscreen virtual keyboard */
|
||||
- (void)showKeyboard
|
||||
{
|
||||
if (keyboardVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
keyboardVisible = YES;
|
||||
if (textField.window) {
|
||||
showingKeyboard = YES;
|
||||
[textField becomeFirstResponder];
|
||||
showingKeyboard = NO;
|
||||
}
|
||||
}
|
||||
|
||||
/* hide onscreen virtual keyboard */
|
||||
- (void)hideKeyboard
|
||||
{
|
||||
if (!keyboardVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
keyboardVisible = NO;
|
||||
[textField resignFirstResponder];
|
||||
if (textField.window) {
|
||||
hidingKeyboard = YES;
|
||||
[textField resignFirstResponder];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)keyboardWillShow:(NSNotification *)notification
|
||||
{
|
||||
BOOL shouldStartTextInput = NO;
|
||||
|
||||
if (!SDL_TextInputActive() && !hidingKeyboard && !rotatingOrientation) {
|
||||
shouldStartTextInput = YES;
|
||||
}
|
||||
|
||||
showingKeyboard = YES;
|
||||
#if !TARGET_OS_TV
|
||||
CGRect kbrect = [[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
||||
|
||||
@ -399,14 +439,36 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
|
||||
[self setKeyboardHeight:(int)kbrect.size.height];
|
||||
#endif
|
||||
|
||||
if (shouldStartTextInput) {
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
}
|
||||
|
||||
- (void)keyboardDidShow:(NSNotification *)notification
|
||||
{
|
||||
showingKeyboard = NO;
|
||||
}
|
||||
|
||||
- (void)keyboardWillHide:(NSNotification *)notification
|
||||
{
|
||||
if (!showingKeyboard && !rotatingOrientation) {
|
||||
BOOL shouldStopTextInput = NO;
|
||||
|
||||
if (SDL_TextInputActive() && !showingKeyboard && !rotatingOrientation) {
|
||||
shouldStopTextInput = YES;
|
||||
}
|
||||
|
||||
hidingKeyboard = YES;
|
||||
[self setKeyboardHeight:0];
|
||||
|
||||
if (shouldStopTextInput) {
|
||||
SDL_StopTextInput();
|
||||
}
|
||||
[self setKeyboardHeight:0];
|
||||
}
|
||||
|
||||
- (void)keyboardDidHide:(NSNotification *)notification
|
||||
{
|
||||
hidingKeyboard = NO;
|
||||
}
|
||||
|
||||
- (void)textFieldTextDidChange:(NSNotification *)notification
|
||||
@ -425,8 +487,8 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
size_t deleteLength = SDL_utf8strlen([[committedText substringFromIndex:matchLength] UTF8String]);
|
||||
while (deleteLength > 0) {
|
||||
/* Send distinct down and up events for each backspace action */
|
||||
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
|
||||
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
|
||||
SDL_SendVirtualKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
|
||||
SDL_SendVirtualKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
|
||||
--deleteLength;
|
||||
}
|
||||
}
|
||||
@ -451,7 +513,11 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
|
||||
{
|
||||
CGAffineTransform t = self.view.transform;
|
||||
CGPoint offset = CGPointMake(0.0, 0.0);
|
||||
#if TARGET_OS_XR
|
||||
CGRect frame = UIKit_ComputeViewFrame(window);
|
||||
#else
|
||||
CGRect frame = UIKit_ComputeViewFrame(window, self.view.window.screen);
|
||||
#endif
|
||||
|
||||
if (self.keyboardHeight) {
|
||||
int rectbottom = self.textInputRect.y + self.textInputRect.h;
|
||||
|
@ -65,6 +65,7 @@
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
#if !TARGET_OS_XR
|
||||
/* Workaround to fix window orientation issues in iOS 8. */
|
||||
/* As of July 1 2019, I haven't been able to reproduce any orientation
|
||||
* issues with this disabled on iOS 12. The issue this is meant to fix might
|
||||
@ -74,6 +75,7 @@
|
||||
if (!UIKit_IsSystemVersionAtLeast(9.0)) {
|
||||
self.frame = self.screen.bounds;
|
||||
}
|
||||
#endif
|
||||
[super layoutSubviews];
|
||||
}
|
||||
|
||||
@ -84,8 +86,13 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, UIWindow
|
||||
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
|
||||
SDL_UIKitDisplayData *displaydata = (__bridge SDL_UIKitDisplayData *)display->driverdata;
|
||||
SDL_uikitview *view;
|
||||
|
||||
|
||||
#if TARGET_OS_XR
|
||||
CGRect frame = UIKit_ComputeViewFrame(window);
|
||||
#else
|
||||
CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen);
|
||||
#endif
|
||||
|
||||
int width = (int)frame.size.width;
|
||||
int height = (int)frame.size.height;
|
||||
|
||||
@ -98,13 +105,15 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, UIWindow
|
||||
|
||||
data.uiwindow = uiwindow;
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
if (displaydata.uiscreen != [UIScreen mainScreen]) {
|
||||
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizable */
|
||||
window->flags &= ~SDL_WINDOW_INPUT_FOCUS; /* never has input focus */
|
||||
window->flags |= SDL_WINDOW_BORDERLESS; /* never has a status bar. */
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
if (displaydata.uiscreen == [UIScreen mainScreen]) {
|
||||
/* SDL_CreateWindow sets the window w&h to the display's bounds if the
|
||||
* fullscreen flag is set. But the display bounds orientation might not
|
||||
@ -166,7 +175,7 @@ int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
/* If monitor has a resolution of 0x0 (hasn't been explicitly set by the
|
||||
* user, so it's in standby), try to force the display to a resolution
|
||||
* that most closely matches the desired window size. */
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
const CGSize origsize = data.uiscreen.currentMode.size;
|
||||
if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
|
||||
const SDL_DisplayMode *bestmode;
|
||||
@ -197,12 +206,18 @@ int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
|
||||
/* ignore the size user requested, and make a fullscreen window */
|
||||
/* !!! FIXME: can we have a smaller view? */
|
||||
#if TARGET_OS_XR
|
||||
UIWindow *uiwindow = [[SDL_uikitwindow alloc] initWithFrame:CGRectMake(window->x, window->y, window->w, window->h)];
|
||||
#else
|
||||
UIWindow *uiwindow = [[SDL_uikitwindow alloc] initWithFrame:data.uiscreen.bounds];
|
||||
#endif
|
||||
|
||||
/* put the window on an external display if appropriate. */
|
||||
#if !TARGET_OS_XR
|
||||
if (data.uiscreen != [UIScreen mainScreen]) {
|
||||
[uiwindow setScreen:data.uiscreen];
|
||||
}
|
||||
#endif
|
||||
|
||||
if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
|
||||
return -1;
|
||||
@ -229,7 +244,10 @@ void UIKit_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
/* Make this window the current mouse focus for touch input */
|
||||
SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window);
|
||||
SDL_UIKitDisplayData *displaydata = (__bridge SDL_UIKitDisplayData *)display->driverdata;
|
||||
if (displaydata.uiscreen == [UIScreen mainScreen]) {
|
||||
#if !TARGET_OS_XR
|
||||
if (displaydata.uiscreen == [UIScreen mainScreen])
|
||||
#endif
|
||||
{
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_SetKeyboardFocus(window);
|
||||
}
|
||||
@ -258,7 +276,7 @@ static void UIKit_UpdateWindowBorder(SDL_VideoDevice *_this, SDL_Window *window)
|
||||
SDL_UIKitWindowData *data = (__bridge SDL_UIKitWindowData *)window->driverdata;
|
||||
SDL_uikitviewcontroller *viewcontroller = data.viewcontroller;
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
#if !TARGET_OS_TV && !TARGET_OS_XR
|
||||
if (data.uiwindow.screen == [UIScreen mainScreen]) {
|
||||
if (window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS)) {
|
||||
[UIApplication sharedApplication].statusBarHidden = YES;
|
||||
@ -354,9 +372,11 @@ void UIKit_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int
|
||||
CGSize size = view.bounds.size;
|
||||
CGFloat scale = 1.0;
|
||||
|
||||
#if !TARGET_OS_XR
|
||||
if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
|
||||
scale = windata.uiwindow.screen.nativeScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Integer truncation of fractional values matches SDL_uikitmetalview and
|
||||
* SDL_uikitopenglview. */
|
||||
|
Reference in New Issue
Block a user