]> git.saurik.com Git - winterboard.git/blobdiff - Library.mm
Add an IconAlpha fix from NickF.
[winterboard.git] / Library.mm
index 95541eee63853007b54a621b5d6135930d5d3cb9..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,11 +778,34 @@ 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_) {
-        UIWindow *&_wallpaperView(MSHookIvar<UIWindow *>(self, "_wallpaperView"));
+        UIImageView *&_wallpaperView(MSHookIvar<UIImageView *>(self, "_wallpaperView"));
         if (&_wallpaperView != NULL) {
             [_wallpaperView removeFromSuperview];
             [_wallpaperView release];
@@ -785,7 +813,6 @@ MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
         }
     }
 
-    UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
     UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
     UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
 
@@ -796,18 +823,24 @@ MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
         player = &_contentView;
     else
         player = NULL;
-
     UIView *layer(player == NULL ? nil : *player);
 
-    UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
+    UIWindow *window([[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
+    UIView *content([[[UIView alloc] initWithFrame:[window frame]] autorelease]);
+    [window setContentView:content];
+
+    UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
+    [window setBackgroundColor:[_window backgroundColor]];
+    [_window setBackgroundColor:[UIColor clearColor]];
+
+    [window setLevel:-1000];
+    [window setHidden:NO];
 
     /*if (player != NULL)
         *player = content;*/
 
     [content setBackgroundColor:[layer backgroundColor]];
     [layer setBackgroundColor:[UIColor clearColor]];
-    [layer setFrame:[content bounds]];
-    [_window setContentView:content];
 
     UIView *indirect;
     if (!SummerBoard_ || !IsWild_)
@@ -929,8 +962,6 @@ MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
         }
     }
 
-    [content addSubview:layer];
-
     return self;
 }
 
@@ -1065,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];
@@ -1391,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;
@@ -1714,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");
@@ -1727,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");
@@ -1737,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$);
@@ -1753,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$);
 
@@ -1798,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];
 }