Skip to content

Instantly share code, notes, and snippets.

@Sakurina
Created October 13, 2010 14:19
Show Gist options
  • Save Sakurina/624110 to your computer and use it in GitHub Desktop.
Save Sakurina/624110 to your computer and use it in GitHub Desktop.
five-column springboard.
/*
* Five-Column SpringBoard (FCSB) by Yanik Magnan
* http://r-ch.net/iphone/
Copyright (c) 2008-2009, Yanik Magnan <kirbykirbykirby@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#import <Foundation/Foundation.h>
#import <CoreGraphics/CGGeometry.h>
#include "CaptainHook.h"
#include <dlfcn.h>
#define CHUseSubstrate
CHDeclareClass(SBIconList);
CHDeclareClass(SBIconListView);
#define shouldNotBeTouched [self isKindOfClass:objc_getClass("SBFolderIconListView")] || [self isKindOfClass:objc_getClass("SBDockIconListView")]
/* Helpers */
static BOOL isDock(id iL) {
return [iL isKindOfClass:NSClassFromString(@"SBButtonBar")];
}
static BOOL isEnabled() {
NSDictionary* settingsDict = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/net.r-ch.fcsb.plist"];
if (settingsDict)
return [[settingsDict objectForKey:@"Enable"] boolValue];
return YES;
}
/* 3.x Hooks */
CHMethod0(int, SBIconList, maxIconColumns) {
if (isDock(self))
return CHSuper0(SBIconList, maxIconColumns);
return 5;
}
CHMethod2(CGPoint, SBIconList, originForIconAtX, int, x, Y, int, y) {
if (isDock(self))
return CHSuper2(SBIconList, originForIconAtX, x, Y, y);
CGPoint origin;
CGPoint orig_origin = CHSuper2(SBIconList, originForIconAtX, x, Y, y);
origin.x = 4 + (x * 63);
origin.y = orig_origin.y;
return origin;
}
/* 4.x Hooks */
CHClassMethod1(int, SBIconListView, iconColumnsForInterfaceOrientation, int, orientation) {
return 5;
}
CHMethod2(CGPoint, SBIconListView, originForIconAtX, int, x, Y, int, y) {
if (shouldNotBeTouched)
return CHSuper2(SBIconListView, originForIconAtX, x, Y, y);
CGPoint origin;
CGPoint orig_origin = CHSuper2(SBIconListView, originForIconAtX, x, Y, y);
origin.x = 4 + (x * 63);
origin.y = orig_origin.y;
return origin;
}
CHConstructor {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
if ((objc_getClass("SpringBoard") == nil) || (isEnabled() == NO)) {
[pool release]; return;
}
CHLoadLateClass(SBIconList);
CHHook0(SBIconList, maxIconColumns);
CHHook2(SBIconList, originForIconAtX, Y);
CHLoadLateClass(SBIconListView);
CHClassHook1(SBIconListView, iconColumnsForInterfaceOrientation);
CHHook2(SBIconListView, originForIconAtX, Y);
dlopen("/Library/MobileSubstrate/DynamicLibraries/IconSupport.dylib", RTLD_LAZY);
[[objc_getClass("ISIconSupport") sharedInstance] addExtension:@"net.r-ch.fcsb"];
[pool release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment