Created
April 30, 2012 18:02
-
-
Save gnachman/2560519 to your computer and use it in GitHub Desktop.
Extra debugging for iTerm2's fitWindowToTabSize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)fitWindowToTabSize:(NSSize)tabSize | |
{ | |
PtyLog(@"fitWindowToTabSize %@", [NSValue valueWithSize:tabSize]); | |
if ([self anyFullScreen]) { | |
[self fitTabsToWindow]; | |
return NO; | |
} | |
// Set the window size to be large enough to encompass that tab plus its decorations. | |
NSSize decorationSize = [self windowDecorationSize]; | |
NSSize winSize = tabSize; | |
PtyLog(@"initial winSize=%@", [NSValue valueWithSize:winSize]); | |
winSize.width += decorationSize.width; | |
winSize.height += decorationSize.height; | |
PtyLog(@"winSize including decorations=%@", [NSValue valueWithSize:winSize]); | |
NSRect frame = [[self window] frame]; | |
PtyLog(@"window frame=%@", [NSValue valueWithRect:frame]); | |
BOOL mustResizeTabs = NO; | |
NSSize maxFrameSize = [self maxFrame].size; | |
PtyLog(@"maxFrameSize=%@, screens=%@", [NSValue valueWithSize:maxFrameSize], [NSScreen screens]); | |
if (maxFrameSize.width <= 0 || maxFrameSize.height <= 0) { | |
// This can happen when scrollers are changing while no monitors are | |
// attached (e.g., plug in mouse+keyboard and external display into | |
// clamshell simultaneously) | |
NSLog(@"* max frame size was not positive; aborting fitWindowToTabSize"); | |
return NO; | |
} | |
if (winSize.width > maxFrameSize.width || | |
winSize.height > maxFrameSize.height) { | |
mustResizeTabs = YES; | |
} | |
winSize.width = MIN(winSize.width, maxFrameSize.width); | |
winSize.height = MIN(winSize.height, maxFrameSize.height); | |
PtyLog(@"winSize constrainted to maxFrameSize=%@", [NSValue valueWithSize:winSize]); | |
CGFloat heightChange = winSize.height - [[self window] frame].size.height; | |
frame.size = winSize; | |
PtyLog(@"Assign winSize to frame. Frame is now %@", [NSValue valueWithRect:frame]); | |
frame.origin.y -= heightChange; | |
[[[self window] contentView] setAutoresizesSubviews:NO]; | |
if (windowType_ == WINDOW_TYPE_TOP || windowType_ == WINDOW_TYPE_BOTTOM) { | |
PtyLog(@"is a top or bottom window"); | |
frame.size.width = [[self window] frame].size.width; | |
frame.origin.x = [[self window] frame].origin.x; | |
} | |
// Set the origin again to the bottom of screen | |
if (windowType_ == WINDOW_TYPE_BOTTOM) { | |
frame.origin.y = self.screen.visibleFrame.origin.y; | |
} | |
BOOL didResize = NSEqualRects([[self window] frame], frame); | |
PtyLog(@"set window frame to %@", [NSValue valueWithRect:frame]); | |
[[self window] setFrame:frame display:YES]; | |
[[[self window] contentView] setAutoresizesSubviews:YES]; | |
[self fitBottomBarToWindow]; | |
PtyLog(@"fitWindowToTabs - refresh textview"); | |
for (PTYSession* session in [[self currentTab] sessions]) { | |
[[session TEXTVIEW] setNeedsDisplay:YES]; | |
} | |
PtyLog(@"fitWindowToTabs - update tab bar"); | |
[tabBarControl update]; | |
PtyLog(@"fitWindowToTabs - return."); | |
if (mustResizeTabs) { | |
[self fitTabsToWindow]; | |
} | |
return didResize; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment