]> git.saurik.com Git - winterboard.git/blobdiff - Library.mm
Add an IconAlpha fix from NickF.
[winterboard.git] / Library.mm
index a55c7d1c5c8d1c12ccafddb1aa58f20dc42ab358..b36ec0f68686df54e137435f9380b16c950458d7 100644 (file)
@@ -101,6 +101,8 @@ bool _itv;
 
 #import <ChatKit/CKMessageCell.h>
 
+#include <sys/sysctl.h>
+
 extern "C" void __clear_cache (char *beg, char *end);
 
 @protocol WinterBoard
@@ -135,6 +137,7 @@ Class $SBIconController;
 Class $SBIconLabel;
 Class $SBIconList;
 Class $SBIconModel;
+Class $SBIconView;
 //Class $SBImageCache;
 Class $SBSearchView;
 Class $SBSearchTableViewCell;
@@ -145,6 +148,8 @@ Class $SBStatusBarTimeView;
 Class $SBUIController;
 Class $SBWidgetApplicationIcon;
 
+#define SBIconView SBIcon
+
 static bool IsWild_;
 static bool Four_;
 
@@ -476,7 +481,7 @@ MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
 MSHook(UIImage *, SBApplicationIcon$generateIconImage$, SBApplicationIcon *self, SEL sel, int type) {
     if (type == 2)
         if (![Info_ wb$boolForKey:@"ComposeStoreIcons"]) {
-            if (IsWild_)
+            if (IsWild_ && false) // XXX: delete this code, it should not be supported
                 if (NSString *path72 = $pathForIcon$([self application], @"-72"))
                     return [UIImage imageWithContentsOfFile:path72];
             if (NSString *path = $pathForIcon$([self application]))
@@ -773,8 +778,31 @@ MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
     if (self == nil)
         return nil;
 
-    UIDevice *device([UIDevice currentDevice]);
-    IsWild_ = [device respondsToSelector:@selector(isWildcat)] && [device isWildcat];
+    {
+        size_t size;
+        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+        char *machine = new char[size];
+
+        if (sysctlbyname("hw.machine", machine, &size, NULL, 0) == -1) {
+            perror("sysctlbyname(\"hw.machine\", ?)");
+            delete [] machine;
+            machine = NULL;
+        }
+
+        IsWild_ = machine != NULL && strncmp(machine, "iPad", 4) == 0;
+    }
+
+    BOOL (*GSSystemHasCapability)(CFStringRef) = reinterpret_cast<BOOL (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemHasCapability"));
+
+    if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
+        [Info_ setObject:[NSNumber numberWithBool:(
+            !(Papered_ || GSSystemHasCapability != NULL && GSSystemHasCapability(CFSTR("homescreen-wallpaper"))) ||
+            [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
+            [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
+        )] forKey:@"UndockedIconLabels"];
+
+    if (Debug_)
+        NSLog(@"WB:Debug:Info = %@", [Info_ description]);
 
     if (Papered_) {
         UIImageView *&_wallpaperView(MSHookIvar<UIImageView *>(self, "_wallpaperView"));
@@ -1068,6 +1096,29 @@ WBDelegate(badge_)
 @end
 /* }}} */
 
+MSHook(void, SBIconView$setIconImageAlpha$, SBIconView *self, SEL sel, float alpha) {
+    if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
+        alpha = [number floatValue];
+    return _SBIconView$setIconImageAlpha$(self, sel, alpha);
+}
+
+MSHook(void, SBIconView$setIconLabelAlpha$, SBIconView *self, SEL sel, float alpha) {
+    if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
+        alpha = [number floatValue];
+    return _SBIconView$setIconLabelAlpha$(self, sel, alpha);
+}
+
+MSHook(id, SBIconView$initWithDefaultSize, SBIconView *self, SEL sel) {
+    if ((self = _SBIconView$initWithDefaultSize(self, sel)) != nil) {
+        if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"]) {
+            // XXX: note: this is overridden above, which is silly
+            float alpha([number floatValue]);
+            [self setIconImageAlpha:alpha];
+            [self setIconLabelAlpha:alpha];
+        }
+    } return self;
+}
+
 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
     if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
         alpha = [number floatValue];
@@ -1394,6 +1445,8 @@ MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *sel
 MSHook(UIImage *, _UIImageWithName, NSString *name) {
     if (Debug_)
         NSLog(@"WB:Debug: _UIImageWithName(\"%@\")", name);
+    if (name == nil)
+        return nil;
 
     int identifier;
     bool packed;
@@ -1717,12 +1770,16 @@ extern "C" void WBInitialize() {
 
         $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
 
+        bool olden(dlsym(RTLD_DEFAULT, "GSLibraryCopyGenerationInfoValueForKey") == NULL);
+
+        if (olden)
+            $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
+
         $SBApplication = objc_getClass("SBApplication");
         $SBApplicationIcon = objc_getClass("SBApplicationIcon");
         $SBAwayView = objc_getClass("SBAwayView");
         $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
         $SBButtonBar = objc_getClass("SBButtonBar");
-        $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
         $SBDockIconListView = objc_getClass("SBDockIconListView");
         $SBIcon = objc_getClass("SBIcon");
         $SBIconBadge = objc_getClass("SBIconBadge");
@@ -1730,6 +1787,7 @@ extern "C" void WBInitialize() {
         $SBIconLabel = objc_getClass("SBIconLabel");
         $SBIconList = objc_getClass("SBIconList");
         $SBIconModel = objc_getClass("SBIconModel");
+        $SBIconView = objc_getClass("SBIconView");
         //$SBImageCache = objc_getClass("SBImageCache");
         $SBSearchView = objc_getClass("SBSearchView");
         $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
@@ -1740,6 +1798,9 @@ extern "C" void WBInitialize() {
         $SBUIController = objc_getClass("SBUIController");
         $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
 
+        if ($SBIconView == nil)
+            $SBIconView = $SBIcon;
+
         Four_ = $SBDockIconListView != nil;
 
         WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
@@ -1756,13 +1817,18 @@ extern "C" void WBInitialize() {
         WBRename(SBIcon, setAlpha:, setAlpha$);
         WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
         WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
+        WBRename(SBIconView, initWithDefaultSize, initWithDefaultSize);
+        WBRename(SBIconView, setIconImageAlpha:, setIconImageAlpha$);
+        WBRename(SBIconView, setIconLabelAlpha:, setIconLabelAlpha$);
         WBRename(SBUIController, init, init);
         WBRename(SBWidgetApplicationIcon, icon, icon);
 
         WBRename(SBDockIconListView, setFrame:, setFrame$);
         MSHookMessage(object_getClass($SBDockIconListView), @selector(shouldShowNewDock), &$SBDockIconListView$shouldShowNewDock, &_SBDockIconListView$shouldShowNewDock);
 
-        WBRename(SBIconLabel, drawRect:, drawRect$);
+        if (olden)
+            WBRename(SBIconLabel, drawRect:, drawRect$);
+
         WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
         WBRename(SBIconLabel, setInDock:, setInDock$);
 
@@ -1801,15 +1867,5 @@ extern "C" void WBInitialize() {
 
     Docked_ = $getTheme$([NSArray arrayWithObjects:@"Dock.png", nil]);
 
-    if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
-        [Info_ setObject:[NSNumber numberWithBool:(
-            !Papered_ ||
-            [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
-            [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
-        )] forKey:@"UndockedIconLabels"];
-
-    if (Debug_)
-        NSLog(@"WB:Debug:Info = %@", [Info_ description]);
-
     [pool release];
 }