Skip to content

Commit

Permalink
Add five icon switcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
grp committed Sep 24, 2011
1 parent a9e3df9 commit 925e46b
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 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
81 changes: 81 additions & 0 deletions five-icon-switcher/Tweak.xm
@@ -0,0 +1,81 @@

#import <SpringBoard/SpringBoard.h>
#import <UIKit/UIKit.h>

#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];
}
Binary file added five-icon-switcher/fiveiconswitcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions 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
@@ -0,0 +1,3 @@
Filter = {
Bundles = (com.apple.springboard);
};
@@ -0,0 +1,114 @@
<?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>title</key>
<string>Five Icon Switcher</string>
<key>entry</key>
<dict>
<key>cell</key>
<string>PSLinkCell</string>
<key>icon</key>
<string>five-icon-switcher.png</string>
<key>label</key>
<string>Five Icon Switcher</string>
</dict>
<key>items</key>
<array>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Five Icon Switcher</string>
</dict>
<dict>
<key>cell</key>
<string>PSLinkListCell</string>
<key>default</key>
<integer>5</integer>
<key>detail</key>
<string>PSListItemsController</string>
<key>key</key>
<string>FISIconCount</string>
<key>label</key>
<string>Icons per Page</string>
<key>validTitles</key>
<array>
<string>One</string>
<string>Two</string>
<string>Three</string>
<string>Four</string>
<string>Five</string>
<string>Six</string>
<string>Seven</string>
<string>Eight</string>
<string>Nine</string>
<string>Ten</string>
</array>
<key>validValues</key>
<array>
<integer>1</integer>
<integer>2</integer>
<integer>3</integer>
<integer>4</integer>
<integer>5</integer>
<integer>6</integer>
<integer>7</integer>
<integer>8</integer>
<integer>9</integer>
<integer>10</integer>
</array>
<key>defaults</key>
<string>com.chpwn.five-icon-switcher</string>
<key>PostNotification</key>
<string>com.chpwn.five-icon-switcher.prefs</string>
</dict>

<!-- Begin static text. -->
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>footerText</key>
<string>Five Icon Switcher © 2010 Grant Paul.
Licensed under the BSD license at http://github.com/chpwn/five-icon-switcher.
All contributions are welcome.</string>
</dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>isStaticText</key>
<string>true</string>
<key>requiredCapabilities</key>
<array>
<dict>
<key>wildcat</key>
<false/>
<key>voip</key>
<false/>
</dict>
</array>
</dict>
<dict>
<key>cell</key>
<string>PSTitleValueCell</string>
<key>label</key>
<string>Five Icon Switcher © 2010 Grant Paul.
Licensed under the BSD license at http://github.com/chpwn/five-icon-switcher.
All contributions are welcome.</string>
<key>requiredCapabilities</key>
<array>
<dict>
<key>wildcat</key>
<false/>
<key>voip</key>
<false/>
</dict>
</array>
</dict>
<!-- End static text. -->

</array>
</dict>
</plist>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 925e46b

Please sign in to comment.