1 /* Cydget - open-source IntelliScreen replacement
2 * Copyright (C) 2009 Jay Freeman (saurik)
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the
11 * above copyright notice, this list of conditions
12 * and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the
14 * above copyright notice, this list of conditions
15 * and the following disclaimer in the documentation
16 * and/or other materials provided with the
18 * 3. The name of the author may not be used to endorse
19 * or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <substrate.h>
40 #include <Foundation/Foundation.h>
41 #include <GraphicsServices/GraphicsServices.h>
43 #import <SpringBoard/SBAwayController.h>
44 #import <SpringBoard/SBAwayWindow.h>
46 MSClassHook(SpringBoard)
47 MSClassHook(SBAwayController)
48 MSClassHook(SBAwayView)
51 NSLog(@"_trace(%s:%u)@%s %d", __FILE__, __LINE__, __FUNCTION__, active_)
53 static_cast<type>(~type())
56 static unsigned lock_;
58 static _H<NSArray> cydgets_;
59 static size_t active_ = _not(size_t);
61 @interface NSDictionary (Cydgets)
62 - (void) enableCydget:(SBAwayController *)away;
63 - (void) disableCydget:(SBAwayController *)away;
66 @implementation NSDictionary (Cydgets)
68 - (void) enableCydget:(SBAwayController *)away {
69 [away enableLockScreenBundleWithName:[self objectForKey:@"Plugin"]];
72 - (void) disableCydget:(SBAwayController *)away {
73 [away disableLockScreenBundleWithName:[self objectForKey:@"Plugin"]];
78 MSHook(BOOL, SBAwayController$handleMenuButtonTap, SBAwayController *self, SEL sel) {
81 if (!_SBAwayController$handleMenuButtonTap(self, sel) && lock != 2) {
82 if (active_ != _not(size_t))
83 [[cydgets_ objectAtIndex:active_] disableCydget:self];
85 size_t count([cydgets_ count]);
86 if ((++active_ %= count + 1) == count)
87 active_ = _not(size_t);
89 [[cydgets_ objectAtIndex:active_] enableCydget:self];
95 MSHook(void, SBAwayController$_undimScreen, SBAwayController *self, SEL sel) {
98 _SBAwayController$_undimScreen(self, sel);
101 MSHook(void, SBAwayController$undimScreen, SBAwayController *self, SEL sel) {
102 lock_ = menu_ ? 1 : 0;
103 _SBAwayController$undimScreen(self, sel);
106 static void Deactivate_(SBAwayController *self) {
107 if (active_ != _not(size_t)) {
108 [[cydgets_ objectAtIndex:active_] disableCydget:self];
109 active_ = _not(size_t);
113 MSHook(void, SBAwayController$finishedDimmingScreen, SBAwayController *self, SEL sel) {
115 _SBAwayController$finishedDimmingScreen(self, sel);
118 MSHook(void, SpringBoard$menuButtonUp$, UIView *self, SEL sel, GSEventRef event) {
120 _SpringBoard$menuButtonUp$(self, sel, event);
124 MSHook(void, SBAwayView$addGestureRecognizer$, UIView *self, SEL sel, id gr) {
125 //_SBAwayView$addGestureRecognizer$(self, sel, gr);
128 MSInstanceMessageHook1(void, SBAwayController, _finishedUnlockAttemptWithStatus, BOOL, status) {
134 #define Cydgets_ @"/System/Library/LockCydgets"
136 MSInitialize { _pooled
137 cydgets_ = [NSMutableArray arrayWithCapacity:4];
139 for (NSString *plist in [[NSFileManager defaultManager] directoryContentsAtPath:Cydgets_])
140 if ([plist hasSuffix:@".plist"])
141 [cydgets_ addObject:[NSDictionary dictionaryWithContentsOfFile:[Cydgets_ stringByAppendingPathComponent:plist]]];
143 MSHookMessage1(SpringBoard, menuButtonUp);
145 MSHookMessage0(SBAwayController, handleMenuButtonTap);
146 MSHookMessage0(SBAwayController, _undimScreen);
147 MSHookMessage0(SBAwayController, undimScreen);
148 MSHookMessage0(SBAwayController, finishedDimmingScreen);
150 MSHookMessage1(SBAwayView, addGestureRecognizer);