From: Jay Freeman (saurik) Date: Mon, 4 Aug 2008 11:19:39 +0000 (+0000) Subject: Matched up WinterBoard to the documentation. X-Git-Tag: v0.9.3900~87 X-Git-Url: https://git.saurik.com/winterboard.git/commitdiff_plain/ca13798d8bb053ba23e057d6b9e056bc747b61d2?ds=sidebyside;hp=889cb4f2c35bd755eb6201eafe7df68715bccf16 Matched up WinterBoard to the documentation. --- diff --git a/Library.mm b/Library.mm index 2655342..e718c4d 100644 --- a/Library.mm +++ b/Library.mm @@ -36,6 +36,7 @@ */ #define _trace() NSLog(@"WB:_trace(%u)", __LINE__); +#define _transient #include #include @@ -97,6 +98,7 @@ extern "C" { @end bool Debug_ = false; +bool Engineer_ = false; /* WinterBoard Backend {{{ */ #define WBPrefix "wb_" @@ -158,6 +160,7 @@ void WBRename(bool instance, const char *classname, const char *oldname, IMP new - (id) wb_initWithFrame:(CGRect)frame; - (id) wb_initWithCoder:(NSCoder *)coder; - (void) wb_setFrame:(CGRect)frame; +- (void) wb_drawRect:(CGRect)rect; - (void) wb_setBackgroundColor:(id)color; - (void) wb_setAlpha:(float)value; - (void) wb_setBarStyle:(int)style; @@ -193,6 +196,12 @@ NSString *SBApplication$pathForIcon(SBApplication *self, SEL sel) { return path; } + if (NSString *folder = [[self path] lastPathComponent]) { + NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/icon.png", theme_, folder]; + if ([Manager_ fileExistsAtPath:path]) + return path; + } + testForIcon(identifier); testForIcon([self displayName]); @@ -216,11 +225,21 @@ NSString *SBApplication$pathForIcon(SBApplication *self, SEL sel) { return [self wb_pathForIcon]; } -NSString *$pathForFileInBundle$(NSString *file) { +NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle) { if (theme_ != nil) { - NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@", theme_, file]; - if ([Manager_ fileExistsAtPath:path]) - return path; + NSString *identifier = [bundle bundleIdentifier]; + + if (identifier != nil) { + NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/%@", theme_, identifier, file]; + if ([Manager_ fileExistsAtPath:path]) + return path; + } + + if (NSString *folder = [[bundle bundlePath] lastPathComponent]) { + NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/%@", theme_, folder, file]; + if ([Manager_ fileExistsAtPath:path]) + return path; + } #define remapResourceName(oldname, newname) \ else if ([file isEqualToString:oldname]) { \ @@ -229,7 +248,7 @@ NSString *$pathForFileInBundle$(NSString *file) { return path; \ } - if (false); + if (identifier == nil || ![identifier isEqualToString:@"com.apple.springboard"]); remapResourceName(@"com.apple.springboard/FSO_BG.png", @"StatusBar") remapResourceName(@"com.apple.springboard/SBDockBG.png", @"Dock") remapResourceName(@"com.apple.springboard/SBWeatherCelsius.png", @"Icons/Weather") @@ -241,9 +260,8 @@ NSString *$pathForFileInBundle$(NSString *file) { UIImage *UIImage$imageNamed$inBundle$(Class self, SEL sel, NSString *name, NSBundle *bundle) { if (Debug_) NSLog(@"WB:Debug: [UIImage(%@) imageNamed:\"%@\"]", [bundle bundleIdentifier], name); - if (NSString *identifier = [bundle bundleIdentifier]) - if (NSString *path = $pathForFileInBundle$([NSString stringWithFormat:@"%@/%@", identifier, name])) - return [UIImage imageWithContentsOfFile:path]; + if (NSString *path = $pathForFile$inBundle$(name, bundle)) + return [UIImage imageWithContentsOfFile:path]; return [self wb_imageNamed:name inBundle:bundle]; } @@ -255,9 +273,8 @@ NSString *NSBundle$pathForResource$ofType$(NSBundle *self, SEL sel, NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type]; if (Debug_) NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file); - if (NSString *identifier = [self bundleIdentifier]) - if (NSString *path = $pathForFileInBundle$([NSString stringWithFormat:@"%@/%@", identifier, file])) - return path; + if (NSString *path = $pathForFile$inBundle$(file, self)) + return path; return [self wb_pathForResource:resource ofType:type]; } @@ -349,66 +366,130 @@ id SBContentLayer$initWithSize$(SBContentLayer *self, SEL sel, CGSi return self; } -@interface WBIconLabel : NSProxy { - NSString *label_; - BOOL docked_; +#define WBDelegate(delegate) \ + - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \ + if (Engineer_) \ + NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \ + if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \ + return sig; \ + NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \ + return nil; \ + } \ +\ + - (void) forwardInvocation:(NSInvocation*)inv { \ + SEL sel = [inv selector]; \ + if ([delegate respondsToSelector:sel]) \ + [inv invokeWithTarget:delegate]; \ + else \ + NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \ + } + +unsigned *ContextCount_; +void ***ContextStack_; + +extern "C" CGColorRef CGGStateGetSystemColor(void *); +extern "C" CGColorRef CGGStateGetFillColor(void *); +extern "C" CGColorRef CGGStateGetStrokeColor(void *); +extern "C" NSString *UIStyleStringFromColor(CGColorRef); + +@interface WBTime : NSProxy { + NSString *time_; + _transient SBStatusBarTimeView *view_; } -- (id) initWithLabel:(NSString *)label; -- (void) setInDock:(BOOL)docked; +- (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view; @end -@implementation WBIconLabel +@implementation WBTime - (void) dealloc { - [label_ release]; + [time_ release]; [super dealloc]; } -- (id) initWithLabel:(NSString *)label { - label_ = [label retain]; +- (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view { + time_ = [time retain]; + view_ = view; return self; } -- (BOOL) respondsToSelector:(SEL)sel { - return - sel == @selector(setInDock:) - ? YES : [super respondsToSelector:sel]; +WBDelegate(time_) + +- (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode { + if (Info_ != nil) + if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) { + BOOL mode; + object_getInstanceVariable(view_, "_mode", (void **) &mode); + + [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@"" + "font-family: Helvetica; " + "font-weight: bold; " + "font-size: 14px; " + "color: %@; " + "%@", mode ? @"white" : @"black", custom]]; + + return CGSizeZero; + } + + return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode]; } -- (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { - if (NSMethodSignature *sig = [label_ methodSignatureForSelector:sel]) - return sig; - NSLog(@"WB:Error: [WBIconLabel methodSignatureForSelector:(%s)]", sel_getName(sel)); - return nil; +@end + +@interface WBIconLabel : NSProxy { + NSString *string_; + BOOL docked_; +} + +- (id) initWithString:(NSString *)string; + +@end + +@implementation WBIconLabel + +- (void) dealloc { + [string_ release]; + [super dealloc]; } -- (void) forwardInvocation:(NSInvocation*)inv { - SEL sel = [inv selector]; - if ([label_ respondsToSelector:sel]) - [inv invokeWithTarget:label_]; - else - NSLog(@"WB:Error: [WBIconLabel forwardInvocation:(%s)]", sel_getName(sel)); +- (id) initWithString:(NSString *)string { + string_ = [string retain]; + return self; } +WBDelegate(string_) + - (NSString *) _iconLabelStyle { - return Info_ == nil ? nil : [Info_ objectForKey:(docked_ ? @"DockIconLabelStyle" : @"IconLabelStyle")]; + return Info_ == nil ? nil : [Info_ objectForKey:(docked_ ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")]; } - (CGSize) drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(int)mode alignment:(int)alignment { if (NSString *custom = [self _iconLabelStyle]) { - [label_ drawInRect:rect withStyle:[NSString stringWithFormat:@"font-family: Helvetica; font-weight: bold; font-size: 11px; text-align: center; %@", custom]]; + [string_ drawInRect:rect withStyle:[NSString stringWithFormat:@"" + "font-family: Helvetica; " + "font-weight: bold; " + "font-size: 11px; " + "text-align: center; " + "color: %@; " + "%@", docked_ ? @"white" : @"#b3b3b3", custom]]; + return CGSizeZero; } - return [label_ drawInRect:rect withFont:font lineBreakMode:mode alignment:alignment]; + return [string_ drawInRect:rect withFont:font lineBreakMode:mode alignment:alignment]; } - (void) drawInRect:(CGRect)rect withStyle:(NSString *)style { if (NSString *custom = [self _iconLabelStyle]) - return [label_ drawInRect:rect withStyle:[NSString stringWithFormat:@"%@; %@", style, custom]]; - return [label_ drawInRect:rect withStyle:style]; + return [string_ drawInRect:rect withStyle:[NSString stringWithFormat:@"%@; %@", style, custom]]; + return [string_ drawInRect:rect withStyle:style]; +} + +- (BOOL) respondsToSelector:(SEL)sel { + return + sel == @selector(setInDock:) + ? YES : [super respondsToSelector:sel]; } - (void) setInDock:(BOOL)docked { @@ -417,6 +498,14 @@ id SBContentLayer$initWithSize$(SBContentLayer *self, SEL sel, CGSi @end +void SBStatusBarTimeView$drawRect$(SBStatusBarTimeView *self, SEL sel, CGRect rect) { + id time; + object_getInstanceVariable(self, "_time", (void **) &time); + if (time != nil && [time class] != [WBTime class]) + object_setInstanceVariable(self, "_time", (void *) [[WBTime alloc] initWithTime:[time autorelease] view:self]); + return [self wb_drawRect:rect]; +} + void SBIconLabel$setInDock$(SBIconLabel *self, SEL sel, BOOL docked) { id label; object_getInstanceVariable(self, "_label", (void **) &label); @@ -428,7 +517,9 @@ void SBIconLabel$setInDock$(SBIconLabel *self, SEL sel, BOOL docked } id SBIconLabel$initWithSize$label$(SBIconLabel *self, SEL sel, CGSize size, NSString *label) { - return [self wb_initWithSize:size label:[[[WBIconLabel alloc] initWithLabel:label] autorelease]]; + // XXX: technically I'm misusing self here + return [self wb_initWithSize:size label:[[[WBIconLabel alloc] initWithString:label] autorelease]]; + //return [self wb_initWithSize:size label:label]; } extern "C" void FindMappedImages(void); @@ -439,27 +530,20 @@ extern "C" void WBInitialize() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - struct nlist nl[3]; + struct nlist nl[5]; memset(nl, 0, sizeof(nl)); nl[0].n_un.n_name = (char *) "___mappedImages"; nl[1].n_un.n_name = (char *) "__UISharedImageInitialize"; + nl[2].n_un.n_name = (char *) "___currentContextCount"; + nl[3].n_un.n_name = (char *) "___currentContextStack"; nlist("/System/Library/Frameworks/UIKit.framework/UIKit", nl); ImageMap_ = (id *) nl[0].n_value; void (*__UISharedImageInitialize)(bool) = (void (*)(bool)) nl[1].n_value; + ContextCount_ = (unsigned *) nl[2].n_value; + ContextStack_ = (void ***) nl[3].n_value; __UISharedImageInitialize(false); - /*NSArray *keys = [*ImageMap_ allKeys]; - for (int i(0), e([keys count]); i != e; ++i) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *key = [keys objectAtIndex:i]; - CGImageRef ref = (CGImageRef) [*ImageMap_ objectForKey:key]; - UIImage *image = [UIImage imageWithCGImage:ref]; - NSData *data = UIImagePNGRepresentation(image); - [data writeToFile:[NSString stringWithFormat:@"/tmp/pwnr/%@", key] atomically:YES]; - [pool release]; - }*/ - English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"]; if (English_ != nil) English_ = [English_ retain]; @@ -482,6 +566,7 @@ extern "C" void WBInitialize() { WBRename(true, "SBButtonBar", "didMoveToSuperview", (IMP) &$didMoveToSuperview); WBRename(true, "SBIconLabel", "setInDock:", (IMP) &SBIconLabel$setInDock$); WBRename(true, "SBIconLabel", "initWithSize:label:", (IMP) &SBIconLabel$initWithSize$label$); + WBRename(true, "SBStatusBarTimeView", "drawRect:", (IMP) &SBStatusBarTimeView$drawRect$); if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()]]) { [settings autorelease]; diff --git a/Nature/Info.plist b/Nature/Info.plist index e4f7da0..128b07d 100644 --- a/Nature/Info.plist +++ b/Nature/Info.plist @@ -5,10 +5,13 @@ NavigationBarStyle 1 -IconLabelStyle -color: white +UndockedIconLabelStyle +font-family: monospace; font-size: 13px; color: white -DockIconLabelStyle -color: burlywood +DockedIconLabelStyle +font-family: monospace; font-size: 13px; oolor: burlywood + +TimeStyle +font-family: monospace; font-size: 16px diff --git a/UIImages.mm b/UIImages.mm new file mode 100644 index 0000000..0e2272c --- /dev/null +++ b/UIImages.mm @@ -0,0 +1,35 @@ +#import +#import +#import + +extern "C" { + #include +} + +int main(int argc, char *argv[]) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + struct nlist nl[3]; + memset(nl, 0, sizeof(nl)); + nl[0].n_un.n_name = (char *) "___mappedImages"; + nl[1].n_un.n_name = (char *) "__UISharedImageInitialize"; + nlist("/System/Library/Frameworks/UIKit.framework/UIKit", nl); + NSMutableDictionary **images = (id *) nl[0].n_value; + void (*__UISharedImageInitialize)(bool) = (void (*)(bool)) nl[1].n_value; + + __UISharedImageInitialize(false); + + NSArray *keys = [*images allKeys]; + for (int i(0), e([keys count]); i != e; ++i) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *key = [keys objectAtIndex:i]; + CGImageRef ref = (CGImageRef) [*images objectForKey:key]; + UIImage *image = [UIImage imageWithCGImage:ref]; + NSData *data = UIImagePNGRepresentation(image); + [data writeToFile:[NSString stringWithFormat:@"%@", key] atomically:YES]; + [pool release]; + } + + [pool release]; + return 0; +} diff --git a/control b/control index 01cd171..f96263e 100644 --- a/control +++ b/control @@ -3,9 +3,11 @@ Priority: optional Section: Themes Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 0.9.2501-4 +Version: 0.9.2504-1 Description: more powerful, open-source SummerBoard - This tool lets you apply SummerBoard themes. Themes are taken from /Library/Themes (or, now, the older SummerBoard folder). Right now the tool is /very/ simplistic: I have spent about a day coding it so that we would have some stronger theme support on iPhone 2.x. After you install or uninstall this package you will have to /reboot/ (seriously, REBOOT) your phone to it to take effect. + After you install or uninstall this package you will have to /reboot/ (seriously, REBOOT) your phone to it to take effect. + + This tool lets you apply SummerBoard themes. Themes are taken from /Library/Themes (or, now, the older SummerBoard folder). Right now the front-end for selecting themes is /very/ simplistic: I have spent only a couple days coding this and almost all of that time has been on the backend. More work will be done on this package in the very near future to make it actually have an interface ;P. diff --git a/make.sh b/make.sh index e9a3ce6..33af7e3 100755 --- a/make.sh +++ b/make.sh @@ -3,4 +3,4 @@ set -e export PKG_ARCH=${PKG_ARCH-iphoneos-arm} PATH=/apl/n42/pre/bin:$PATH /apl/tel/exec.sh com.saurik.winterboard make "$@" export CODESIGN_ALLOCATE=$(which arm-apple-darwin9-codesign_allocate) -/apl/tel/util/ldid -S WinterBoard WinterBoard.dylib +/apl/tel/util/ldid -S WinterBoard WinterBoard.dylib UIImages diff --git a/makefile b/makefile index 08cdfad..6ae658a 100644 --- a/makefile +++ b/makefile @@ -4,14 +4,17 @@ else target := $(PKG_TARG)- endif -all: WinterBoard WinterBoard.dylib +all: WinterBoard WinterBoard.dylib UIImages clean: - rm -f WinterBoard WinterBoard.dylib + rm -f WinterBoard WinterBoard.dylib UIImages WinterBoard.dylib: Library.mm makefile $(target)g++ -dynamiclib -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework CoreFoundation -framework Foundation -lobjc -init _WBInitialize -I/apl/inc/iPhoneOS-2.0 -framework CoreGraphics +UIImages: UIImages.mm makefile + $(target)g++ -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework Foundation -framework CoreFoundation -lobjc + WinterBoard: Application.mm makefile $(target)g++ -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework Foundation -framework CoreFoundation -lobjc -framework CoreGraphics @@ -22,7 +25,7 @@ package: mkdir -p winterboard/Library/Themes cp -a Nature winterboard/Library/Themes/com.saurik.WinterBoard.Nature cp -a control preinst postinst prerm winterboard/DEBIAN - cp -a Test.sh icon.png WinterBoard.dylib WinterBoard Info.plist ../pledit/pledit winterboard/Applications/WinterBoard.app - dpkg-deb -b winterboard winterboard_0.9.2501-4_iphoneos-arm.deb + cp -a Test.sh icon.png WinterBoard.dylib WinterBoard UIImages Info.plist ../pledit/pledit winterboard/Applications/WinterBoard.app + dpkg-deb -b winterboard winterboard_0.9.2504-1_iphoneos-arm.deb .PHONY: all clean package