diff --git a/five-icon-switcher/Makefile b/five-icon-switcher/Makefile new file mode 100644 index 0000000..d34e8d2 --- /dev/null +++ b/five-icon-switcher/Makefile @@ -0,0 +1,6 @@ +TWEAK_NAME = fis +fis_OBJCC_FILES = Tweak.mm +fis_FRAMEWORKS = UIKit QuartzCore CoreGraphics + +include framework/makefiles/common.mk +include framework/makefiles/tweak.mk diff --git a/five-icon-switcher/Tweak.xm b/five-icon-switcher/Tweak.xm new file mode 100644 index 0000000..677da95 --- /dev/null +++ b/five-icon-switcher/Tweak.xm @@ -0,0 +1,81 @@ + +#import +#import + +#define idForKeyWithDefault(dict, key, default) ([(dict) objectForKey:(key)]?:(default)) +#define floatForKeyWithDefault(dict, key, default) ({ id _result = [(dict) objectForKey:(key)]; (_result)?[_result floatValue]:(default); }) +#define NSIntegerForKeyWithDefault(dict, key, default) (NSInteger)({ id _result = [(dict) objectForKey:(key)]; (_result)?[_result integerValue]:(default); }) +#define BOOLForKeyWithDefault(dict, key, default) (BOOL)({ id _result = [(dict) objectForKey:(key)]; (_result)?[_result boolValue]:(default); }) + +#define PreferencesFilePath [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Preferences/com.chpwn.five-icon-switcher.plist"] +#define PreferencesChangedNotification "com.chpwn.five-icon-switcher.prefs" + +#define GetPreference(name, type) type ## ForKeyWithDefault(prefsDict, @#name, (name)) + +@interface SBAppSwitcherBarView : UIView { } ++ (unsigned)iconsPerPage:(int)page; +- (CGPoint)_firstPageOffset; +- (CGPoint)_firstPageOffset:(CGSize)size; +- (CGRect)_frameForIndex:(unsigned)index withSize:(CGSize)size; +- (CGRect)_iconFrameForIndex:(unsigned)index withSize:(CGSize)size; +@end + +static NSDictionary *prefsDict = nil; + +static void preferenceChangedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { + [prefsDict release]; + prefsDict = [[NSDictionary alloc] initWithContentsOfFile:PreferencesFilePath]; +} + +CGRect make_frame(SBAppSwitcherBarView *self, int index, CGSize size, CGRect orig) { + CGRect r = orig; + + int page = index / [[self class] iconsPerPage:0]; + CGFloat gap = ([self frame].size.width - (r.size.width * [[self class] iconsPerPage:0])) / ([[self class] iconsPerPage:0] + 1); + r.origin.x = gap; + + if ([self respondsToSelector:@selector(_firstPageOffset)]) r.origin.x += [self _firstPageOffset].x; + else r.origin.x += [self _firstPageOffset:[self frame].size].x; + r.origin.x += (gap + size.width) * index; + r.origin.x += (gap * page); + r.origin.x = floorf(r.origin.x); + + return r; +} + +%hook SBAppSwitcherBarView + ++ (unsigned int)iconsPerPage:(int)page { + return [[prefsDict objectForKey:@"FISIconCount"] intValue] ?: 5; +} + +// 4.0 and 4.1 +- (CGRect)_frameForIndex:(unsigned)index withSize:(CGSize)size { + return make_frame(self, index, size, %orig); +} + +- (CGPoint)_firstPageOffset:(CGSize)offset { + %log; + return %orig; +} + +// 4.2 +- (CGRect)_iconFrameForIndex:(unsigned)index withSize:(CGSize)size { + return make_frame(self, index, size, %orig); +} + + +%end + +__attribute__((constructor)) static void fis_init() { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + // SpringBoard only! + if (![[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.springboard"]) + return; + + prefsDict = [[NSDictionary alloc] initWithContentsOfFile:PreferencesFilePath]; + CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, preferenceChangedCallback, CFSTR(PreferencesChangedNotification), NULL, CFNotificationSuspensionBehaviorCoalesce); + + [pool release]; +} diff --git a/five-icon-switcher/fiveiconswitcher.png b/five-icon-switcher/fiveiconswitcher.png new file mode 100644 index 0000000..5ab4dc3 Binary files /dev/null and b/five-icon-switcher/fiveiconswitcher.png differ diff --git a/five-icon-switcher/layout/DEBIAN/control b/five-icon-switcher/layout/DEBIAN/control new file mode 100644 index 0000000..228d610 --- /dev/null +++ b/five-icon-switcher/layout/DEBIAN/control @@ -0,0 +1,10 @@ +Package: com.chpwn.five-icon-switcher +Name: Five Icon Switcher +Pre-Depends: firmware (>= 4.0) +Depends: mobilesubstrate +Version: 1.1 +Architecture: iphoneos-arm +Description: Five icons in the multitasking switcher! +Maintainer: chpwn +Author: chpwn +Section: Tweaks diff --git a/five-icon-switcher/layout/Library/MobileSubstrate/DynamicLibraries/fis.plist b/five-icon-switcher/layout/Library/MobileSubstrate/DynamicLibraries/fis.plist new file mode 100644 index 0000000..92bd284 --- /dev/null +++ b/five-icon-switcher/layout/Library/MobileSubstrate/DynamicLibraries/fis.plist @@ -0,0 +1,3 @@ +Filter = { + Bundles = (com.apple.springboard); +}; \ No newline at end of file diff --git a/five-icon-switcher/layout/Library/PreferenceLoader/Preferences/five-icon-switcher.plist b/five-icon-switcher/layout/Library/PreferenceLoader/Preferences/five-icon-switcher.plist new file mode 100644 index 0000000..7225f4c --- /dev/null +++ b/five-icon-switcher/layout/Library/PreferenceLoader/Preferences/five-icon-switcher.plist @@ -0,0 +1,114 @@ + + + + + title + Five Icon Switcher + entry + + cell + PSLinkCell + icon + five-icon-switcher.png + label + Five Icon Switcher + + items + + + cell + PSGroupCell + label + Five Icon Switcher + + + cell + PSLinkListCell + default + 5 + detail + PSListItemsController + key + FISIconCount + label + Icons per Page + validTitles + + One + Two + Three + Four + Five + Six + Seven + Eight + Nine + Ten + + validValues + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + + defaults + com.chpwn.five-icon-switcher + PostNotification + com.chpwn.five-icon-switcher.prefs + + + + + cell + PSGroupCell + footerText + Five Icon Switcher © 2010 Grant Paul. + +Licensed under the BSD license at http://github.com/chpwn/five-icon-switcher. +All contributions are welcome. + + + cell + PSGroupCell + isStaticText + true + requiredCapabilities + + + wildcat + + voip + + + + + + cell + PSTitleValueCell + label + Five Icon Switcher © 2010 Grant Paul. + +Licensed under the BSD license at http://github.com/chpwn/five-icon-switcher. +All contributions are welcome. + requiredCapabilities + + + wildcat + + voip + + + + + + + + + diff --git a/five-icon-switcher/layout/Library/PreferenceLoader/Preferences/five-icon-switcher.png b/five-icon-switcher/layout/Library/PreferenceLoader/Preferences/five-icon-switcher.png new file mode 100644 index 0000000..64f208c Binary files /dev/null and b/five-icon-switcher/layout/Library/PreferenceLoader/Preferences/five-icon-switcher.png differ