#import <SpringBoard/SBButtonBar.h>
#import <SpringBoard/SBIcon.h>
-@protocol Tweak
-- (float) fid_leftMarginForIconRowArray:(NSArray *)row;
-- (void) fid_setOrigin:(CGPoint)origin;
-- (float) fid_topIconPadding;
-@end
-
-static bool $SBButtonBar$$isCrowded(SBButtonBar<Tweak> *self) {
- NSArray *matrix;
- object_getInstanceVariable(self, "_iconMatrix", reinterpret_cast<void **>(&matrix));
- NSArray *row([matrix objectAtIndex:0]);
- return row != nil && [row indexOfObject:[NSNull null]] == NSNotFound;
-}
-
-static float $SBButtonBar$leftMarginForIconRowArray$(SBButtonBar<Tweak> *self, SEL sel, NSArray *row) {
- return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : [self fid_leftMarginForIconRowArray:row];
+MSHook(float, SBButtonBar$leftMarginForIconRowArray$, SBButtonBar *self, SEL sel, NSArray *row) {
+ return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : _SBButtonBar$leftMarginForIconRowArray$(self, sel, row);
}
-static int $SBButtonBar$maxIconColumns(SBButtonBar<Tweak> *self, SEL sel) {
+static int $SBButtonBar$maxIconColumns(SBButtonBar *self, SEL sel) {
return 5;
}
-static float $SBButtonBar$topIconPadding(SBButtonBar<Tweak> *self, SEL sel) {
- float padding([self fid_topIconPadding]);
- if ($SBButtonBar$$isCrowded(self))
- --padding;
- return padding;
+static unsigned $SBButtonBar$count(SBButtonBar *self) {
+ NSArray *&_iconMatrix(MSHookIvar<NSArray *>(self, "_iconMatrix"));
+ NSArray *row([_iconMatrix objectAtIndex:0]);
+ unsigned count(0);
+ for (id icon in row)
+ if (icon != [NSNull null])
+ ++count;
+ return count;
}
-static float $SBButtonBar$verticalIconPadding(SBButtonBar<Tweak> *self, SEL sel) {
- return 0;
+static float $SBButtonBar$topIconPadding(SBButtonBar *self, SEL sel) {
+ return $SBButtonBar$count(self);
}
-static void $SBIcon$setOrigin$(SBIcon<Tweak> *self, SEL sel, CGPoint origin) {
- if (origin.y == 10)
- origin.x = (origin.x - 4) / 76 * 63 + 4;
- else if (origin.y == 84) {
- origin.y -= 74;
+MSHook(void, SBIcon$setOrigin$, SBIcon *self, SEL sel, CGPoint origin) {
+ unsigned count(origin.y);
+ //NSLog(@"C:%u=(%f,%f)", count, origin.x, origin.y);
+
+ if (count < 90 && count > 40)
origin.x = 256;
- } else goto set;
- ++origin.y;
+ else if (count > 10 || count < 0)
+ goto set;
+ else if (count == 5)
+ origin.x = (origin.x - 4) / 76 * 63 + 4;
+
+ origin.y = 11;
set:
- [self fid_setOrigin:origin];
+ _SBIcon$setOrigin$(self, sel, origin);
}
-extern "C" void TweakInitialize() {
- if (objc_getClass("SpringBoard") == nil)
- return;
+MSHook(CGPoint, SBButtonBar$originForIconAtX$Y$, SBButtonBar *self, SEL sel, int x, int y) {
+ CGPoint origin;//(_SBButtonBar$originForIconAtX$Y$(self, sel, x, y));
+ //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
+ origin.y = 11;
+
+ unsigned count($SBButtonBar$count(self)), gap;
+ unsigned space(320 - 60 * count);
+
+ if (count >= 4)
+ gap = space / (count + 1);
+ else // I hate people who love Apple.
+ gap = 16;
+
+ origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
+ return origin;
+}
+
+extern "C" void TweakInitialize() {
Class $SBButtonBar(objc_getClass("SBButtonBar"));
- MSHookMessage($SBButtonBar, @selector(leftMarginForIconRowArray:), (IMP) &$SBButtonBar$leftMarginForIconRowArray$, "fid_");
- MSHookMessage($SBButtonBar, @selector(maxIconColumns), (IMP) &$SBButtonBar$maxIconColumns, "fid_");
- MSHookMessage($SBButtonBar, @selector(topIconPadding), (IMP) &$SBButtonBar$topIconPadding, "fid_");
- MSHookMessage($SBButtonBar, @selector(verticalIconPadding), (IMP) &$SBButtonBar$verticalIconPadding, "fid_");
+ _SBButtonBar$leftMarginForIconRowArray$ = MSHookMessage($SBButtonBar, @selector(leftMarginForIconRowArray:), &$SBButtonBar$leftMarginForIconRowArray$);
+ MSHookMessage($SBButtonBar, @selector(maxIconColumns), &$SBButtonBar$maxIconColumns);
+ MSHookMessage($SBButtonBar, @selector(topIconPadding), &$SBButtonBar$topIconPadding);
+ _SBButtonBar$originForIconAtX$Y$ = MSHookMessage($SBButtonBar, @selector(originForIconAtX:Y:), &$SBButtonBar$originForIconAtX$Y$);
Class $SBIcon(objc_getClass("SBIcon"));
- MSHookMessage($SBIcon, @selector(setOrigin:), (IMP) $SBIcon$setOrigin$, "fid_");
+ _SBIcon$setOrigin$ = MSHookMessage($SBIcon, @selector(setOrigin:), &$SBIcon$setOrigin$);
}