-/* Cydget - open-source IntelliScreen replacement
- * Copyright (C) 2009 Jay Freeman (saurik)
+/* Cydget - open-source AwayView plugin multiplexer
+ * Copyright (C) 2009-2011 Jay Freeman (saurik)
*/
/*
#import <SpringBoard/SpringBoard.h>
MSClassHook(SpringBoard)
+
MSClassHook(SBAwayController)
MSClassHook(SBAwayView)
+MSClassHook(SBAwayViewController)
MSClassHook(SBAwayWindow)
#define _trace() \
static_cast<type>(~type())
static bool menu_;
-static unsigned lock_;
static _H<NSArray> settings_;
static _H<NSArray> cydgets_;
- (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"]) {
[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) {
+ // 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);
- if (!MSOldCall() && lock != 2) {
+ 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) {
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"
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();