Skip to content

Commit

Permalink
Fix broadcast input for tmux sessions. Also, don't save tmux windows …
Browse files Browse the repository at this point in the history
…for lion's resume
  • Loading branch information
gnachman committed Feb 1, 2012
1 parent ab0f3ce commit b5dfb01
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
2 changes: 2 additions & 0 deletions PTYSession.h
Expand Up @@ -251,6 +251,7 @@ typedef enum {
+ (void)selectMenuItem:(NSString*)theName;

- (BOOL)isTmuxClient;
- (BOOL)isTmuxGateway;

// init/dealloc
- (id)init;
Expand Down Expand Up @@ -321,6 +322,7 @@ typedef enum {

// PTYTask
- (void)writeTask:(NSData*)data;
- (void)writeTaskNoBroadcast:(NSData *)data;
- (void)readTask:(NSData*)data;
- (void)brokenPipe;

Expand Down
23 changes: 21 additions & 2 deletions PTYSession.m
Expand Up @@ -865,6 +865,16 @@ - (void)writeTaskImpl:(NSData *)data
}
}

- (void)writeTaskNoBroadcast:(NSData *)data
{
if (tmuxMode_ == TMUX_CLIENT) {
[[tmuxController_ gateway] sendKeys:data
toWindowPane:tmuxPane_];
return;
}
[self writeTaskImpl:data];
}

- (void)handleKeypressInTmuxGateway:(unichar)unicode
{
if (unicode == 27) {
Expand Down Expand Up @@ -898,8 +908,12 @@ - (void)writeTask:(NSData*)data
{
if (tmuxMode_ == TMUX_CLIENT) {
[self setBell:NO];
[[tmuxController_ gateway] sendKeys:data
toWindowPane:tmuxPane_];
if ([[tab_ realParentWindow] broadcastInputToSession:self]) {
[[tab_ realParentWindow] sendInputToAllSessions:data];
} else {
[[tmuxController_ gateway] sendKeys:data
toWindowPane:tmuxPane_];
}
PTYScroller* ptys = (PTYScroller*)[SCROLLVIEW verticalScroller];
[ptys setUserScroll:NO];
return;
Expand Down Expand Up @@ -3622,6 +3636,11 @@ - (BOOL)isTmuxClient
return tmuxMode_ == TMUX_CLIENT;
}

- (BOOL)isTmuxGateway
{
return tmuxMode_ == TMUX_GATEWAY;
}

- (void)tmuxDetach
{
if (tmuxMode_ != TMUX_GATEWAY) {
Expand Down
3 changes: 3 additions & 0 deletions PseudoTerminal.h
Expand Up @@ -403,6 +403,9 @@ NSWindowDelegate,
// Set the window title to non-transient.
- (void)resetTempTitle;

// Sessions in the broadcast group.
- (NSArray *)broadcastSessions;

// Call writeTask: for each session's shell with the given data.
- (void)sendInputToAllSessions:(NSData *)data;

Expand Down
31 changes: 22 additions & 9 deletions PseudoTerminal.m
Expand Up @@ -450,7 +450,7 @@ - (id)initWithSmartLayout:(BOOL)smartLayout
}
if (isHotkey && IsSnowLeopardOrLater()) {
[[self window] setCollectionBehavior:[[self window] collectionBehavior] | NSWindowCollectionBehaviorIgnoresCycle];
[[self window] setCollectionBehavior:[[self window] collectionBehavior] & ~NSWindowCollectionBehaviorParticipatesInCycle];
[[self window] setCollectionBehavior:[[self window] collectionBehavior] & ~NSWindowCollectionBehaviorParticipatesInCycle];
}

toolbelt_ = [[[ToolbeltView alloc] initWithFrame:NSMakeRect(0, 0, 200, self.window.frame.size.height - kToolbeltMargin)
Expand Down Expand Up @@ -1051,19 +1051,19 @@ - (void)resetTempTitle
tempTitle = NO;
}

- (void)sendInputToAllSessions:(NSData *)data
- (NSArray *)broadcastSessions
{
NSMutableArray *sessions = [NSMutableArray array];
int i;

int n = [TABVIEW numberOfTabViewItems];
switch (broadcastMode_) {
case BROADCAST_OFF:
return;
break;

case BROADCAST_TO_ALL_PANES:
for (PTYSession* aSession in [[self currentTab] sessions]) {
if (![aSession exited]) {
[[aSession SHELL] writeTask:data];
[sessions addObject:aSession];
}
}
break;
Expand All @@ -1072,7 +1072,7 @@ - (void)sendInputToAllSessions:(NSData *)data
for (i = 0; i < n; ++i) {
for (PTYSession* aSession in [[[TABVIEW tabViewItemAtIndex:i] identifier] sessions]) {
if (![aSession exited]) {
[[aSession SHELL] writeTask:data];
[sessions addObject:aSession];
}
}
}
Expand All @@ -1083,14 +1083,26 @@ - (void)sendInputToAllSessions:(NSData *)data
for (PTYSession *aSession in [aTab sessions]) {
if ([broadcastViewIds_ containsObject:[NSNumber numberWithInt:[[aSession view] viewId]]]) {
if (![aSession exited]) {
[[aSession SHELL] writeTask:data];
[sessions addObject:aSession];
}
}
}
}
break;
}
}
return sessions;
}

- (void)sendInputToAllSessions:(NSData *)data
{
for (PTYSession *aSession in [self broadcastSessions]) {
if ([aSession isTmuxClient]) {
[aSession writeTaskNoBroadcast:data];
} else if (![aSession isTmuxGateway]) {
[[aSession SHELL] writeTask:data];
}
}
}

- (BOOL)broadcastInputToSession:(PTYSession *)session
Expand Down Expand Up @@ -1239,7 +1251,7 @@ + (PseudoTerminal*)bareTerminalWithArrangement:(NSDictionary*)arrangement
term = [[[PseudoTerminal alloc] initWithSmartLayout:NO
windowType:WINDOW_TYPE_FORCE_FULL_SCREEN
screen:screenIndex] autorelease];

NSRect rect;
rect.origin.x = [[arrangement objectForKey:TERMINAL_ARRANGEMENT_OLD_X_ORIGIN] doubleValue];
rect.origin.y = [[arrangement objectForKey:TERMINAL_ARRANGEMENT_OLD_Y_ORIGIN] doubleValue];
Expand All @@ -1260,7 +1272,7 @@ + (PseudoTerminal*)bareTerminalWithArrangement:(NSDictionary*)arrangement
}
// TODO: this looks like a bug - are top-of-screen windows not restored to the right screen?
term = [[[PseudoTerminal alloc] initWithSmartLayout:NO windowType:windowType screen:-1] autorelease];

NSRect rect;
rect.origin.x = [[arrangement objectForKey:TERMINAL_ARRANGEMENT_X_ORIGIN] doubleValue];
rect.origin.y = [[arrangement objectForKey:TERMINAL_ARRANGEMENT_Y_ORIGIN] doubleValue];
Expand Down Expand Up @@ -5444,6 +5456,7 @@ - (void)window:(NSWindow *)window willEncodeRestorableState:(NSCoder *)state
{
if ([self isHotKeyWindow] || [self allTabsAreTmuxTabs]) {
// Don't save and restore hotkey windows or tmux windows.
[[self ptyWindow] setRestoreState:nil];
return;
}
if (wellFormed_) {
Expand Down

0 comments on commit b5dfb01

Please sign in to comment.