Skip to content

Commit

Permalink
Fix status bar for the external display
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Jul 8, 2024
1 parent 575548a commit 9a8304f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 10 deletions.
4 changes: 4 additions & 0 deletions SpringBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
@interface SBExternalDisplayRuntimeAvailabilitySettings : NSObject
@property(nonatomic, assign) BOOL requirePointer, requireHardwareKeyboard;
@end

@interface SBWindowScene : UIWindowScene
- (BOOL)isExternalDisplayWindowScene;
@end
64 changes: 62 additions & 2 deletions TweakSB.x
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import "SpringBoard.h"
#import "TPPrefsObserver.h"
#import "UIKitPrivate.h"

#include <assert.h>
#include <dlfcn.h>
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions TweakUI.x
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#import <UIKit/UIKit.h>
#import "UIKitPrivate.h"
#import <rootless.h>

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) {
Expand Down
26 changes: 26 additions & 0 deletions UIKitPrivate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#import <UIKit/UIKit.h>

@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

0 comments on commit 9a8304f

Please sign in to comment.