From 56a24300ff1a54f6f7cdfca5a3cca9655f494285 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 4 Jun 2009 05:03:01 +0000 Subject: [PATCH] Welcome to iPhoneOS 3.x. --- Tweak.mm | 87 +++++++++++++++++++++++++++++------------------------ Tweak.plist | 1 + control | 2 +- 3 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 Tweak.plist diff --git a/Tweak.mm b/Tweak.mm index be19307..ad2f26f 100644 --- a/Tweak.mm +++ b/Tweak.mm @@ -6,60 +6,69 @@ #import #import -@protocol Tweak -- (float) fid_leftMarginForIconRowArray:(NSArray *)row; -- (void) fid_setOrigin:(CGPoint)origin; -- (float) fid_topIconPadding; -@end - -static bool $SBButtonBar$$isCrowded(SBButtonBar *self) { - NSArray *matrix; - object_getInstanceVariable(self, "_iconMatrix", reinterpret_cast(&matrix)); - NSArray *row([matrix objectAtIndex:0]); - return row != nil && [row indexOfObject:[NSNull null]] == NSNotFound; -} - -static float $SBButtonBar$leftMarginForIconRowArray$(SBButtonBar *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 *self, SEL sel) { +static int $SBButtonBar$maxIconColumns(SBButtonBar *self, SEL sel) { return 5; } -static float $SBButtonBar$topIconPadding(SBButtonBar *self, SEL sel) { - float padding([self fid_topIconPadding]); - if ($SBButtonBar$$isCrowded(self)) - --padding; - return padding; +static unsigned $SBButtonBar$count(SBButtonBar *self) { + NSArray *&_iconMatrix(MSHookIvar(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 *self, SEL sel) { - return 0; +static float $SBButtonBar$topIconPadding(SBButtonBar *self, SEL sel) { + return $SBButtonBar$count(self); } -static void $SBIcon$setOrigin$(SBIcon *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$); } diff --git a/Tweak.plist b/Tweak.plist new file mode 100644 index 0000000..f94fd41 --- /dev/null +++ b/Tweak.plist @@ -0,0 +1 @@ +Filter = {Bundles = ("com.apple.springboard");}; diff --git a/control b/control index 780c275..d60b28d 100644 --- a/control +++ b/control @@ -3,7 +3,7 @@ Priority: optional Section: Tweaks Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 0.9.2559-1 +Version: 0.9.2924-1 Description: fits even more stuff right down there Name: Five Icon Dock Depends: mobilesubstrate (>= 0.9.2555-1) -- 2.45.2