Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
choco committed Dec 23, 2015
0 parents commit 8500d8b
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "JRSwizzle"]
path = JRSwizzle
url = git://github.com/rentzsch/jrswizzle.git
31 changes: 31 additions & 0 deletions Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>noTitleBar-Terminal</string>
<key>CFBundleIdentifier</key>
<string>me.choco.noTitleBarTerminal</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>noTitleBar-Terminal</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.1</string>
<key>NSPrincipalClass</key>
<string>noTitleBarTerminal</string>
<key>SIMBLTargetApplications</key>
<array>
<dict>
<key>BundleIdentifier</key>
<string>com.apple.Terminal</string>
</dict>
</array>
</dict>
</plist>
1 change: 1 addition & 0 deletions JRSwizzle
Submodule JRSwizzle added at 6627af
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
CC=clang
LD=$(CC)

ARCH=
ARCHES=$(foreach arch,$(ARCH),-arch $(arch))
OSXVER=10.5
OSXVER64=10.5
ifneq ($(OSXVER),$(OSXVER64))
ARCHES+=-Xarch_x86_64 -mmacosx-version-min=$(OSXVER64)
endif

OPTLEVEL=2
CFLAGS+=-std=c99 -O$(OPTLEVEL) -Wall -mmacosx-version-min=$(OSXVER) $(ARCHES)
LDFLAGS+=-bundle -framework Cocoa
OBJS=noTitleBar-Terminal.m JRSwizzle/JRSwizzle.o
NAME=noTitleBar-Terminal
BUNDLE=$(NAME).bundle
TARGET=$(BUNDLE)/Contents/MacOS/$(NAME)
SIMBLDIR=$(HOME)/Library/Application\ Support/SIMBL/Plugins

default: all
%.o: %.m
$(CC) -c $(CFLAGS) $< -o $@

$(TARGET): $(OBJS)
mkdir -p $(BUNDLE)/Contents/MacOS
$(LD) $(CFLAGS) $(LDFLAGS) -o $@ $^
cp Info.plist $(BUNDLE)/Contents

all: $(TARGET)

clean:
rm -f *.o
rm -f JRSwizzle/*.o
rm -rf $(BUNDLE) $(NAME)

install: $(TARGET) uninstall
mkdir -p $(SIMBLDIR)
cp -R $(BUNDLE) $(SIMBLDIR)

uninstall:
rm -rf $(SIMBLDIR)/$(BUNDLE)
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
「 noTitleBar Terminal.app 」
=================================

Simple SIMBL plugin that removes the Titlebar (and Toolbar) from Terminal.app.

Why and how
-----------

I've always envied Linux for the great window managers that the community
produces. Some nice tools to mimic that behaviour are finally surfacing on OS X
like [Hammerspoon][1] and [Kwm][2]. Many setups you see around use iTerm without
the title bar, and since I thought it was pretty cool I decided to add the same
option in Terminal.app
The basic change is removing the NSTitledWindowMask during the window creation,
the other hooked functions are needed to keep all Terminal features working.

Download
--------

An already compiled bundle is available:

[https://github.com/cHoco/noTitleBar-Terminal/releases]
(https://github.com/cHoco/noTitleBar-Terminal/releases)

Development
-----------

Download the development repository using Git:

git clone --recursive git://github.com/cHoco/noTitleBar-Terminal.git

Run `make` to compile the plugin, and `make install` to install it into your
home directory's SIMBL plugins folder.

[1]: http://www.hammerspoon.org
[2]: https://github.com/koekeishiya/kwm
13 changes: 13 additions & 0 deletions noTitleBar-Terminal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// noTitleBar-Terminal.h
// noTitleBar-Terminal
//
// Created by Enrico "cHoco" Ghirardi on 23/12/15.
// Copyright (c) 2015 cHoco. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface noTitleBarTerminal : NSObject

@end
103 changes: 103 additions & 0 deletions noTitleBar-Terminal.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// noTitleBar-Terminal.m
// noTitleBar-Terminal
//
// Created by Enrico "cHoco" Ghirardi on 23/12/15.
// Copyright (c) 2015 cHoco. All rights reserved.
//

#import "noTitleBar-Terminal.h"
#import "JRSwizzle/JRSwizzle.h"
#import <objc/objc-class.h>

@implementation noTitleBarTerminal

+ (void)load {
[NSClassFromString(@"TTWindow")
jr_swizzleMethod:@selector(initWithContentRect:styleMask:backing:defer:)
withMethod:@selector(noTitleBar_initWithContentRect:styleMask:backing:defer:)
error:NULL];
[NSClassFromString(@"TTWindow")
jr_swizzleMethod:@selector(canBecomeKeyWindow)
withMethod:@selector(noTitleBar_canBecomeKeyWindow)
error:NULL];
[NSClassFromString(@"TTWindow")
jr_swizzleMethod:@selector(canBecomeMainWindow)
withMethod:@selector(noTitleBar_canBecomeMainWindow)
error:NULL];
[NSClassFromString(@"TTWindow")
jr_swizzleMethod:@selector(performClose:)
withMethod:@selector(noTitleBar_performClose:)
error:NULL];
[self updateWindows];
}

/*
* Remove the titlebars of already created windows, since our bundle will
* probably be loaded after the first window is created (SIMBL limitation)
*/
+ (void)updateWindows {
Class windowMetaClass = NSClassFromString(@"TTWindow");
Class applicationMetaClass = NSClassFromString(@"TTApplication");
id currentApp = [applicationMetaClass sharedApplication];
NSArray *windows = [currentApp windows];
for (id possibleWindow in windows) {
if ([possibleWindow isKindOfClass:windowMetaClass]) {
// This was a nightmare to debug... for some reason changing the
// styleMask of a window also changes the firstResponder, losing
// keyboard focus. We just save and restore it!
id savedResponder = [possibleWindow firstResponder];
[possibleWindow setStyleMask:(NSClosableWindowMask |
NSMiniaturizableWindowMask |
NSResizableWindowMask |
NSTexturedBackgroundWindowMask)];
[possibleWindow makeFirstResponder:savedResponder];
}
}
}

@end

@implementation NSWindow(TTWindow)

/*
* The 3 following methods must be added because Cocoa doesn't give focus and
* main window status if the window doesn't have a title bar.
* The first two are well documented around the web but the third one is
* necessary to keep Command-W shortucut to close a window since it's disabled
* without a titlebar
*/
- (BOOL)noTitleBar_canBecomeKeyWindow {
return YES;
}

- (BOOL)noTitleBar_canBecomeMainWindow {
return YES;
}

- (void)noTitleBar_performClose:(id)sender {
BOOL shouldClose = YES;

if ([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) {
shouldClose = [(id)[self delegate] windowShouldClose:sender];
}
if (shouldClose) {
[self close];
}
}

- (id)noTitleBar_initWithContentRect:(CGRect)rect
styleMask:(unsigned long long)style
backing:(unsigned long long)backing
defer:(char)defer
{
return [self noTitleBar_initWithContentRect:rect
styleMask:(NSClosableWindowMask |
NSMiniaturizableWindowMask |
NSResizableWindowMask |
NSTexturedBackgroundWindowMask)
backing:backing
defer:defer];
}

@end

0 comments on commit 8500d8b

Please sign in to comment.