mirror of https://github.com/encounter/SDL.git
Workaround for views being in portrait instead of landscape mode on iOS 16
Fixes https://github.com/libsdl-org/SDL/issues/6289
This commit is contained in:
parent
9f784b1887
commit
a40b7cde10
|
@ -69,6 +69,18 @@
|
|||
CGSize size = self.bounds.size;
|
||||
size.width *= self.layer.contentsScale;
|
||||
size.height *= self.layer.contentsScale;
|
||||
|
||||
/* Make sure the width/height are oriented correctly
|
||||
*
|
||||
* This works around an issue in iOS 16 where the bounds come back in portrait mode
|
||||
* instead of landscape until the event loop runs.
|
||||
*/
|
||||
if ([self shouldSwapDimensions:(size.width >= size.height)]) {
|
||||
CGFloat temp = size.width;
|
||||
size.width = size.height;
|
||||
size.height = temp;
|
||||
}
|
||||
|
||||
((CAMetalLayer *)self.layer).drawableSize = size;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
|
||||
- (void)setSDLWindow:(SDL_Window *)window;
|
||||
|
||||
- (BOOL)shouldSwapDimensions:(BOOL)portrait;
|
||||
|
||||
#if !TARGET_OS_TV && defined(__IPHONE_13_4)
|
||||
- (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4));
|
||||
- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4));
|
||||
|
|
|
@ -120,6 +120,8 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
[data.uiwindow layoutIfNeeded];
|
||||
}
|
||||
|
||||
sdlwindow = window;
|
||||
|
||||
/* Add ourself to the new window. */
|
||||
if (window) {
|
||||
data = (__bridge SDL_WindowData *) window->driverdata;
|
||||
|
@ -144,8 +146,29 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
|||
* layout now to immediately update the bounds. */
|
||||
[data.uiwindow layoutIfNeeded];
|
||||
}
|
||||
}
|
||||
|
||||
sdlwindow = window;
|
||||
- (BOOL)shouldSwapDimensions:(BOOL)landscape
|
||||
{
|
||||
#if !TARGET_OS_TV
|
||||
if (sdlwindow) {
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(sdlwindow);
|
||||
SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata;
|
||||
|
||||
if (displaydata.uiscreen == [UIScreen mainScreen]) {
|
||||
NSUInteger orients = UIKit_GetSupportedOrientations(sdlwindow);
|
||||
BOOL supportsLandscape = (orients & UIInterfaceOrientationMaskLandscape) != 0;
|
||||
BOOL supportsPortrait = (orients & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown)) != 0;
|
||||
|
||||
/* Make sure the width/height are oriented correctly */
|
||||
if ((landscape && !supportsLandscape) || (!landscape && !supportsPortrait)) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* !TARGET_OS_TV */
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
#if !TARGET_OS_TV && defined(__IPHONE_13_4)
|
||||
|
|
Loading…
Reference in New Issue