]> git.saurik.com Git - winterboard.git/blobdiff - Library.mm
Add an IconAlpha fix from NickF.
[winterboard.git] / Library.mm
index 084ab9aee684db4f13e56d639bc80ad7537e6da7..b36ec0f68686df54e137435f9380b16c950458d7 100644 (file)
@@ -101,6 +101,8 @@ bool _itv;
 
 #import <ChatKit/CKMessageCell.h>
 
 
 #import <ChatKit/CKMessageCell.h>
 
+#include <sys/sysctl.h>
+
 extern "C" void __clear_cache (char *beg, char *end);
 
 @protocol WinterBoard
 extern "C" void __clear_cache (char *beg, char *end);
 
 @protocol WinterBoard
@@ -135,6 +137,7 @@ Class $SBIconController;
 Class $SBIconLabel;
 Class $SBIconList;
 Class $SBIconModel;
 Class $SBIconLabel;
 Class $SBIconList;
 Class $SBIconModel;
+Class $SBIconView;
 //Class $SBImageCache;
 Class $SBSearchView;
 Class $SBSearchTableViewCell;
 //Class $SBImageCache;
 Class $SBSearchView;
 Class $SBSearchTableViewCell;
@@ -145,6 +148,8 @@ Class $SBStatusBarTimeView;
 Class $SBUIController;
 Class $SBWidgetApplicationIcon;
 
 Class $SBUIController;
 Class $SBWidgetApplicationIcon;
 
+#define SBIconView SBIcon
+
 static bool IsWild_;
 static bool Four_;
 
 static bool IsWild_;
 static bool Four_;
 
@@ -773,12 +778,25 @@ MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
     if (self == nil)
         return nil;
 
     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:(
 
     if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
         [Info_ setObject:[NSNumber numberWithBool:(
-            !(Papered_ || GSSystemHasCapability(CFSTR("homescreen-wallpaper"))) ||
+            !(Papered_ || GSSystemHasCapability != NULL && GSSystemHasCapability(CFSTR("homescreen-wallpaper"))) ||
             [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
             [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
         )] forKey:@"UndockedIconLabels"];
             [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
             [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
         )] forKey:@"UndockedIconLabels"];
@@ -1078,6 +1096,29 @@ WBDelegate(badge_)
 @end
 /* }}} */
 
 @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];
 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
     if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
         alpha = [number floatValue];
@@ -1729,12 +1770,16 @@ extern "C" void WBInitialize() {
 
         $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
 
 
         $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");
         $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");
         $SBDockIconListView = objc_getClass("SBDockIconListView");
         $SBIcon = objc_getClass("SBIcon");
         $SBIconBadge = objc_getClass("SBIconBadge");
@@ -1742,6 +1787,7 @@ extern "C" void WBInitialize() {
         $SBIconLabel = objc_getClass("SBIconLabel");
         $SBIconList = objc_getClass("SBIconList");
         $SBIconModel = objc_getClass("SBIconModel");
         $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");
         //$SBImageCache = objc_getClass("SBImageCache");
         $SBSearchView = objc_getClass("SBSearchView");
         $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
@@ -1752,6 +1798,9 @@ extern "C" void WBInitialize() {
         $SBUIController = objc_getClass("SBUIController");
         $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
 
         $SBUIController = objc_getClass("SBUIController");
         $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
 
+        if ($SBIconView == nil)
+            $SBIconView = $SBIcon;
+
         Four_ = $SBDockIconListView != nil;
 
         WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
         Four_ = $SBDockIconListView != nil;
 
         WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
@@ -1768,13 +1817,18 @@ extern "C" void WBInitialize() {
         WBRename(SBIcon, setAlpha:, setAlpha$);
         WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
         WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
         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(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$);
 
         WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
         WBRename(SBIconLabel, setInDock:, setInDock$);