Skip to content

Commit ea3fea8

Browse files
committed
Various fixes for pinned tabs
1 parent ed3f5b0 commit ea3fea8

File tree

5 files changed

+94
-76
lines changed

5 files changed

+94
-76
lines changed

ThirdParty/PSMTabBarControl/source/PSMTabBarControl.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,6 @@ - (void)reallyUpdate:(BOOL)animate {
11831183
NSMutableArray *newOrigins = [NSMutableArray arrayWithCapacity:cellCount];
11841184

11851185
for (int i = 0; i < cellCount; ++i) {
1186-
PSMTabBarCell *cell = [_cells objectAtIndex:i];
11871186
if (currentOrigin + cellRect.size.height <= [self frame].size.height) {
11881187
[newOrigins addObject:[NSNumber numberWithFloat:currentOrigin]];
11891188
currentOrigin += cellRect.size.height;
@@ -1215,10 +1214,12 @@ - (NSUInteger)numberOfPinnedCells {
12151214
}
12161215

12171216
- (CGFloat)totalPinnedSpaceForPinnedCount:(NSUInteger)pinnedCount unpinnedCount:(NSUInteger)unpinnedCount {
1218-
if (pinnedCount == 0) return 0;
1219-
CGFloat spacing = _style.intercellSpacing;
1217+
if (pinnedCount == 0) {
1218+
return 0;
1219+
}
1220+
const CGFloat spacing = _style.intercellSpacing;
12201221
// Width of pinned tabs themselves
1221-
CGFloat pinnedWidth = pinnedCount * _pinnedTabWidth;
1222+
const CGFloat pinnedWidth = pinnedCount * _pinnedTabWidth;
12221223
// Spacing between pinned tabs
12231224
CGFloat pinnedSpacing = (pinnedCount - 1) * spacing;
12241225
// Spacing between pinned and unpinned groups
@@ -1280,7 +1281,7 @@ - (BOOL)shouldUseOptimalWidthWithOverflow:(BOOL)withOverflow {
12801281
}
12811282

12821283
if (pinnedCount == 0) {
1283-
// No pinned cells - use the original algorithm.
1284+
// No pinned cells
12841285
NSMutableArray<NSNumber *> *newWidths = [NSMutableArray array];
12851286
if ([self shouldUseOptimalWidthWithOverflow:withOverflow]) {
12861287
for (int i = 0; i < cellCount; i++) {
@@ -1627,7 +1628,7 @@ - (NSMenu *)_setupCells:(NSArray *)newValues {
16271628
}
16281629

16291630
if ([cell hasIcon]) {
1630-
[menuItem setImage:[(id)[[cell representedObject] identifier] icon]];
1631+
[menuItem setImage:(NSImage *)[(id)[[cell representedObject] identifier] icon]];
16311632
}
16321633

16331634
if ([cell count] > 0) {

ThirdParty/PSMTabBarControl/source/PSMTabDragAssistant.m

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,21 +582,29 @@ - (void)reallyPerformDragOperation:(id<NSDraggingInfo>)sender {
582582
int theIndex;
583583
NSArray *cells = [[self sourceTabBar] cells];
584584

585-
//find the index of where the dragged cell was just dropped
586-
for (theIndex = 0; theIndex < [cells count] && [cells objectAtIndex:theIndex] != [self draggedCell]; theIndex++);
585+
// Find the index of where the dragged cell was just dropped
586+
for (theIndex = 0; theIndex < [cells count] && cells[theIndex] != [self draggedCell]; theIndex++) {
587+
;
588+
}
587589

588590
// Enforce pinned/unpinned boundary (placeholders are already removed here).
589591
{
590592
int pinnedCount = 0;
591593
for (PSMTabBarCell *c in cells) {
592-
if (c.isPinned) pinnedCount++;
594+
if (c.isPinned) {
595+
pinnedCount++;
596+
}
593597
}
594598
if (pinnedCount > 0 && pinnedCount < (int)[cells count]) {
595599
int clampedIndex = theIndex;
596600
if ([[self draggedCell] isPinned]) {
597-
if (clampedIndex >= pinnedCount) clampedIndex = pinnedCount - 1;
601+
if (clampedIndex >= pinnedCount) {
602+
clampedIndex = pinnedCount - 1;
603+
}
598604
} else {
599-
if (clampedIndex < pinnedCount) clampedIndex = pinnedCount;
605+
if (clampedIndex < pinnedCount) {
606+
clampedIndex = pinnedCount;
607+
}
600608
}
601609
if (clampedIndex != theIndex) {
602610
NSMutableArray *mutCells = [[self sourceTabBar] cells];

ThirdParty/PSMTabBarControl/source/PSMTahoeTabStyle.swift

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,14 +1477,16 @@ class PSMTahoeTabStyle: NSObject, PSMTabStyle {
14771477
objects.append(GroupLO(name: "Pin Indicator", priority: Priority.required.rawValue, gravity: .left, members: [
14781478
ImageLO(name: "Pin Icon", image: pinImage, priority: Priority.required.rawValue, gravity: .left) { resolved in
14791479
var pinRect = resolved.frame
1480-
pinRect.origin.y = cell.frame.minY + floor((cell.frame.height - pinRect.height) / 2.0) + orientationShift
1480+
pinRect.size = pinImage.size
1481+
pinRect.origin.y = cell.frame.minY + floor((cell.frame.height - pinRect.height) / 2.0) + orientationShift + 2.0
14811482
tintedPin.draw(in: pinRect,
14821483
from: NSZeroRect,
14831484
operation: .sourceOver,
14841485
fraction: pinAlpha,
14851486
respectFlipped: true,
14861487
hints: nil)
14871488
},
1489+
FixedSpacerLO(name: "Post-pin Spacer", width: 4.0, priority: Priority.required.rawValue, gravity: .left)
14881490
]))
14891491
} else {
14901492
objects.append(FixedSpacerLO(name: "Leading Spacer", width: edgePadding, priority: Priority.required.rawValue, gravity: .left))
@@ -1521,54 +1523,53 @@ class PSMTahoeTabStyle: NSObject, PSMTabStyle {
15211523
// Amount to shift text down from vertically centered so that it matches the OS's rendering
15221524
let textShift = 1.0 + orientationShift
15231525
if !skipLabel {
1524-
objects.append(TextLO(name: Name.label.rawValue,
1525-
priority: Priority.required.rawValue,
1526-
minWidth: 8,
1527-
attributedStringWidth: labelWidth,
1528-
gravity: orientation == .horizontalOrientation ? .center : .left) { resolved in
1529-
let labelOffset: CGFloat
1530-
let mainLabelHeight: CGFloat
1531-
if let cachedTitle = cell.cachedTitle,
1532-
!cachedTitle.isEmpty {
1533-
let drawString: NSAttributedString
1534-
if cell.isPinned && orientation == .horizontalOrientation {
1535-
// For pinned tabs, show only the first character.
1536-
let title = cachedTitle.inputs.title ?? ""
1537-
let firstChar = title.isEmpty ? "" : String(title.prefix(1))
1538-
let fullString = cachedTitle.attributedStringForcingLeftAlignment(
1539-
true, truncatedForWidth: resolved.frame.size.width)
1540-
let attrs: [NSAttributedString.Key: Any] = fullString.length > 0
1541-
? fullString.attributes(at: 0, effectiveRange: nil)
1542-
: [:]
1543-
drawString = NSAttributedString(string: firstChar, attributes: attrs)
1526+
objects.append(TextLO(name: Name.label.rawValue,
1527+
priority: Priority.required.rawValue,
1528+
minWidth: 8,
1529+
attributedStringWidth: labelWidth,
1530+
gravity: orientation == .horizontalOrientation ? .center : .left) { resolved in
1531+
let labelOffset: CGFloat
1532+
let mainLabelHeight: CGFloat
1533+
if let cachedTitle = cell.cachedTitle,
1534+
!cachedTitle.isEmpty {
1535+
let drawString: NSAttributedString
1536+
if cell.isPinned && orientation == .horizontalOrientation {
1537+
// For pinned tabs, show only the first character.
1538+
let title = cachedTitle.inputs.title
1539+
let firstChar = title.isEmpty ? "" : String(title.prefix(1))
1540+
let fullString = cachedTitle.attributedStringForcingLeftAlignment(
1541+
true,
1542+
truncatedForWidth: resolved.frame.size.width)
1543+
let attrs = fullString.length > 0 ? fullString.attributes(at: 0, effectiveRange: nil) : [:]
1544+
drawString = NSAttributedString(string: firstChar, attributes: attrs)
1545+
} else {
1546+
drawString = cachedTitle.attributedStringForcingLeftAlignment(
1547+
orientation == .verticalOrientation,
1548+
truncatedForWidth: resolved.frame.size.width)
1549+
}
1550+
var rect = resolved.frame
1551+
let boundingSize = cachedTitle.boundingRect(with: NSSize(width: resolved.frame.width, height: cell.frame.height)).size
1552+
mainLabelHeight = boundingSize.height
1553+
labelOffset = PSMTahoeTabStyle.willDrawSubtitle(cell.cachedSubtitle) ? PSMTahoeTabStyle.verticalOffsetForTitleWhenSubtitlePresent : 0
1554+
rect.origin.y = cell.frame.origin.y + floor((cell.frame.size.height - boundingSize.height) / 2.0) + labelOffset + textShift
1555+
rect.size.height = boundingSize.height
1556+
drawString.draw(in: rect)
15441557
} else {
1545-
drawString = cachedTitle.attributedStringForcingLeftAlignment(
1546-
orientation == .verticalOrientation,
1547-
truncatedForWidth: resolved.frame.size.width)
1558+
labelOffset = 0
1559+
mainLabelHeight = 0
15481560
}
1549-
var rect = resolved.frame
1550-
let boundingSize = cachedTitle.boundingRect(with: NSSize(width: resolved.frame.width, height: cell.frame.height)).size
1551-
mainLabelHeight = boundingSize.height
1552-
labelOffset = PSMTahoeTabStyle.willDrawSubtitle(cell.cachedSubtitle) ? PSMTahoeTabStyle.verticalOffsetForTitleWhenSubtitlePresent : 0
1553-
rect.origin.y = cell.frame.origin.y + floor((cell.frame.size.height - boundingSize.height) / 2.0) + labelOffset + textShift
1554-
rect.size.height = boundingSize.height
1555-
drawString.draw(in: rect)
1556-
} else {
1557-
labelOffset = 0
1558-
mainLabelHeight = 0
1559-
}
1560-
1561-
// Draw subtitle (never for pinned tabs).
1562-
if supportsMultiLineLabels && !cell.isPinned {
1563-
self.drawSubtitle(cell: cell,
1564-
orientation: orientation,
1565-
xOrigin: resolved.frame.minX,
1566-
maxWidth: resolved.frame.width,
1567-
labelOffset: labelOffset,
1568-
mainLabelHeight: mainLabelHeight)
1569-
}
1570-
})
1571-
} // !skipLabel
1561+
1562+
// Draw subtitle (never for pinned tabs).
1563+
if supportsMultiLineLabels && !cell.isPinned {
1564+
self.drawSubtitle(cell: cell,
1565+
orientation: orientation,
1566+
xOrigin: resolved.frame.minX,
1567+
maxWidth: resolved.frame.width,
1568+
labelOffset: labelOffset,
1569+
mainLabelHeight: mainLabelHeight)
1570+
}
1571+
})
1572+
}
15721573

15731574
// Icon
15741575
if cell.hasIcon, let icon = icon(cell: cell) {

sources/PseudoTerminal.m

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7407,7 +7407,7 @@ - (NSMenu *)tabView:(NSTabView *)tabView menuForTabViewItem:(NSTabViewItem *)tab
74077407
}
74087408

74097409
// pin/unpin tab (not available for tmux tabs)
7410-
if (![theTab tmuxController]) {
7410+
if (![theTab isTmuxTab]) {
74117411
[rootMenu addItem:[NSMenuItem separatorItem]];
74127412
NSString *pinTitle = theTab.isPinned ? @"Unpin Tab" : @"Pin Tab";
74137413
item = [[[NSMenuItem alloc] initWithTitle:pinTitle
@@ -12865,8 +12865,6 @@ - (void)tabSessionDidChangeBackgroundColor:(PTYTab *)tab {
1286512865
[self updateForTransparency:self.ptyWindow];
1286612866
}
1286712867

12868-
// tab:didChangePinnedState: is in PseudoTerminal.swift
12869-
1287012868
- (void)tab:(PTYTab *)tab didChangeToState:(PTYTabState)newState {
1287112869
if (self.numberOfTabs == 1) {
1287212870
[self setWindowTitle];
@@ -12990,7 +12988,7 @@ - (void)updateToolbeltAppearance {
1299012988
}
1299112989
break;
1299212990
}
12993-
12991+
1299412992
case TAB_STYLE_AUTOMATIC:
1299512993
case TAB_STYLE_LIGHT:
1299612994
case TAB_STYLE_LIGHT_HIGH_CONTRAST:
@@ -13227,6 +13225,11 @@ - (void)tabEndSyntheticSession:(PTYSession *)syntheticSession {
1322713225
[self replaceSyntheticSessionWithLiveSessionIfNeeded:syntheticSession];
1322813226
}
1322913227

13228+
- (void)tab:(PTYTab *)tab didChangePinnedState:(BOOL)pinned {
13229+
[self _tab:tab didChangePinnedState:pinned];
13230+
}
13231+
13232+
1323013233
#pragma mark - PSMMinimalTabStyleDelegate
1323113234

1323213235
- (NSColor *)minimalTabStyleBackgroundColor {
@@ -13286,7 +13289,7 @@ - (void)broadcastInputHelperDidUpdate:(iTermBroadcastInputHelper *)helper {
1328613289
// Update dimming of panes.
1328713290
[self refreshTerminal:nil];
1328813291
[self setDimmingForSessions];
13289-
13292+
1329013293
// Post a notification to reload menus
1329113294
[[NSNotificationCenter defaultCenter] postNotificationName:@"iTermWindowBecameKey"
1329213295
object:self
@@ -13386,18 +13389,18 @@ - (BOOL)swipeHandlerShouldBeginNewSwipe {
1338613389

1338713390
- (id)swipeHandlerBeginSessionAtOffset:(CGFloat)offset identifier:(nonnull id)identifier {
1338813391
DLog(@"swipeHandlerBeginSessionAtOffset:%@ identifier:%@", @(offset), identifier);
13389-
13392+
1339013393
assert(!_swipeContainerView);
1339113394
self.swipeIdentifier = identifier;
13392-
13395+
1339313396
NSRect frame = NSZeroRect;
1339413397
frame.origin.x = offset;
1339513398
frame.size.width = self.tabs.firstObject.realRootView.frame.size.width * self.tabs.count;
1339613399
frame.size.height = self.tabs.firstObject.realRootView.frame.size.height;
1339713400
_swipeContainerView = [[[NSView alloc] initWithFrame:frame] autorelease];
1339813401
[self updateUseMetalInAllTabs];
1339913402
const CGFloat width = self.swipeHandlerParameters.width;
13400-
13403+
1340113404
[self.tabs enumerateObjectsUsingBlock:^(PTYTab * _Nonnull tab, NSUInteger idx, BOOL * _Nonnull stop) {
1340213405
NSView *view = tab.realRootView;
1340313406
NSRect frame = view.frame;
@@ -13410,7 +13413,7 @@ - (id)swipeHandlerBeginSessionAtOffset:(CGFloat)offset identifier:(nonnull id)id
1341013413
[_swipeContainerView addSubview:clipView];
1341113414
}];
1341213415
[self.contentView.tabView addSubview:_swipeContainerView];
13413-
13416+
1341413417
return @{};
1341513418
}
1341613419

@@ -13431,14 +13434,14 @@ - (CGFloat)truncatedSwipeOffset:(CGFloat)x {
1343113434

1343213435
- (void)swipeHandlerSetOffset:(CGFloat)rawOffset forSession:(id)session {
1343313436
DLog(@"setOffset:%@ forSession:%@", @(rawOffset), session);
13434-
13437+
1343513438
NSRect frame = _swipeContainerView.frame;
1343613439
const CGFloat offset = -[self truncatedSwipeOffset:-rawOffset];
1343713440
frame.origin.x = offset;
13438-
13441+
1343913442
DLog(@"_swipeContainerView.frame=%@", NSStringFromRect(frame));
1344013443
_swipeContainerView.frame = frame;
13441-
13444+
1344213445
DLog(@"After setting frame:\n%@", [self.window.contentView iterm_recursiveDescription]);
1344313446
}
1344413447

@@ -13502,14 +13505,14 @@ - (void)didFinishRestoringWindow {
1350213505
[self.window setFrame:rect display:YES];
1350313506
[self fitTabsToWindow];
1350413507
}
13505-
13508+
1350613509
DLog(@"Set width adjustment to 0 for %@", self);
1350713510
_widthAdjustment = 0;
1350813511
}
1350913512

1351013513
- (NSRect)rectByAdjustingWidth:(NSRect)rect {
1351113514
DLog(@"%@: Computing width adjustment for window type %@ rect %@ widthAdjustment %@",
13512-
self, @(self.windowType), NSStringFromRect(rect), @(_widthAdjustment));
13515+
self, @(self.windowType), NSStringFromRect(rect), @(_widthAdjustment));
1351313516
switch (self.windowType) {
1351413517
case WINDOW_TYPE_TRADITIONAL_FULL_SCREEN:
1351513518
case WINDOW_TYPE_LION_FULL_SCREEN:
@@ -13519,7 +13522,7 @@ - (NSRect)rectByAdjustingWidth:(NSRect)rect {
1351913522
case WINDOW_TYPE_COMPACT_MAXIMIZED:
1352013523
DLog(@"No width adjustment because of window type");
1352113524
return rect;
13522-
13525+
1352313526
case WINDOW_TYPE_CENTERED:
1352413527
case WINDOW_TYPE_NORMAL:
1352513528
case WINDOW_TYPE_LEFT_PERCENTAGE:

sources/PseudoTerminal.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,17 @@ extension PseudoTerminal: ColorsMenuItemViewDelegate {
309309
if tab == nil {
310310
tab = currentTab()
311311
}
312-
guard let tab else { return }
313-
if tab.tmuxController() != nil { return }
312+
guard let tab else {
313+
return
314+
}
315+
if tab.tmuxController() != nil {
316+
return
317+
}
314318
tab.isPinned = !tab.isPinned
315319
}
316320

317-
@objc func tab(_ tab: PTYTab, didChangePinnedState pinned: Bool) {
321+
// Delegate method call forwarded from main class.
322+
@objc(_tab:didChangePinnedState:) func tab(_ tab: PTYTab, didChangePinnedState pinned: Bool) {
318323
guard let tabViewItem = tab.tabViewItem else { return }
319324
tabBarControl()?.setIsPinned(pinned, for: tabViewItem)
320325

0 commit comments

Comments
 (0)