Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to make Terminal.app a UIElement #61

Merged
merged 9 commits into from
Dec 4, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions totalterminal-plugin/Terminal/TTTabController.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@

@property (readonly) TTPane* activePane; // @synthesize activePane;

-(id)windowController;
-(void)closePane:(id)arg1;
-(void)splitPane:(id)arg1;

@end
1 change: 1 addition & 0 deletions totalterminal-plugin/TotalTerminal+Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
-(IBAction)exitMe:(id)sender;
-(IBAction)crashMe:(id)sender;
-(IBAction)createVisorProfile:(id)sender;
-(IBAction)toggleUIElement:(id)sender;

@end
7 changes: 7 additions & 0 deletions totalterminal-plugin/TotalTerminal+Commands.mm
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,11 @@ -(IBAction) createVisorProfile:(id)sender {
}
}

-(IBAction) toggleUIElement:(id)sender {
AUTO_LOGGERF(@"sender=%@", sender);
NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];
BOOL val = [ud boolForKey:@"TotalTerminalHideDockIcon"];
[ud setBool:(val ? NO:YES) forKey:@"TotalTerminalHideDockIcon"];
}

@end
3 changes: 3 additions & 0 deletions totalterminal-plugin/TotalTerminal+Defaults.mm
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ +(void) sanitizeDefaults:(NSUserDefaults*)ud {
if (![ud objectForKey:@"TotalTerminalDontCustomizeDockIcon"]) {
[ud setBool:NO forKey:@"TotalTerminalDontCustomizeDockIcon"];
}
if (![ud objectForKey:@"TotalTerminalHideDockIcon"]) {
[ud setBool:NO forKey:@"TotalTerminalHideDockIcon"];
}
if (![ud objectForKey:@"TotalTerminalUsePreReleases"]) {
[ud setBool:NO forKey:@"TotalTerminalUsePreReleases"];
}
Expand Down
4 changes: 4 additions & 0 deletions totalterminal-plugin/TotalTerminal+Observers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ -(void) registerObservers {
[udc addObserver:self forKeyPath:@"values.TotalTerminalVisorUseBackgroundAnimation" options:0 context:nil];
[udc addObserver:self forKeyPath:@"values.TotalTerminalVisorBackgroundAnimationOpacity" options:0 context:nil];
[udc addObserver:self forKeyPath:@"values.TotalTerminalDontCustomizeDockIcon" options:0 context:nil];
[udc addObserver:self forKeyPath:@"values.TotalTerminalHideDockIcon" options:0 context:nil];
[udc addObserver:self forKeyPath:@"values.TotalTerminalShortcuts" options:0 context:nil];
[udc addObserver:self forKeyPath:@"values.TotalTerminalUsePreReleases" options:0 context:nil];
[udc addObserver:self forKeyPath:@"values.TotalTerminalVisorPinned" options:0 context:nil];
Expand Down Expand Up @@ -72,6 +73,9 @@ -(void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NS
if ([keyPath isEqualToString:@"values.TotalTerminalDontCustomizeDockIcon"]) {
[self setupDockIcon];
}
if ([keyPath isEqualToString:@"values.TotalTerminalHideDockIcon"]) {
[self updateUIElement];
}
if ([keyPath isEqualToString:@"values.TotalTerminalVisorFullScreen"]) {
[self resetWindowPlacement];
}
Expand Down
16 changes: 16 additions & 0 deletions totalterminal-plugin/TotalTerminal+UIElement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TotalTerminal+UIElement.h
// TotalTerminal
//
// Created by Brian K Garrett on 11/30/12.
// Copyright (c) 2012 BinaryAge. All rights reserved.
//

#import "TotalTerminal.h"

@interface TotalTerminal (UIElement)

-(BOOL)isUIElement;
-(void)updateUIElement;

@end
39 changes: 39 additions & 0 deletions totalterminal-plugin/TotalTerminal+UIElement.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// TotalTerminal+UIElement.mm
// TotalTerminal
//
// Created by Brian K Garrett on 11/30/12.
// Copyright (c) 2012 BinaryAge. All rights reserved.
//

#import "TotalTerminal+UIElement.h"

@implementation TotalTerminal (UIElement)

-(BOOL) isUIElement {
return ([[NSRunningApplication currentApplication] activationPolicy] == NSApplicationActivationPolicyAccessory) ? YES : NO;
}

-(void) updateUIElement {
BOOL hideDockIcon = [[NSUserDefaults standardUserDefaults] boolForKey:@"TotalTerminalHideDockIcon"];
NSApplicationActivationPolicy policy = [[NSRunningApplication currentApplication] activationPolicy];
ProcessSerialNumber psn = {
0, kCurrentProcess
};

if (policy == NSApplicationActivationPolicyRegular) {
if (hideDockIcon) {
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
}
} else if (policy == NSApplicationActivationPolicyAccessory) {
if (!hideDockIcon) {
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
} else {
// Terminal is running as NSApplicationActivationPolicyProhibited
// and is a background daemon for some reason
return;
}
}

@end
42 changes: 37 additions & 5 deletions totalterminal-plugin/TotalTerminal+Visor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ -(id) SMETHOD (TTWindowController, forceVisorProfileIfVisoredWindow) {
// responsible for opening all tabs in Visored window with Visor profile (regardless of "default profile" setting)
-(id) SMETHOD (TTWindowController, newTabWithProfile):(id)arg1 {
id profile = [self SMETHOD (TTWindowController, forceVisorProfileIfVisoredWindow)]; // returns nil if not Visor-ed window

AUTO_LOGGERF(@"profile=%@", profile);
if (profile) {
arg1 = profile;
Expand All @@ -148,6 +149,7 @@ -(id) SMETHOD (TTWindowController, newTabWithProfile):(id)arg1 {
// this seems to be an alternative point to intercept new tab creation
-(id) SMETHOD (TTWindowController, newTabWithProfile):(id)arg1 command:(id)arg2 runAsShell:(BOOL)arg3 {
id profile = [self SMETHOD (TTWindowController, forceVisorProfileIfVisoredWindow)]; // returns nil if not Visor-ed window

AUTO_LOGGERF(@"profile=%@", profile);
if (profile) {
arg1 = profile;
Expand All @@ -165,6 +167,7 @@ -(id) SMETHOD (TTWindowController, newTabWithProfile):(id)arg1 command:(id)arg2
-(id) SMETHOD (TTWindowController, newTabWithProfile):(id)arg1 customFont:(id)arg2 command:(id)arg3 runAsShell:(BOOL)arg4 restorable:(BOOL)arg5 workingDirectory:(id)arg6 sessionClass:(id)arg7
restoreSession :(id)arg8 {
id profile = [self SMETHOD (TTWindowController, forceVisorProfileIfVisoredWindow)]; // returns nil if not Visor-ed window

AUTO_LOGGERF(@"profile=%@", profile);
if (profile) {
arg1 = profile;
Expand All @@ -181,6 +184,7 @@ -(id) SMETHOD (TTWindowController, newTabWithProfile):(id)arg1 customFont:(id)ar
// Mountain Lion renaming since v304
-(id) SMETHOD (TTWindowController, makeTabWithProfile):(id)arg1 {
id profile = [self SMETHOD (TTWindowController, forceVisorProfileIfVisoredWindow)]; // returns nil if not Visor-ed window

AUTO_LOGGERF(@"profile=%@", profile);
if (profile) {
arg1 = profile;
Expand All @@ -197,22 +201,22 @@ -(id) SMETHOD (TTWindowController, makeTabWithProfile):(id)arg1 {
-(id) SMETHOD (TTWindowController,
makeTabWithProfile):(id)arg1 customFont:(id)arg2 command:(id)arg3 runAsShell:(BOOL)arg4 restorable:(BOOL)arg5 workingDirectory:(id)arg6 sessionClass:(id)arg7 restoreSession:(id)arg8 {
id profile = [self SMETHOD (TTWindowController, forceVisorProfileIfVisoredWindow)]; // returns nil if not Visor-ed window

AUTO_LOGGERF(@"profile=%@", profile);
if (profile) {
arg1 = profile;
ScopedNSDisableScreenUpdatesWithDelay disabler(0, __FUNCTION__); // this is needed to prevent visual switch when calling resetVisorWindowSize followed by applyVisorPositioning
[[TotalTerminal sharedInstance] resetVisorWindowSize]; // see https://github.com/binaryage/totalterminal/issues/56
}

id tab = [self SMETHOD (TTWindowController, makeTabWithProfile):arg1 customFont:arg2 command:arg3 runAsShell:arg4 restorable:arg5 workingDirectory:arg6 sessionClass:arg7 restoreSession:arg8];
if ([(TTWindowController*) self numberOfTabs] > 1) { // why this test?
if (profile) [[TotalTerminal sharedInstance] applyVisorPositioning];
if (profile) {
[[TotalTerminal sharedInstance] applyVisorPositioning];
}
return tab;
}

// The following TabView methods fill out support for making and closing tabs
//
-(void) SMETHOD (TTWindowController, tabView):(id)arg1 didCloseTabViewItem:(id)arg2 {
AUTO_LOGGER();
[self SMETHOD (TTWindowController, tabView):arg1 didCloseTabViewItem:arg2];
Expand All @@ -225,6 +229,31 @@ -(void) SMETHOD (TTWindowController, tabView):(id)arg1 didCloseTabViewItem:(id)a

@end

@implementation NSObject (TotalTerminal)

// Both [TTWindowController close/splitActivePane:] and [TTPane close/splitPressed:] call these methods
-(void) SMETHOD (TTTabController, closePane):(id)arg1 {
AUTO_LOGGER();
[(TTTabController*) self SMETHOD(TTTabController, closePane):arg1];
TTWindowController* winc = [(TTTabController*) self windowController];
TotalTerminal* totalTerminal = [TotalTerminal sharedInstance];
if ([totalTerminal isVisorWindow:[winc window]]) {
[totalTerminal applyVisorPositioning];
}
}

-(void) SMETHOD (TTTabController, splitPane):(id)arg1 {
AUTO_LOGGER();
[(TTTabController*) self SMETHOD(TTTabController, splitPane):arg1];
TTWindowController* winc = [(TTTabController*) self windowController];
TotalTerminal* totalTerminal = [TotalTerminal sharedInstance];
if ([totalTerminal isVisorWindow:[winc window]]) {
[totalTerminal applyVisorPositioning];
}
}

@end

@implementation NSApplication (TotalTerminal)

-(void) SMETHOD (TTApplication, sendEvent):(NSEvent*)theEvent {
Expand Down Expand Up @@ -728,7 +757,7 @@ -(void) applyVisorPositioning {
}
BOOL shouldForceFullScreenWindow = [[NSUserDefaults standardUserDefaults] boolForKey:@"TotalTerminalVisorFullScreen"];
if ([position isEqualToString:@"Full Screen"] || shouldForceFullScreenWindow) {
XLOG(@"FULL SCREEN forced=%@", shouldForceFullScreenWindow?@"true":@"false");
XLOG(@"FULL SCREEN forced=%@", shouldForceFullScreenWindow ? @"true" : @"false");
NSRect frame = [window_ frame];
frame.size.width = screenRect.size.width;
frame.size.height = screenRect.size.height - shift;
Expand Down Expand Up @@ -1266,6 +1295,9 @@ +(void) loadVisor {
}
SWIZZLE(TTWindowController, tabView: didCloseTabViewItem:);

SWIZZLE(TTTabController, closePane:);
SWIZZLE(TTTabController, splitPane:);

SWIZZLE(TTWindowController, setCloseDialogExpected:);
SWIZZLE(TTWindowController, window: willPositionSheet: usingRect:);

Expand Down
1 change: 1 addition & 0 deletions totalterminal-plugin/TotalTerminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#import "TotalTerminal+Commands.h"
#import "TotalTerminal+Helpers.h"
#import "TotalTerminal+Dock.h"
#import "TotalTerminal+UIElement.h"
#import "TotalTerminal+Sparkle.h"
#import "TotalTerminal+Shortcuts.h"
#import "TotalTerminal+Menu.h"
Expand Down
1 change: 1 addition & 0 deletions totalterminal-plugin/TotalTerminal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ -(id) init {
modifiersShift_ = [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"ModifiersShift"]];

[self setupDockIcon];
[self updateUIElement];

[self initializeBackground];
[self initStatusMenu];
Expand Down
9 changes: 9 additions & 0 deletions totalterminal-plugin/TotalTerminal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
07CA8BD712B499F600A6D8BF /* Error.png in Resources */ = {isa = PBXBuildFile; fileRef = 07CA8BD612B499F600A6D8BF /* Error.png */; };
26C7384F11045EBF00E5058E /* TotalTerminal+PasteOnRightClick.mm in Sources */ = {isa = PBXBuildFile; fileRef = 26C7384E11045EBF00E5058E /* TotalTerminal+PasteOnRightClick.mm */; };
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; };
D37060FD1668AF2C00E99968 /* TotalTerminal+UIElement.mm in Sources */ = {isa = PBXBuildFile; fileRef = D37060FC1668AF2C00E99968 /* TotalTerminal+UIElement.mm */; };
D614F0B61607C5D70045572D /* AutoLogger.mm in Sources */ = {isa = PBXBuildFile; fileRef = D614F0B51607C5D70045572D /* AutoLogger.mm */; };
D62204AF1051CC3700FAEA30 /* TotalTerminal+TerminalColours.mm in Sources */ = {isa = PBXBuildFile; fileRef = D62204AE1051CC3700FAEA30 /* TotalTerminal+TerminalColours.mm */; };
D62A1D1C13E4B7F100221A33 /* Visor-Lion.terminal in Resources */ = {isa = PBXBuildFile; fileRef = D62A1D1A13E4B7F100221A33 /* Visor-Lion.terminal */; };
Expand Down Expand Up @@ -169,6 +170,8 @@
8D5B49B6048680CD000E48DA /* TotalTerminal.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TotalTerminal.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D2F7E65807B2D6F200F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
D37060FB1668AF2C00E99968 /* TotalTerminal+UIElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TotalTerminal+UIElement.h"; sourceTree = "<group>"; };
D37060FC1668AF2C00E99968 /* TotalTerminal+UIElement.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "TotalTerminal+UIElement.mm"; sourceTree = "<group>"; };
D614F0B41607C5D70045572D /* AutoLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AutoLogger.h; path = base/AutoLogger.h; sourceTree = "<group>"; };
D614F0B51607C5D70045572D /* AutoLogger.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AutoLogger.mm; path = base/AutoLogger.mm; sourceTree = "<group>"; };
D62204AD1051CC3700FAEA30 /* TotalTerminal+TerminalColours.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TotalTerminal+TerminalColours.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -307,8 +310,11 @@
089C1671FE841209C02AAC07 /* Frameworks and Libraries */,
19C28FB8FE9D52D311CA2CBB /* Products */,
);
indentWidth = 2;
name = Visor;
sourceTree = "<group>";
tabWidth = 2;
usesTabs = 0;
};
089C1671FE841209C02AAC07 /* Frameworks and Libraries */ = {
isa = PBXGroup;
Expand Down Expand Up @@ -374,6 +380,8 @@
D6AF5AAB13E314F000C44014 /* TotalTerminal+Helpers.mm */,
D6AF5AAD13E3154F00C44014 /* TotalTerminal+Dock.h */,
D6AF5AAE13E3154F00C44014 /* TotalTerminal+Dock.mm */,
D37060FB1668AF2C00E99968 /* TotalTerminal+UIElement.h */,
D37060FC1668AF2C00E99968 /* TotalTerminal+UIElement.mm */,
D6AF5AB013E3156000C44014 /* TotalTerminal+Sparkle.h */,
D6AF5AB113E3156000C44014 /* TotalTerminal+Sparkle.mm */,
D6AF5A9013E2FF5500C44014 /* TotalTerminal+Shortcuts.h */,
Expand Down Expand Up @@ -815,6 +823,7 @@
D69D315D13E46F000013A750 /* ScreenUpdates.mm in Sources */,
D65192E014F013EB002B562B /* TotalTerminal+AutoSlide.mm in Sources */,
D614F0B61607C5D70045572D /* AutoLogger.mm in Sources */,
D37060FD1668AF2C00E99968 /* TotalTerminal+UIElement.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down