From 95cf70e82cd3b56d1249eabebbdff7566116ac87 Mon Sep 17 00:00:00 2001 From: inket Date: Sat, 21 Jul 2012 04:20:41 +0100 Subject: [PATCH] Initial commit --- LICENSE | 13 ++++++ README.md | 13 ++++++ cosyTabs.xcodeproj/project.pbxproj | 6 +++ cosyTabs/cosyTabs-Info.plist | 29 +++++-------- cosyTabs/cosyTabs.h | 13 ++++++ cosyTabs/cosyTabs.m | 65 ++++++++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 20 deletions(-) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 cosyTabs/cosyTabs.h create mode 100644 cosyTabs/cosyTabs.m diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..12630d9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright (C) 2012 inket + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See http://www.gnu.org/licenses/gpl-3.0.txt for details. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a30341 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +Safari 5 tabs on Safari 6, cosy. + +![Before](http://i.imgur.com/TBcMt.png) + +![After](http://i.imgur.com/Wo89C.png) + + +#### Known Issues +- Safari opens with Safari 6 tabs style before switching to the old style--because SIMBL waits for it to finish launching before injecting the plug-in. + + +#### License +This program is licensed under GNU GPL v3.0 (see LICENSE) \ No newline at end of file diff --git a/cosyTabs.xcodeproj/project.pbxproj b/cosyTabs.xcodeproj/project.pbxproj index c9aa953..fd6d4a0 100644 --- a/cosyTabs.xcodeproj/project.pbxproj +++ b/cosyTabs.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ B26DE59415B7871900EDFD3F /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B26DE59315B7871900EDFD3F /* CoreFoundation.framework */; }; B26DE59A15B7871900EDFD3F /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = B26DE59815B7871900EDFD3F /* InfoPlist.strings */; }; + B26DE5A315B78DC500EDFD3F /* cosyTabs.m in Sources */ = {isa = PBXBuildFile; fileRef = B26DE5A215B78DC500EDFD3F /* cosyTabs.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -17,6 +18,8 @@ B26DE59715B7871900EDFD3F /* cosyTabs-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "cosyTabs-Info.plist"; sourceTree = ""; }; B26DE59915B7871900EDFD3F /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; B26DE59B15B7871900EDFD3F /* cosyTabs-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "cosyTabs-Prefix.pch"; sourceTree = ""; }; + B26DE5A115B78DC500EDFD3F /* cosyTabs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cosyTabs.h; sourceTree = ""; }; + B26DE5A215B78DC500EDFD3F /* cosyTabs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = cosyTabs.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -60,6 +63,8 @@ isa = PBXGroup; children = ( B26DE59615B7871900EDFD3F /* Supporting Files */, + B26DE5A115B78DC500EDFD3F /* cosyTabs.h */, + B26DE5A215B78DC500EDFD3F /* cosyTabs.m */, ); path = cosyTabs; sourceTree = ""; @@ -136,6 +141,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + B26DE5A315B78DC500EDFD3F /* cosyTabs.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/cosyTabs/cosyTabs-Info.plist b/cosyTabs/cosyTabs-Info.plist index 5cefccc..4173598 100644 --- a/cosyTabs/cosyTabs-Info.plist +++ b/cosyTabs/cosyTabs-Info.plist @@ -22,25 +22,14 @@ ???? CFBundleVersion 1 - CFPlugInDynamicRegisterFunction - - CFPlugInDynamicRegistration - NO - CFPlugInFactories - - 00000000-0000-0000-0000-000000000000 - MyFactoryFunction - - CFPlugInTypes - - 00000000-0000-0000-0000-000000000000 - - 00000000-0000-0000-0000-000000000000 - - - CFPlugInUnloadFunction - - NSHumanReadableCopyright - Copyright © 2012 inket. All rights reserved. + NSPrincipalClass + cosyTabs + SIMBLTargetApplications + + + BundleIdentifier + com.apple.Safari + + diff --git a/cosyTabs/cosyTabs.h b/cosyTabs/cosyTabs.h new file mode 100644 index 0000000..82ca2a9 --- /dev/null +++ b/cosyTabs/cosyTabs.h @@ -0,0 +1,13 @@ +// +// cosyTabs.h +// cosyTabs +// +// Created by inket on 19/07/2012. +// Copyright (c) 2012 inket. Licensed under GNU GPL v3.0. See LICENSE for details. +// + +#import + +@interface cosyTabs : NSObject + +@end diff --git a/cosyTabs/cosyTabs.m b/cosyTabs/cosyTabs.m new file mode 100644 index 0000000..b4a7272 --- /dev/null +++ b/cosyTabs/cosyTabs.m @@ -0,0 +1,65 @@ +// +// cosyTabs.m +// cosyTabs +// +// Created by inket on 19/07/2012. +// Copyright (c) 2012 inket. Licensed under GNU GPL v3.0. See LICENSE for details. +// + +#import "cosyTabs.h" +#define MAX_TAB_WIDTH 250 // Maximum tab width in Safari 5 is 250px, amirite? + +static cosyTabs* plugin = nil; + +@implementation NSObject (cosyTabs) + +- (double)new_availableWidthForButtonsWhenUnclipped { + unsigned long long numberOfTabs = (unsigned long long)[self performSelector:@selector(numberOfTabs)]; + + double defaultAvailableWidth = [self new_availableWidthForButtonsWhenUnclipped]; + double customAvailableWidth = (double)(MAX_TAB_WIDTH*numberOfTabs); + + if (defaultAvailableWidth <= customAvailableWidth) + return defaultAvailableWidth; + + return customAvailableWidth; +} + +- (void)new_tabViewDidChangeNumberOfTabViewItems:(id)arg1 { + [self new_tabViewDidChangeNumberOfTabViewItems:arg1]; + + [self performSelector:@selector(refreshButtons)]; +} + +@end + + +@implementation cosyTabs + +#pragma mark SIMBL methods and loading + ++ (cosyTabs*)sharedInstance { + if (plugin == nil) + plugin = [[cosyTabs alloc] init]; + + return plugin; +} + ++ (void)load { + [[cosyTabs sharedInstance] loadPlugin]; + NSLog(@"cosyTabs loaded."); +} + +- (void)loadPlugin { + Class class = NSClassFromString(@"TabBarView"); + + Method new = class_getInstanceMethod(class, @selector(new_availableWidthForButtonsWhenUnclipped)); + Method old = class_getInstanceMethod(class, @selector(_availableWidthForButtonsWhenUnclipped)); + method_exchangeImplementations(new, old); + + new = class_getInstanceMethod(class, @selector(new_tabViewDidChangeNumberOfTabViewItems:)); + old = class_getInstanceMethod(class, @selector(tabViewDidChangeNumberOfTabViewItems:)); + method_exchangeImplementations(new, old); +} + +@end