]> git.saurik.com Git - fiveicondock.git/blob - Tweak.mm
8e6a74d67471cd64b32717d47f2575c409a1d6d6
[fiveicondock.git] / Tweak.mm
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 #import <SpringBoard/SBIconModel.h>
9
10 MSHook(float, SBButtonBar$leftMarginForIconRowArray$, SBButtonBar *self, SEL sel, NSArray *row) {
11 return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : _SBButtonBar$leftMarginForIconRowArray$(self, sel, row);
12 }
13
14 static int $SBButtonBar$maxIconColumns(SBButtonBar *self, SEL sel) {
15 return 5;
16 }
17
18 static unsigned $SBButtonBar$count(SBButtonBar *self) {
19 NSArray *&_iconMatrix(MSHookIvar<NSArray *>(self, "_iconMatrix"));
20 NSArray *row([_iconMatrix objectAtIndex:0]);
21 unsigned count(0);
22 for (id icon in row)
23 if (icon != [NSNull null])
24 ++count;
25 return count;
26 }
27
28 static float $SBButtonBar$topIconPadding(SBButtonBar *self, SEL sel) {
29 return 313370 + $SBButtonBar$count(self);
30 }
31
32 MSHook(void, SBIcon$setOrigin$, SBIcon *self, SEL sel, CGPoint origin) {
33 unsigned count(origin.y);
34 if (count < 313370)
35 goto set;
36 count -= 313370;
37
38 if (count > 40)
39 origin.x = 256;
40 else if (count > 10 || count < 0)
41 goto set;
42 else if (count == 5)
43 origin.x = (origin.x - 4) / 76 * 63 + 4;
44
45 origin.y = 11;
46 set:
47 _SBIcon$setOrigin$(self, sel, origin);
48 }
49
50 MSHook(CGPoint, SBButtonBar$originForIconAtX$Y$, SBButtonBar *self, SEL sel, int x, int y) {
51 CGPoint origin;//(_SBButtonBar$originForIconAtX$Y$(self, sel, x, y));
52 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
53 origin.y = 11;
54
55 unsigned count($SBButtonBar$count(self)), gap;
56 unsigned space(320 - 60 * count);
57
58 if (count >= 4)
59 gap = space / (count + 1);
60 else // I hate people who love Apple.
61 gap = 16;
62
63 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
64
65 return origin;
66 }
67
68 static int $SBIconModel$maxIconListCount(SBIconModel *self, SEL sel) {
69 return 16;
70 }
71
72 extern "C" void TweakInitialize() {
73 Class $SBButtonBar(objc_getClass("SBButtonBar"));
74 MSHookMessage($SBButtonBar, @selector(leftMarginForIconRowArray:), MSHake(SBButtonBar$leftMarginForIconRowArray$));
75 MSHookMessage($SBButtonBar, @selector(maxIconColumns), &$SBButtonBar$maxIconColumns);
76 MSHookMessage($SBButtonBar, @selector(topIconPadding), &$SBButtonBar$topIconPadding);
77 MSHookMessage($SBButtonBar, @selector(originForIconAtX:Y:), MSHake(SBButtonBar$originForIconAtX$Y$));
78
79 Class $SBIcon(objc_getClass("SBIcon"));
80 MSHookMessage($SBIcon, @selector(setOrigin:), MSHake(SBIcon$setOrigin$));
81
82 Class $SBIconModel(objc_getClass("SBIconModel"));
83 Class $$SBIconModel(object_getClass($SBIconModel));
84 MSHookMessage($$SBIconModel, @selector(maxIconListCount), &$SBIconModel$maxIconListCount);
85 }