]>
Commit | Line | Data |
---|---|---|
b6ceaaff JF |
1 | #include <substrate.h> |
2 | ||
3 | #import <Foundation/NSArray.h> | |
4 | #import <Foundation/NSNull.h> | |
5 | #import <CoreGraphics/CGGeometry.h> | |
6 | #import <SpringBoard/SBButtonBar.h> | |
7 | #import <SpringBoard/SBIcon.h> | |
8 | ||
9 | @protocol Tweak | |
10 | - (float) fid_leftMarginForIconRowArray:(NSArray *)row; | |
11 | - (void) fid_setOrigin:(CGPoint)origin; | |
12 | - (float) fid_topIconPadding; | |
13 | @end | |
14 | ||
15 | static bool $SBButtonBar$$isCrowded(SBButtonBar<Tweak> *self) { | |
16 | NSArray *matrix; | |
17 | object_getInstanceVariable(self, "_iconMatrix", reinterpret_cast<void **>(&matrix)); | |
18 | NSArray *row([matrix objectAtIndex:0]); | |
19 | return row != nil && [row indexOfObject:[NSNull null]] == NSNotFound; | |
20 | } | |
21 | ||
22 | static float $SBButtonBar$leftMarginForIconRowArray$(SBButtonBar<Tweak> *self, SEL sel, NSArray *row) { | |
23 | return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : [self fid_leftMarginForIconRowArray:row]; | |
24 | } | |
25 | ||
26 | static int $SBButtonBar$maxIconColumns(SBButtonBar<Tweak> *self, SEL sel) { | |
27 | return 5; | |
28 | } | |
29 | ||
30 | static float $SBButtonBar$topIconPadding(SBButtonBar<Tweak> *self, SEL sel) { | |
31 | float padding([self fid_topIconPadding]); | |
32 | if ($SBButtonBar$$isCrowded(self)) | |
33 | --padding; | |
34 | return padding; | |
35 | } | |
36 | ||
37 | static float $SBButtonBar$verticalIconPadding(SBButtonBar<Tweak> *self, SEL sel) { | |
38 | return 0; | |
39 | } | |
40 | ||
41 | static void $SBIcon$setOrigin$(SBIcon<Tweak> *self, SEL sel, CGPoint origin) { | |
42 | if (origin.y == 10) | |
43 | origin.x = (origin.x - 4) / 76 * 63 + 4; | |
44 | else if (origin.y == 84) { | |
45 | origin.y -= 74; | |
46 | origin.x = 256; | |
47 | } else goto set; | |
48 | ++origin.y; | |
49 | set: | |
50 | [self fid_setOrigin:origin]; | |
51 | } | |
52 | ||
53 | extern "C" void TweakInitialize() { | |
54 | if (objc_getClass("SpringBoard") == nil) | |
55 | return; | |
56 | ||
57 | Class $SBButtonBar(objc_getClass("SBButtonBar")); | |
58 | MSHookMessage($SBButtonBar, @selector(leftMarginForIconRowArray:), (IMP) &$SBButtonBar$leftMarginForIconRowArray$, "fid_"); | |
59 | MSHookMessage($SBButtonBar, @selector(maxIconColumns), (IMP) &$SBButtonBar$maxIconColumns, "fid_"); | |
60 | MSHookMessage($SBButtonBar, @selector(topIconPadding), (IMP) &$SBButtonBar$topIconPadding, "fid_"); | |
61 | MSHookMessage($SBButtonBar, @selector(verticalIconPadding), (IMP) &$SBButtonBar$verticalIconPadding, "fid_"); | |
62 | ||
63 | Class $SBIcon(objc_getClass("SBIcon")); | |
64 | MSHookMessage($SBIcon, @selector(setOrigin:), (IMP) $SBIcon$setOrigin$, "fid_"); | |
65 | } |