X-Git-Url: https://git.saurik.com/cydget.git/blobdiff_plain/3aa346e50eee394a7d8a9d5862aebb52fe94e758..ca6f1b3064202e2d366d288fc88b5659b80e02a6:/Tweak.mm diff --git a/Tweak.mm b/Tweak.mm index 550510a..361223f 100644 --- a/Tweak.mm +++ b/Tweak.mm @@ -1,5 +1,5 @@ -/* Cydget - open-source IntelliScreen replacement - * Copyright (C) 2009 Jay Freeman (saurik) +/* Cydget - open-source AwayView plugin multiplexer + * Copyright (C) 2009-2011 Jay Freeman (saurik) */ /* @@ -42,12 +42,15 @@ #include #import +#import #import #import MSClassHook(SpringBoard) + MSClassHook(SBAwayController) MSClassHook(SBAwayView) +MSClassHook(SBAwayViewController) MSClassHook(SBAwayWindow) #define _trace() \ @@ -56,7 +59,6 @@ MSClassHook(SBAwayWindow) static_cast(~type()) static bool menu_; -static unsigned lock_; static _H settings_; static _H cydgets_; @@ -73,7 +75,8 @@ static unsigned online_; @implementation CydgetController + (NSDictionary *) currentConfiguration { - return [[cydgets_ objectAtIndex:active_] objectForKey:@"Configuration"]; + NSDictionary *cydget([cydgets_ objectAtIndex:active_]); + return [cydget objectForKey:@"CYConfiguration"] ?: [cydget objectForKey:@"Configuration"]; } @end @@ -83,48 +86,76 @@ static unsigned online_; - (void) disableCydget:(SBAwayController *)away; @end +@interface UIPeripheralHost : NSObject ++ (UIPeripheralHost *) sharedInstance; ++ (void) _releaseSharedInstance; +- (void) createAutomaticKeyboardIfNeeded; +@end + +MSClassHook(UIPeripheralHost) + +@interface UITextEffectsWindow : UIWindow ++ (UIWindow *) sharedTextEffectsWindow; +@end + @implementation NSDictionary (Cydgets) - (void) enableCydget:(SBAwayController *)away { - if (NSString *plugin = [self objectForKey:@"Plugin"]) { - [away enableLockScreenBundleWithName:plugin]; + if (NSString *plugin = [self objectForKey:@"CYPlugin"] ?: [self objectForKey:@"Plugin"]) { ++online_; + UIKeyboardEnableAutomaticAppearance(); + + [[$UIPeripheralHost sharedInstance] createAutomaticKeyboardIfNeeded]; + [[UITextEffectsWindow sharedTextEffectsWindow] setWindowLevel:1000]; + + [away enableLockScreenBundleWithName:plugin]; } } - (void) disableCydget:(SBAwayController *)away { - if (NSString *plugin = [self objectForKey:@"Plugin"]) { + if (NSString *plugin = [self objectForKey:@"CYPlugin"] ?: [self objectForKey:@"Plugin"]) { [away disableLockScreenBundleWithName:plugin]; + + [$UIPeripheralHost _releaseSharedInstance]; + + UIKeyboardDisableAutomaticAppearance(); --online_; } } @end -MSInstanceMessageHook0(BOOL, SBAwayController, handleMenuButtonTap) { - unsigned lock(lock_); +// avoid rendering a keyboard onto the default SBAwayView while automatic keyboard is online +MSInstanceMessageHook0(UIView *, SBAwayView, inputView) { + if (online_ == 0) + return MSOldCall(); + + return [[[UIView alloc] init] autorelease]; +} - if (!MSOldCall() && lock != 2) { +// by default, keyboard actions are redirected to SBAwayController and press menu button +MSInstanceMessageHook1(void, SpringBoard, handleKeyEvent, GSEventRef, event) { + if (online_ == 0) + return MSOldCall(event); + + return MSSuperCall(event); +} + +MSInstanceMessageHook0(BOOL, SBAwayController, handleMenuButtonTap) { + if (!MSOldCall() && menu_) { [[cydgets_ objectAtIndex:active_] disableCydget:self]; active_ = (active_ + 1) % [cydgets_ count]; [[cydgets_ objectAtIndex:active_] enableCydget:self]; - } else if (lock == 2) - lock_ = 0; + } return YES; } MSInstanceMessageHook0(void, SBAwayController, _undimScreen) { - if (lock_ == 1) - lock_ = 2; - [[cydgets_ objectAtIndex:active_] enableCydget:[$SBAwayController sharedAwayController]]; - MSOldCall(); -} - -MSInstanceMessageHook0(void, SBAwayController, undimScreen) { - if (lock_ != 2) - lock_ = menu_ ? 1 : 0; - MSOldCall(); + menu_ = false; + [[cydgets_ objectAtIndex:active_] enableCydget:self]; + [[[self awayView] window] makeKeyWindow]; + return MSOldCall(); } static void Deactivate_(SBAwayController *self) { @@ -132,36 +163,27 @@ static void Deactivate_(SBAwayController *self) { active_ = 0; } -#define MSNotificationHook(notification) \ - static void N_mas(); \ - static void burple(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef info) { \ - N_mas(); \ - } \ - static class N_MSq { public: _finline N_MSq() { \ - CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &burple, CFSTR(notification), NULL, 0); \ - } } n_msq; \ - static void N_mas() - -MSNotificationHook("SBDidTurnOffDisplayNotification") { +MSInstanceMessageHook1(void, SBAwayController, dimScreen, BOOL, dim) { Deactivate_([$SBAwayController sharedAwayController]); + MSOldCall(dim); } MSInstanceMessageHook1(void, SpringBoard, menuButtonUp, GSEventRef, event) { menu_ = true; MSOldCall(event); - menu_ = false; } MSInstanceMessageHook1(void, SBAwayView, addGestureRecognizer, id, recognizer) { - // MSOldCall(recognizer); + if (online_ == 0) + return MSOldCall(recognizer); } MSInstanceMessageHook1(void, SBAwayWindow, sendGSEvent, GSEventRef, event) { -_trace(); - if (online_ != 0) - MSSuperCall(event); - else - MSOldCall(event); + NSLog(@"sendGSEvent"); + if (online_ == 0) + return MSOldCall(event); + + return MSSuperCall(event); } #define Cydgets_ @"/System/Library/LockCydgets" @@ -181,6 +203,9 @@ static void CydgetSetup() { if ([[cydget objectForKey:@"Active"] boolValue]) if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.cydget/Info.plist", Cydgets_, [cydget objectForKey:@"Name"]]]) [cydgets_ addObject:info]; + + if ([cydgets_ count] == 0) + cydgets_ = nil; } // XXX: this could happen while it is unlocked @@ -196,3 +221,18 @@ MSInstanceMessageHook1(void, SBAwayController, _finishedUnlockAttemptWithStatus, Deactivate_(self); MSOldCall(status); } + +MSInstanceMessageHook0(void, SBAwayView, updateInterface) { + MSOldCall(); + + NSDictionary *cydget([cydgets_ objectAtIndex:active_]); + + NSString *background([cydget objectForKey:@"CYBackground"]); + if ([background isEqualToString:@"Wallpaper"]) { + MSIvarHook(UIView *, _backgroundView); + [_backgroundView setAlpha:1.0f]; + } + + if ([[cydget objectForKey:@"CYShowDateTime"] boolValue]) + [self addDateView]; +}