Skip to content

Commit 887cc06

Browse files
committed
uikit screen orientation: Use UIWindowSceneGeometry.interfaceOrientation over deprecated [UIApplication sharedApplication].statusBarOrientation.
statusBarOrientation function does not report the correct value for iPhone Duo.
1 parent 97ee0c5 commit 887cc06

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎src/video/uikit/SDL_uikitappdelegate.m‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void *reserve
6767
// Load a launch image using the old UILaunchImageFile-era naming rules.
6868
static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh)
6969
{
70-
UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
70+
UIInterfaceOrientation curorient = UIKit_GetInterfaceOrientation();
7171
UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
7272
UIImage *image = nil;
7373

@@ -207,7 +207,7 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB
207207

208208

209209
#if !defined(SDL_PLATFORM_TVOS) && !defined(SDL_PLATFORM_VISIONOS)
210-
UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
210+
UIInterfaceOrientation curorient = UIKit_GetInterfaceOrientation();
211211

212212
// We always want portrait-oriented size, to match UILaunchImageSize.
213213
if (screenw > screenh) {

‎src/video/uikit/SDL_uikitmodes.m‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ bool UIKit_IsDisplayLandscape(UIScreen *uiscreen)
330330
{
331331
#ifndef SDL_PLATFORM_TVOS
332332
if (uiscreen == [UIScreen mainScreen]) {
333-
return UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
333+
return UIInterfaceOrientationIsLandscape(UIKit_GetInterfaceOrientation());
334334
} else
335335
#endif // !SDL_PLATFORM_TVOS
336336
{
@@ -484,7 +484,7 @@ void UIKit_QuitModes(SDL_VideoDevice *_this)
484484
#if !defined(SDL_PLATFORM_TVOS) && !defined(SDL_PLATFORM_VISIONOS)
485485
void SDL_OnApplicationDidChangeStatusBarOrientation(void)
486486
{
487-
BOOL isLandscape = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
487+
BOOL isLandscape = UIInterfaceOrientationIsLandscape(UIKit_GetInterfaceOrientation());
488488
SDL_VideoDisplay *display = SDL_GetVideoDisplay(SDL_GetPrimaryDisplay());
489489

490490
if (display) {
@@ -518,7 +518,7 @@ void SDL_OnApplicationDidChangeStatusBarOrientation(void)
518518
}
519519
}
520520

521-
switch ([UIApplication sharedApplication].statusBarOrientation) {
521+
switch (UIKit_GetInterfaceOrientation()) {
522522
case UIInterfaceOrientationPortrait:
523523
orientation = SDL_ORIENTATION_PORTRAIT;
524524
break;

‎src/video/uikit/SDL_uikitvideo.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ extern CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen);
4343

4444
extern API_AVAILABLE(ios(13.0)) UIWindowScene *UIKit_GetActiveWindowScene(void);
4545

46+
#if !defined(SDL_PLATFORM_TVOS) && !defined(SDL_PLATFORM_VISIONOS)
47+
extern UIInterfaceOrientation UIKit_GetInterfaceOrientation(void);
48+
#endif
49+
4650
extern void UIKit_SetGameControllerInteraction(bool enabled);
4751
extern void UIKit_SetViewGameControllerInteraction(UIView *view, bool enabled);
4852

‎src/video/uikit/SDL_uikitvideo.m‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
237237
* https://bugzilla.libsdl.org/show_bug.cgi?id=3505
238238
* https://bugzilla.libsdl.org/show_bug.cgi?id=3465
239239
* https://forums.developer.apple.com/thread/65337 */
240-
UIInterfaceOrientation orient = [UIApplication sharedApplication].statusBarOrientation;
240+
UIInterfaceOrientation orient = UIKit_GetInterfaceOrientation();
241+
if (@available(iOS 16.0, *)) {
242+
UIWindowScene *windowScene = data.uiwindow.windowScene;
243+
if (windowScene) {
244+
orient = windowScene.effectiveGeometry.interfaceOrientation;
245+
}
246+
}
241247
BOOL landscape = UIInterfaceOrientationIsLandscape(orient) ||
242248
!(UIKit_GetSupportedOrientations(window) & (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown));
243249
BOOL fullscreen = CGRectEqualToRect(screen.bounds, frame);
@@ -291,6 +297,20 @@ CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
291297
return nil;
292298
}
293299

300+
#if !defined(SDL_PLATFORM_TVOS) && !defined(SDL_PLATFORM_VISIONOS)
301+
UIInterfaceOrientation UIKit_GetInterfaceOrientation(void)
302+
{
303+
if (@available(iOS 16.0, *)) {
304+
UIWindowScene *windowScene = UIKit_GetActiveWindowScene();
305+
if (windowScene) {
306+
return windowScene.effectiveGeometry.interfaceOrientation;
307+
}
308+
}
309+
310+
return [UIApplication sharedApplication].statusBarOrientation;
311+
}
312+
#endif
313+
294314
void UIKit_SetGameControllerInteraction(bool enabled)
295315
{
296316
if (@available(iOS 13.0, tvOS 13.0, *)) {

0 commit comments

Comments
 (0)