]> git.saurik.com Git - fiveicondock.git/blob - FiveIconDock.mm
Support iOS 7.0.
[fiveicondock.git] / FiveIconDock.mm
1 #include <CydiaSubstrate/CydiaSubstrate.h>
2
3 %apt Package: com.saurik.iphone.fid
4 %apt Author: Jay Freeman (saurik) <saurik@saurik.com>
5
6 %apt Name: Five Icon Dock
7 %apt Description: fits even more stuff right down there
8 %apt Depiction: http://cydia.saurik.com/info/com.saurik.iphone.fid/
9 %apt Tag: purpose::extension, role::enduser
10
11 %apt Depends: mobilesubstrate (>= 0.9.3005-1), firmware (>= 2.2), firmware (<< 3.0) | com.chpwn.iconsupport (>= 1.7.3-1)
12 %apt Conflicts: gsc.wildcat
13
14 %bundle com.apple.springboard
15
16 %flag -framework Foundation
17
18 #import <Foundation/NSArray.h>
19 #import <Foundation/NSAutoreleasePool.h>
20 #import <Foundation/NSNull.h>
21
22 #import <CoreGraphics/CGGeometry.h>
23
24 @interface ISIconSupport : NSObject {
25 }
26
27 + (ISIconSupport *) sharedInstance;
28 - (void) addExtension:(NSString *)name;
29
30 @end
31
32 @interface SBDockIconListView : NSObject {
33 }
34 - (NSArray *) icons;
35 @end
36
37 MSClassHook(SBButtonBar)
38 MSClassHook(SBDockIconListView)
39 MSClassHook(SBIcon)
40 MSClassHook(SBIconModel)
41
42 MSMetaClassHook(SBDockIconListView)
43 MSMetaClassHook(SBIconModel)
44
45 __attribute__((__constructor__))
46 static void MSFixClass() {
47 if ($SBIcon == nil)
48 $SBIcon = objc_getClass("SBIconView");
49 }
50
51 MSInstanceMessageHook1(float, SBButtonBar, leftMarginForIconRowArray, NSArray *, row) {
52 return [row indexOfObject:[NSNull null]] == NSNotFound ? 4 : MSOldCall(row);
53 }
54
55 MSInstanceMessageHook0(int, SBButtonBar, maxIconColumns) {
56 return 5;
57 }
58
59 MSClassMessageHook1(NSUInteger, SBDockIconListView, iconColumnsForInterfaceOrientation, NSInteger, orientation) {
60 return 5;
61 }
62
63 static unsigned $SBButtonBar$count(SBButtonBar *self) {
64 MSIvarHook(NSArray *, _iconMatrix);
65 NSArray *row([_iconMatrix objectAtIndex:0]);
66 unsigned count(0);
67 for (id icon in row)
68 if (icon != [NSNull null])
69 ++count;
70 return count;
71 }
72
73 MSInstanceMessageHook0(float, SBButtonBar, topIconPadding) {
74 return 313370 + $SBButtonBar$count(self);
75 }
76
77 MSInstanceMessageHook1(void, SBIcon, setOrigin, CGPoint, origin) {
78 unsigned count(origin.y);
79 if (count < 313370)
80 goto set;
81 count -= 313370;
82
83 if (count > 40)
84 origin.x = 256;
85 else if (count > 10 || count < 0)
86 goto set;
87 else if (count == 5)
88 origin.x = (origin.x - 4) / 76 * 63 + 4;
89
90 origin.y = 11;
91 set:
92 MSOldCall(origin);
93 }
94
95 MSInstanceMessageHook2(CGPoint, SBButtonBar, originForIconAtX,Y, int, x, int, y) {
96 CGPoint origin;//(MSOldCall(x, y, ));
97 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
98 origin.y = 11;
99
100 unsigned count($SBButtonBar$count(self)), gap;
101 unsigned space(320 - 60 * count);
102
103 if (count >= 4)
104 gap = space / (count + 1);
105 else // I hate people who love Apple.
106 gap = 16;
107
108 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
109
110 return origin;
111 }
112
113 // XXX: merge with previous function if possible, but not until after iPhone 4
114 MSInstanceMessageHook2(CGPoint, SBDockIconListView, originForIconAtX,Y, int, x, int, y) {
115 CGPoint origin;//(MSOldCall(x, y, ));
116 //NSLog(@"f:%u,%u=(%f,%f)", x, y, origin.x, origin.y);
117 origin.y = 11;
118
119 unsigned count([[self icons] count]), gap;
120 unsigned space(320 - 60 * count);
121
122 if (count >= 4)
123 gap = space / (count + 1);
124 else // I hate people who love Apple.
125 gap = 16;
126
127 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * x;
128
129 return origin;
130 }
131
132 // XXX: merge with previous functions if possible, but not until after iPhone 5S ;P
133 MSInstanceMessage1(CGPoint, SBDockIconListView, originForIconAtIndex, NSInteger, index) {
134 CGPoint origin(MSOldCall(0));
135
136 unsigned count([[self icons] count]), gap;
137 unsigned space(320 - 60 * count);
138
139 if (count >= 4)
140 gap = space / (count + 1);
141 else // I hate people who love Apple.
142 gap = 16;
143
144 origin.x = (space - gap * (count - 1)) / 2 + (60 + gap) * index;
145
146 return origin;
147 }
148
149 MSInitialize {
150 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
151
152 if (dlopen("/Library/MobileSubstrate/DynamicLibraries/IconSupport.dylib", RTLD_GLOBAL | RTLD_LAZY) != NULL)
153 if (Class $ISIconSupport = objc_getClass("ISIconSupport"))
154 [[$ISIconSupport sharedInstance] addExtension:@"com.saurik.iphone.fid"];
155
156 if (kCFCoreFoundationVersionNumber >= 800)
157 MSHookMessage($SBDockIconListView, @selector(originForIconAtIndex:), MSHake(SBDockIconListView$originForIconAtIndex$));
158
159 [pool release];
160 }