Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle layouts that are too large for a window (e.g., a fullscreen wi…

…ndow). Fixes bug 1719
  • Loading branch information...
commit c0ba707f8cf66c843dde659e8c4feaf71452b84c 1 parent b4e299a
George Nachman authored
View
6 PTYTab.h
@@ -247,11 +247,17 @@ static const int MIN_SESSION_COLUMNS = 2;
hSpacing:(double)hs
vSpacing:(double)vs;
+// Size we should report to fit the current layout
- (NSSize)tmuxSize;
+// Size we are given the current layout
+- (NSSize)maxTmuxSize;
+
- (int)tmuxWindow;
- (BOOL)isTmuxTab;
- (void)setTmuxLayout:(NSMutableDictionary *)parseTree
tmuxController:(TmuxController *)tmuxController;
+// Returns true if the tmux layout is too large for the window to accommodate.
+- (BOOL)layoutIsTooLarge;
- (TmuxController *)tmuxController;
#pragma mark NSSplitView delegate methods
View
24 PTYTab.m
@@ -2571,6 +2571,21 @@ - (int)tmuxSizeForHeight:(BOOL)forHeight
return [[sortedValues lastObject] intValue];
}
+// Returns the size (in characters) of the largest layout that can fit in this tab.
+- (NSSize)maxTmuxSize
+{
+ NSSize rootSize = root_.frame.size;
+ NSSize containerSize = flexibleView_.frame.size;
+ NSSize overage = NSMakeSize(MAX(0, rootSize.width - containerSize.width),
+ MAX(0, rootSize.height - containerSize.height));
+ NSSize charSize = [PTYTab cellSizeForBookmark:[PTYTab tmuxBookmark]];
+ overage.width = ceil(overage.width / charSize.width);
+ overage.height = ceil(overage.height / charSize.height);
+ NSSize tmuxSize = [self tmuxSize];
+ return NSMakeSize(tmuxSize.width - overage.width,
+ tmuxSize.height - overage.height);
+}
+
// Returns the size (in characters) of the minimum window size that can contain
// this tab. It picks the smallest height that can contain every column and
// every row (counting characters and dividers as 1).
@@ -2829,6 +2844,15 @@ - (void)setTmuxLayout:(NSMutableDictionary *)parseTree
parseTree_ = [parseTree retain];
}
+- (BOOL)layoutIsTooLarge
+{
+ if (!flexibleView_) {
+ return NO;
+ }
+ return (root_.frame.size.width > flexibleView_.frame.size.width ||
+ root_.frame.size.height > flexibleView_.frame.size.height);
+}
+
- (BOOL)hasMaximizedPane
{
return isMaximized_;
View
1  TmuxController.h
@@ -85,6 +85,7 @@ extern NSString *kTmuxControllerAttachedSessionDidChange;
// This should be called after the host sends an %exit command.
- (void)detach;
- (BOOL)windowDidResize:(PseudoTerminal *)term;
+- (void)fitLayoutToWindows;
- (void)setClientSize:(NSSize)size;
- (BOOL)hasOutstandingWindowResize;
- (void)windowPane:(int)wp
View
19 TmuxController.m
@@ -333,6 +333,25 @@ - (BOOL)windowDidResize:(PseudoTerminal *)term
return YES;
}
+- (void)fitLayoutToWindows
+{
+ NSSize minSize = NSMakeSize(INFINITY, INFINITY);
+ for (id windowKey in windows_) {
+ PTYTab *tab = [[windows_ objectForKey:windowKey] objectAtIndex:0];
+ NSSize size = [tab maxTmuxSize];
+ minSize.width = MIN(minSize.width, size.width);
+ minSize.height = MIN(minSize.height, size.height);
+ }
+ if (minSize.width == 0 || minSize.height == 0) {
+ // After the last session closes a size of 0 is reported.
+ return;
+ }
+ if (NSEqualSizes(minSize, lastSize_)) {
+ return;
+ }
+ [self setClientSize:minSize];
+}
+
- (void)setClientSize:(NSSize)size
{
lastSize_ = size;
View
6 TmuxWindowOpener.m
@@ -135,6 +135,9 @@ - (void)updateLayoutInTab:(PTYTab *)tab;
// in two windows.
[tab setTmuxLayout:self.parseTree
tmuxController:controller_];
+ if ([tab layoutIsTooLarge]) {
+ [controller_ fitLayoutToWindows];
+ }
}
}
@@ -240,6 +243,9 @@ - (void)requestDidComplete
if (tabToUpdate_) {
[tabToUpdate_ setTmuxLayout:parseTree
tmuxController:controller_];
+ if ([tabToUpdate_ layoutIsTooLarge]) {
+ [controller_ fitLayoutToWindows];
+ }
} else {
if (![self.controller window:windowIndex_]) {
// Safety valve: don't open an existing tmux window.
Please sign in to comment.
Something went wrong with that request. Please try again.