]> git.saurik.com Git - cydget.git/blobdiff - Tweak.mm
Support application URL schemes.
[cydget.git] / Tweak.mm
index 0c49064a83da3a0211a8f9941a63428f3bbe2a89..c4c0eb387c38ef7962e8839e1970f053396f66e1 100644 (file)
--- a/Tweak.mm
+++ b/Tweak.mm
 #import <SpringBoard/SpringBoard.h>
 
 MSClassHook(SpringBoard)
+
 MSClassHook(SBAwayController)
 MSClassHook(SBAwayView)
+MSClassHook(SBAwayViewController)
 MSClassHook(SBAwayWindow)
 
 #define _trace() \
@@ -84,24 +86,60 @@ static unsigned online_;
 - (void) disableCydget:(SBAwayController *)away;
 @end
 
+@interface UIPeripheralHost : NSObject
++ (UIPeripheralHost *) sharedInstance;
++ (void) _releaseSharedInstance;
+@end
+
+MSClassHook(UIPeripheralHost)
+
+@interface UITextEffectsWindow : UIWindow
++ (UIWindow *) sharedTextEffectsWindow;
+@end
+
 @implementation NSDictionary (Cydgets)
 
 - (void) enableCydget:(SBAwayController *)away {
     if (NSString *plugin = [self objectForKey:@"CYPlugin"] ?: [self objectForKey:@"Plugin"]) {
-        [away enableLockScreenBundleWithName:plugin];
         ++online_;
+        UIKeyboardEnableAutomaticAppearance();
+
+        [[UITextEffectsWindow sharedTextEffectsWindow] setWindowLevel:1000];
+
+        [away enableLockScreenBundleWithName:plugin];
     }
 }
 
 - (void) disableCydget:(SBAwayController *)away {
     if (NSString *plugin = [self objectForKey:@"CYPlugin"] ?: [self objectForKey:@"Plugin"]) {
-        --online_;
         [away disableLockScreenBundleWithName:plugin];
+
+        [$UIPeripheralHost _releaseSharedInstance];
+
+        UIKeyboardDisableAutomaticAppearance();
+        --online_;
     }
 }
 
 @end
 
+// avoid rendering a keyboard onto the default SBAwayView while automatic keyboard is online
+MSInstanceMessageHook0(UIView *, SBAwayView, inputView) {
+    // XXX: there is a conceptual error here
+    if (online_ == 0 && false)
+        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);
+}
+
 MSInstanceMessageHook0(BOOL, SBAwayController, handleMenuButtonTap) {
     if (!MSOldCall() && menu_) {
         [[cydgets_ objectAtIndex:active_] disableCydget:self];
@@ -114,8 +152,9 @@ MSInstanceMessageHook0(BOOL, SBAwayController, handleMenuButtonTap) {
 
 MSInstanceMessageHook0(void, SBAwayController, _undimScreen) {
     menu_ = false;
-    [[cydgets_ objectAtIndex:active_] enableCydget:[$SBAwayController sharedAwayController]];
-    MSOldCall();
+    [[cydgets_ objectAtIndex:active_] enableCydget:self];
+    [[[self awayView] window] makeKeyWindow];
+    return MSOldCall();
 }
 
 static void Deactivate_(SBAwayController *self) {
@@ -134,14 +173,16 @@ MSInstanceMessageHook1(void, SpringBoard, menuButtonUp, GSEventRef, event) {
 }
 
 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"
@@ -180,6 +221,12 @@ MSInstanceMessageHook1(void, SBAwayController, _finishedUnlockAttemptWithStatus,
     MSOldCall(status);
 }
 
+// this is called occasionally by -[SBAwayView updateInterface] and takes away our keyboard
+MSInstanceMessageHook0(void, SBAwayView, _fixupFirstResponder) {
+    if (online_ == 0)
+        return MSOldCall();
+}
+
 MSInstanceMessageHook0(void, SBAwayView, updateInterface) {
     MSOldCall();