]> git.saurik.com Git - cydget.git/commitdiff
Simplified 4.x-compatible menu state-machine.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 24 Oct 2010 10:41:50 +0000 (10:41 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 24 Oct 2010 10:41:50 +0000 (10:41 +0000)
Tweak.mm

index d0f12d9c4dbd7cec23d52bba2c1bf256c6512293..5b8e843e4d25f21e65d73f584b7163a4bf085909 100644 (file)
--- a/Tweak.mm
+++ b/Tweak.mm
@@ -57,7 +57,6 @@ MSClassHook(SBAwayWindow)
     static_cast<type>(~type())
 
 static bool menu_;
-static unsigned lock_;
 
 static _H<NSArray> settings_;
 static _H<NSArray> cydgets_;
@@ -104,54 +103,34 @@ static unsigned online_;
 @end
 
 MSInstanceMessageHook0(BOOL, SBAwayController, handleMenuButtonTap) {
-    unsigned lock(lock_);
-
-    if (!MSOldCall() && lock != 2) {
+    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;
+    menu_ = false;
     [[cydgets_ objectAtIndex:active_] enableCydget:[$SBAwayController sharedAwayController]];
     MSOldCall();
 }
 
-MSInstanceMessageHook0(void, SBAwayController, undimScreen) {
-    if (lock_ != 2)
-        lock_ = menu_ ? 1 : 0;
-    MSOldCall();
-}
-
 static void Deactivate_(SBAwayController *self) {
     [[cydgets_ objectAtIndex:active_] disableCydget: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) {