]> git.saurik.com Git - fiveicondock.git/blob - Tweak.mm
28e7ebb95ea608750a4f047540c866ddf2e4fb65
[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 MSHookClass(SBButtonBar)
11 MSHookClass(SBIcon)
12 MSHookClass(SBIconModel)
13
14 MSHookMetaClass(SBIconModel)
15
16 MSMessageHook1(float, SBButtonBar, leftMarginForIconRowArray, NSArray *row) {
17 return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : MSCall1(SBButtonBar, leftMarginForIconRowArray, row);
18 }
19
20 MSMessageHook0(int, SBButtonBar, maxIconColumns) {
21 return 10;
22 }
23
24 static unsigned $SBButtonBar$count(SBButtonBar *self) {
25 MSIvar(NSArray *, _iconMatrix);
26 NSArray *row([_iconMatrix objectAtIndex:0]);
27 unsigned count(0);
28 for (id icon in row)
29 if (icon != [NSNull null])
30 ++count;
31 return count;
32 }
33
34 MSMessageHook0(float, SBButtonBar, topIconPadding) {
35 return 313370 + $SBButtonBar$count(self);
36 }
37
38 MSMessageHook1(void, SBIcon, setOrigin, CGPoint origin) {
39 unsigned count(origin.y);
40 if (count < 313370)
41 goto set;
42 count -= 313370;
43
44 if (count > 40)
45 origin.x = 256;
46 else if (count > 10 || count < 0)
47 goto set;
48 else if (count == 5)
49 origin.x = (origin.x - 4) / 76 * 63 + 4;
50
51 origin.y = 11;
52 set:
53 MSCall1(SBIcon, setOrigin, origin);
54 }
55
56 MSMessageHook2(CGPoint, SBButtonBar, originForIconAtX,Y, int x, int y) {
57 CGPoint origin;//(_SBButtonBar$originForIconAtX$Y$(self, _cmd, x, y));
58 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
59 origin.y = 11;
60
61 unsigned count($SBButtonBar$count(self)), gap;
62 unsigned space(320 - 60 * count);
63
64 if (count >= 4)
65 gap = space / (count + 1);
66 else // I hate people who love Apple.
67 gap = 16;
68
69 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
70
71 return origin;
72 }
73
74 MSMetaMessageHook0(int, SBIconModel, maxIconListCount) {
75 return 16;
76 }