From 9a8304f6a7ca9d5307b6f50dfb570ac64ae5ab26 Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Mon, 8 Jul 2024 20:41:59 +0700 Subject: [PATCH] Fix status bar for the external display --- SpringBoard.h | 4 ++++ TweakSB.x | 64 ++++++++++++++++++++++++++++++++++++++++++++++++-- TweakUI.x | 9 +------ UIKitPrivate.h | 26 ++++++++++++++++++++ 4 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 UIKitPrivate.h diff --git a/SpringBoard.h b/SpringBoard.h index db8f6ca..e27ef9c 100644 --- a/SpringBoard.h +++ b/SpringBoard.h @@ -15,3 +15,7 @@ @interface SBExternalDisplayRuntimeAvailabilitySettings : NSObject @property(nonatomic, assign) BOOL requirePointer, requireHardwareKeyboard; @end + +@interface SBWindowScene : UIWindowScene +- (BOOL)isExternalDisplayWindowScene; +@end diff --git a/TweakSB.x b/TweakSB.x index b3b4d42..4330ffc 100644 --- a/TweakSB.x +++ b/TweakSB.x @@ -1,8 +1,8 @@ #import -#import #import #import "SpringBoard.h" #import "TPPrefsObserver.h" +#import "UIKitPrivate.h" #include #include @@ -68,6 +68,16 @@ static uint16_t forcePadIdiom = 0; } %end +%hook UITraitCollection +- (UIUserInterfaceIdiom)userInterfaceIdiom { + if (forcePadIdiom > 0) { + return UIUserInterfaceIdiomPad; + } else { + return %orig; + } +} +%end + /* %hook SBFloatingDockView - (CGFloat)contentHeightForBounds:(CGRect)frame { @@ -81,6 +91,40 @@ static uint16_t forcePadIdiom = 0; %end */ +// Fix status bar for the external display +%hook _UIStatusBar +- (void)_prepareVisualProviderIfNeeded { + UIScreen *screen = self._effectiveTargetScreen; + if (forcePadIdiom || screen != UIScreen.mainScreen) { + // For performance reason, we're gonna overwrite userInterfaceIdiom directly + // userInterfaceIdiom: ldr x0, [x0, #0x8] + uint64_t *collection = (uint64_t *)(__bridge void *)screen.traitCollection; + if (collection) { + collection[1] = UIUserInterfaceIdiomPad; + } + } + %orig; +} +%end +%hook UIStatusBarWindow +- (void)setStatusBar:(UIStatusBar *)statusBar { + if (self.windowScene.screen._isExternal) { + statusBar.statusBar.targetScreen = self.windowScene.screen; + } + %orig; +} +%end + +/* +%hook SBSystemShellExtendedDisplayControllerPolicy +-(void)displayController:(id)arg1 didBeginTransaction:(id)arg2 sceneManager:(id)arg3 displayConfiguration:(id)arg4 deactivationReasons:(unsigned long long)arg5 { + forcePadIdiom++; + %orig; + forcePadIdiom--; +} +%end +*/ + // Enable Medusa multitasking (three-dots) button on top %hook SBFullScreenSwitcherLiveContentOverlayCoordinator -(void)layoutStateTransitionCoordinator:(id)arg1 transitionDidBeginWithTransitionContext:(id)arg2 { @@ -89,6 +133,15 @@ static uint16_t forcePadIdiom = 0; forcePadIdiom--; } %end +/* +%hook SBShelfLiveContentOverlayCoordinator +-(void)layoutStateTransitionCoordinator:(id)arg1 transitionDidBeginWithTransitionContext:(id)arg2 { + forcePadIdiom++; + %orig; + forcePadIdiom--; +} +%end +*/ // Fix iOS 16 multitasking (split screen, slide over, stage manager) %hook SBMainSwitcherControllerCoordinator @@ -171,11 +224,18 @@ static uint16_t forcePadIdiom = 0; } %end -// Use iPadOS app switching animation instead %hook SBFluidSwitcherViewController +// Use iPadOS app switching animation instead - (BOOL)isDevicePad { return pref.useiPadAppSwitchingAnimation; } + +// Restore number of grid to 1 +/* +- (NSUInteger)numberOfRowsInGridSwitcher { + return 1; +} +*/ %end // Fix truncated app name in app switcher diff --git a/TweakUI.x b/TweakUI.x index 4fd3644..1d540b3 100644 --- a/TweakUI.x +++ b/TweakUI.x @@ -1,15 +1,8 @@ -#import +#import "UIKitPrivate.h" #import static BOOL forcePadKBIdiom = YES, showShortcutButtonsOnKeyboard; -@interface UIDevice(private) -+ (BOOL)_hasHomeButton; -@end -@interface UIKeyboardImpl : NSObject -+ (BOOL)isFloating; -@end - // Unlock iPadOS keyboard UIUserInterfaceIdiom UIKeyboardGetSafeDeviceIdiom(); %hookf(UIUserInterfaceIdiom, UIKeyboardGetSafeDeviceIdiom) { diff --git a/UIKitPrivate.h b/UIKitPrivate.h new file mode 100644 index 0000000..9a16048 --- /dev/null +++ b/UIKitPrivate.h @@ -0,0 +1,26 @@ +#import + +@interface UIDevice(private) ++ (BOOL)_hasHomeButton; +@end +@interface UIKeyboardImpl : NSObject ++ (BOOL)isFloating; +@end + +@interface UIScreen(private) +- (BOOL)isUserInterfaceIdiomPad; +- (BOOL)_isExternal; +- (void)_setUserInterfaceIdiom:(UIUserInterfaceIdiom)idiom; +@end + +@interface UIStatusBarWindow : UIWindow +@end + +@interface _UIStatusBar +- (void)setTargetScreen:(UIScreen *)screen; +- (UIScreen *)_effectiveTargetScreen; +@end + +@interface UIStatusBar +- (_UIStatusBar *)statusBar; +@end