]> git.saurik.com Git - fiveicondock.git/blob - Tweak.mm
Support IconSupport and iOS 5.0.
[fiveicondock.git] / Tweak.mm
1 #include <substrate.h>
2
3 #import <Foundation/NSArray.h>
4 #import <Foundation/NSAutoreleasePool.h>
5 #import <Foundation/NSNull.h>
6
7 #import <CoreGraphics/CGGeometry.h>
8
9 #import <SpringBoard/SBButtonBar.h>
10 #import <SpringBoard/SBIcon.h>
11 #import <SpringBoard/SBIconModel.h>
12
13 @interface ISIconSupport : NSObject {
14 }
15
16 + (ISIconSupport *) sharedInstance;
17 - (void) addExtension:(NSString *)name;
18
19 @end
20
21 @interface SBDockIconListView : NSObject {
22 }
23 - (NSArray *) icons;
24 @end
25
26 MSClassHook(SBButtonBar)
27 MSClassHook(SBDockIconListView)
28 MSClassHook(SBIcon)
29 MSClassHook(SBIconModel)
30
31 MSMetaClassHook(SBDockIconListView)
32 MSMetaClassHook(SBIconModel)
33
34 __attribute__((__constructor__))
35 static void MSFixClass() {
36 if ($SBIcon == nil)
37 $SBIcon = objc_getClass("SBIconView");
38 }
39
40 MSInstanceMessageHook1(float, SBButtonBar, leftMarginForIconRowArray, NSArray *, row) {
41 return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : MSOldCall(row);
42 }
43
44 MSInstanceMessageHook0(int, SBButtonBar, maxIconColumns) {
45 return 5;
46 }
47
48 MSClassMessageHook1(int, SBDockIconListView, iconColumnsForInterfaceOrientation, int, orientation) {
49 return 5;
50 }
51
52 static unsigned $SBButtonBar$count(SBButtonBar *self) {
53 MSIvarHook(NSArray *, _iconMatrix);
54 NSArray *row([_iconMatrix objectAtIndex:0]);
55 unsigned count(0);
56 for (id icon in row)
57 if (icon != [NSNull null])
58 ++count;
59 return count;
60 }
61
62 MSInstanceMessageHook0(float, SBButtonBar, topIconPadding) {
63 return 313370 + $SBButtonBar$count(self);
64 }
65
66 MSInstanceMessageHook1(void, SBIcon, setOrigin, CGPoint, origin) {
67 unsigned count(origin.y);
68 if (count < 313370)
69 goto set;
70 count -= 313370;
71
72 if (count > 40)
73 origin.x = 256;
74 else if (count > 10 || count < 0)
75 goto set;
76 else if (count == 5)
77 origin.x = (origin.x - 4) / 76 * 63 + 4;
78
79 origin.y = 11;
80 set:
81 MSOldCall(origin);
82 }
83
84 MSInstanceMessageHook2(CGPoint, SBButtonBar, originForIconAtX,Y, int, x, int, y) {
85 CGPoint origin;//(MSOldCall(x, y, ));
86 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
87 origin.y = 11;
88
89 unsigned count($SBButtonBar$count(self)), gap;
90 unsigned space(320 - 60 * count);
91
92 if (count >= 4)
93 gap = space / (count + 1);
94 else // I hate people who love Apple.
95 gap = 16;
96
97 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
98
99 return origin;
100 }
101
102 // XXX: merge with previous function if possible, but not until after iPhone 4
103 MSInstanceMessageHook2(CGPoint, SBDockIconListView, originForIconAtX,Y, int, x, int, y) {
104 CGPoint origin;//(MSOldCall(x, y, ));
105 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
106 origin.y = 11;
107
108 unsigned count([[self icons] count]), gap;
109 unsigned space(320 - 60 * count);
110
111 if (count >= 4)
112 gap = space / (count + 1);
113 else // I hate people who love Apple.
114 gap = 16;
115
116 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
117
118 return origin;
119 }
120
121 /*MSClassMessageHook0(int, SBIconModel, maxIconListCount) {
122 return 16;
123 }*/
124
125 MSInitialize {
126 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
127
128 if (dlopen("/Library/MobileSubstrate/DynamicLibraries/IconSupport.dylib", RTLD_GLOBAL | RTLD_LAZY) != NULL)
129 if (Class $ISIconSupport = objc_getClass("ISIconSupport"))
130 [[$ISIconSupport sharedInstance] addExtension:@"com.saurik.iphone.fid"];
131
132 [pool release];
133 }