Skip to content
Snippets Groups Projects
Commit be900867 authored by George Nachman's avatar George Nachman
Browse files

Make the app hotkey remember the previously active app so it can switch back...

Make the app hotkey remember the previously active app so it can switch back to it from a lion fullscreen window. Issue 5925.
parent 784dcbfb
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,12 +3,44 @@
#import "DebugLogging.h"
#import "iTermController.h"
#import "iTermPreferences.h"
#import "iTermPreviousState.h"
#import "NSTextField+iTerm.h"
#import "PreferencePanel.h"
 
@class iTermHotKey;
 
@implementation iTermAppHotKey
@implementation iTermAppHotKey {
NSRunningApplication *_previousApp;
iTermPreviousState *_previousState;
}
- (instancetype)initWithShortcuts:(NSArray<iTermShortcut *> *)shortcuts
hasModifierActivation:(BOOL)hasModifierActivation
modifierActivation:(iTermHotKeyModifierActivation)modifierActivation {
self = [super initWithShortcuts:shortcuts
hasModifierActivation:hasModifierActivation
modifierActivation:modifierActivation];
if (self) {
_previousState = [[iTermPreviousState alloc] init];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
selector:@selector(workspaceDidDeactivateApplication:)
name:NSWorkspaceDidDeactivateApplicationNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:NSApplicationDidBecomeActiveNotification
object:nil];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
[_previousApp release];
[_previousState release];
[super dealloc];
}
 
- (NSArray<iTermBaseHotKey *> *)hotKeyPressedWithSiblings:(NSArray<iTermBaseHotKey *> *)siblings {
DLog(@"hotkey pressed");
Loading
Loading
@@ -19,7 +51,11 @@
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
if (prefsWindow != keyWindow ||
prefsWindowController.window.firstResponder != prefsWindowController.hotkeyField) {
[NSApp hide:nil];
if (_previousState && (keyWindow.styleMask & NSFullScreenWindowMask)) {
[_previousState restorePreviouslyActiveApp];
} else {
[NSApp hide:nil];
}
}
} else {
iTermController *controller = [iTermController sharedInstance];
Loading
Loading
@@ -32,4 +68,18 @@
return nil;
}
 
- (void)workspaceDidDeactivateApplication:(NSNotification *)notification {
[_previousApp autorelease];
_previousApp = [notification.userInfo[NSWorkspaceApplicationKey] retain];
}
- (void)applicationDidBecomeActive:(NSNotification *)notification {
[_previousState autorelease];
_previousState = nil;
if (_previousApp) {
_previousState = [[iTermPreviousState alloc] initWithRunningApp:_previousApp];
}
}
@end
Loading
Loading
@@ -12,6 +12,8 @@
 
@property(nonatomic, retain) iTermProfileHotKey *owner;
 
- (instancetype)initWithRunningApp:(NSRunningApplication *)runningApp;
// Returns YES if another app was activated.
- (BOOL)restoreAllowingAppSwitch:(BOOL)allowAppSwitch;
 
Loading
Loading
Loading
Loading
@@ -6,22 +6,33 @@
 
@implementation iTermPreviousState
 
- (instancetype)init {
- (instancetype)initWithBundleIdentifier:(NSString *)bundleIdentifier
processID:(pid_t)processID {
self = [super init];
if (self) {
NSDictionary *activeAppDict = [[NSWorkspace sharedWorkspace] activeApplication];
DLog(@"Saving state: active app is %@", activeAppDict);
if ([[activeAppDict objectForKey:@"NSApplicationBundleIdentifier"] isEqualToString:[[NSBundle mainBundle] bundleIdentifier]]) {
if ([bundleIdentifier isEqualToString:[[NSBundle mainBundle] bundleIdentifier]]) {
self.previouslyActiveAppPID = nil;
} else {
self.previouslyActiveAppPID = activeAppDict[@"NSApplicationProcessIdentifier"];
self.previouslyActiveAppPID = @(processID);
}
DLog(@"Previously active pid for %p is %@", self, _previouslyActiveAppPID);
DLog(@"Previously active pid for %p is %@", self, @(processID));
_itermWasActiveWhenHotkeyOpened = [NSApp isActive];
}
return self;
}
 
- (instancetype)init {
NSDictionary *activeAppDict = [[NSWorkspace sharedWorkspace] activeApplication];
DLog(@"Saving state: active app is %@", activeAppDict);
return [self initWithBundleIdentifier:activeAppDict[@"NSApplicationBundleIdentifier"]
processID:[activeAppDict[@"NSApplicationProcessIdentifier"] longLongValue]];
}
- (instancetype)initWithRunningApp:(NSRunningApplication *)runningApp {
return [self initWithBundleIdentifier:runningApp.bundleIdentifier
processID:runningApp.processIdentifier];
}
- (void)dealloc {
[_owner release];
[super dealloc];
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment