]> git.saurik.com Git - cydget.git/blobdiff - Tweak.mm
Update cy+ dependencies.
[cydget.git] / Tweak.mm
index c85d3fb06664ec0936a4f0321c11e5ef0b5adcf0..361223f1cde0985a9f311117555eec12ff4fc92c 100644 (file)
--- 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)
 */
 
 /*
 #include <UIKit/UIKit.h>
 
 #import <SpringBoard/SBAwayController.h>
+#import <SpringBoard/SBAwayView.h>
 #import <SpringBoard/SBAwayWindow.h>
 #import <SpringBoard/SpringBoard.h>
 
 MSClassHook(SpringBoard)
+
 MSClassHook(SBAwayController)
 MSClassHook(SBAwayView)
+MSClassHook(SBAwayViewController)
 MSClassHook(SBAwayWindow)
 
 #define _trace() \
@@ -56,7 +59,6 @@ MSClassHook(SBAwayWindow)
     static_cast<type>(~type())
 
 static bool menu_;
-static unsigned lock_;
 
 static _H<NSArray> settings_;
 static _H<NSArray> 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];
+}
+
+// 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);
+}
 
-    if (!MSOldCall() && lock != 2) {
+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,35 +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) {
-    if (online_ != 0)
-        MSSuperCall(event);
-    else
-        MSOldCall(event);
+    NSLog(@"sendGSEvent");
+    if (online_ == 0)
+        return MSOldCall(event);
+
+    return MSSuperCall(event);
 }
 
 #define Cydgets_ @"/System/Library/LockCydgets"
@@ -198,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];
+}