Skip to content

Commit

Permalink
implement "auto" dock alignment mode
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanArbuckle committed Jan 24, 2021
1 parent 796fcd6 commit c75722e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/CRCarplayWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ id getCarplayCADisplay(void);
@property (nonatomic, retain) id appViewController;
@property (nonatomic, retain) id sceneMonitor;
@property (nonatomic, retain) id application;
@property (nonatomic, retain) id sessionStatus;
@property (nonatomic, retain) NSMutableArray *observers;

@property (nonatomic) int orientation;
Expand Down
31 changes: 28 additions & 3 deletions src/CRCarplayWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ - (id)initWithBundleIdentifier:(id)identifier
// Start in landscape
self.orientation = 3;

self.sessionStatus = objcInvoke([objc_getClass("CARSessionStatus") alloc], @"initForCarPlayShell");

self.application = objcInvoke_1(objcInvoke(objc_getClass("SBApplicationController"), @"sharedInstance"), @"applicationWithBundleIdentifier:", identifier);
assertGotExpectedObject(self.application, @"SBApplication");

Expand Down Expand Up @@ -145,7 +147,7 @@ - (void)setupDock
}

CGRect rootWindowFrame = [[self rootWindow] frame];
BOOL rightHandDock = [[CRPreferences sharedInstance] dockAlignment] == CRDockAlignmentRight;
BOOL rightHandDock = [self shouldUseRightHandDock];

CGFloat dockXOrigin = (rightHandDock) ? rootWindowFrame.size.width - CARPLAY_DOCK_WIDTH : 0;
self.dockView = [[UIView alloc] initWithFrame:CGRectMake(dockXOrigin, rootWindowFrame.origin.y, CARPLAY_DOCK_WIDTH, rootWindowFrame.size.height)];
Expand Down Expand Up @@ -554,17 +556,40 @@ - (void)resizeAppViewForOrientation:(int)desiredOrientation fullscreen:(BOOL)ful
[hostingContentView setTransform:CGAffineTransformMakeScale(widthScale, heightScale)];
[[self.appViewController view] setFrame:CGRectMake(xOrigin, [[self.appViewController view] frame].origin.y, carplayDisplaySize.width, carplayDisplaySize.height)];

BOOL rightHandDock = [[CRPreferences sharedInstance] dockAlignment] == CRDockAlignmentRight;
BOOL rightHandDock = [self shouldUseRightHandDock];
UIView *containingView = [self appContainerView];
CGRect containingViewFrame = [containingView frame];
containingViewFrame.origin.x = (rightHandDock) ? 0 : dockWidth;
[containingView setFrame:containingViewFrame];

[self.dockView setAlpha: (fullscreen) ? 0: 1];
[self.dockView setAlpha: (fullscreen) ? 0 : 1];

// Update last known orientation and fullscreen status
self.orientation = desiredOrientation;
self.isFullscreen = fullscreen;
}

- (BOOL)shouldUseRightHandDock
{
switch ([[CRPreferences sharedInstance] dockAlignment])
{
case CRDockAlignmentLeft:
return NO;
case CRDockAlignmentRight:
return YES;
case CRDockAlignmentAuto:
{
id carplaySession = objcInvoke(self.sessionStatus, @"session");
id usesRightHand = objcInvoke_1(carplaySession, @"_endpointValueForKey:", @"RightHandDrive");
return [usesRightHand boolValue];
}
default:
{
break;
}
}

return NO;
}

@end

0 comments on commit c75722e

Please sign in to comment.