]> git.saurik.com Git - veency.git/commitdiff
Added support for Ashikase MouseSupport. v0.9.3143
authorJay Freeman (saurik) <saurik@saurik.com>
Sat, 27 Mar 2010 23:58:22 +0000 (23:58 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Sat, 27 Mar 2010 23:58:22 +0000 (23:58 +0000)
Settings.plist
Tweak.mm
control

index 991e190638f1a036c3edd6609958a6dfa3bd45c6..2635a6c4ba9cdecfd37aace17bc8457dfd48f014 100644 (file)
        <key>label</key>
        <string>Veency</string>
     </dict>
+
     <key>items</key>
     <array>
        <dict>
            <key>cell</key>
            <string>PSGroupCell</string>
        </dict>
+
         <dict>
            <key>cell</key>
            <string>PSSwitchCell</string>
             <key>PostNotification</key>
             <string>com.saurik.Veency-Enabled</string>
         </dict>
+
+        <dict>
+           <key>cell</key>
+           <string>PSSwitchCell</string>
+           <key>default</key>
+           <true/>
+            <key>defaults</key>
+            <string>com.saurik.Veency</string>
+            <key>key</key>
+            <string>ShowCursor</string>
+            <key>label</key>
+            <string>Show Cursor</string>
+            <key>PostNotification</key>
+            <string>com.saurik.Veency-Settings</string>
+        </dict>
+
        <dict>
            <key>cell</key>
            <string>PSGroupCell</string>
        </dict>
+
         <dict>
             <key>cell</key>
             <string>PSSecureEditTextCell</string>
             <key>PostNotification</key>
             <string>com.saurik.Veency-Settings</string>
         </dict>
+
        <dict>
            <key>cell</key>
            <string>PSGroupCell</string>
            <key>isStaticText</key>
             <true/>
        </dict>
+
        <dict>
            <key>cell</key>
            <string>PSTitleValueCell</string>
            <key>label</key>
            <string>Leaving the password blank will prompt you to accept each incoming connection.</string>
        </dict>
+
     </array>
+
     <key>title</key>
     <string>Veency</string>
 </dict>
index f969bf622aac5c26ecb3bc0940955baa8b814e32..4329106d4fc943d311b56e0caa5e522e2c455d4d 100644 (file)
--- a/Tweak.mm
+++ b/Tweak.mm
@@ -1,5 +1,5 @@
 /* Veency - VNC Remote Access Server for iPhoneOS
- * Copyright (C) 2008-2009  Jay Freeman (saurik)
+ * Copyright (C) 2008-2010  Jay Freeman (saurik)
 */
 
 /*
@@ -37,6 +37,8 @@
 
 #define _trace() \
     fprintf(stderr, "_trace()@%s:%u[%s]\n", __FILE__, __LINE__, __FUNCTION__)
+#define _unlikely(expr) \
+    __builtin_expect(expr, 0)
 
 #include <substrate.h>
 
 #import <SpringBoard/SBDismissOnlyAlertItem.h>
 #import <SpringBoard/SBStatusBarController.h>
 
-static const size_t Width = 320;
-static const size_t Height = 480;
+static size_t Width = 320;
+static size_t Height = 480;
+
 static const size_t BytesPerPixel = 4;
 static const size_t BitsPerSample = 8;
 
-static const size_t Stride = Width * BytesPerPixel;
-static const size_t Size32 = Width * Height;
-static const size_t Size8 = Size32 * BytesPerPixel;
-
 static NSMutableSet *handlers_;
 static rfbScreenInfoPtr screen_;
 static bool running_;
@@ -76,6 +75,53 @@ static int x_, y_;
 
 static unsigned clients_;
 
+static CFMessagePortRef ashikase_;
+static bool cursor_;
+
+static bool Ashikase(bool always) {
+    if (ashikase_ == NULL)
+        ashikase_ = CFMessagePortCreateRemote(kCFAllocatorDefault, CFSTR("jp.ashikase.mousesupport"));
+    return ashikase_ != NULL && (always || cursor_);
+}
+
+static CFDataRef cfTrue_;
+static CFDataRef cfFalse_;
+
+typedef struct {
+    float x, y;
+    int buttons;
+    BOOL absolute;
+} MouseEvent;
+
+static MouseEvent event_;
+static CFDataRef cfEvent_;
+
+typedef enum {
+    MouseMessageTypeEvent,
+    MouseMessageTypeSetEnabled
+} MouseMessageType;
+
+static void AshikaseSetEnabled(bool enabled, bool always) {
+    if (!Ashikase(always))
+        return;
+
+    CFMessagePortSendRequest(ashikase_, MouseMessageTypeSetEnabled, cursor_ ? cfTrue_ : cfFalse_, 0, 0, NULL, NULL);
+}
+
+static bool AshikaseSendEvent(float x, float y, int buttons = 0) {
+    if (!Ashikase(false))
+        return false;
+
+    event_.x = x;
+    event_.y = y;
+    event_.buttons = buttons;
+    event_.absolute = true;
+
+    CFMessagePortSendRequest(ashikase_, MouseMessageTypeEvent, cfEvent_, 0, 0, NULL, NULL);
+
+    return true;
+}
+
 MSClassHook(SBAlertItemsController)
 MSClassHook(SBStatusBarController)
 
@@ -104,11 +150,13 @@ static rfbClientPtr client_;
 }
 
 + (void) removeStatusBarItem {
+    AshikaseSetEnabled(false, false);
     [[$SBStatusBarController sharedStatusBarController] removeStatusBarItem:@"Veency"];
 }
 
 + (void) registerClient {
     ++clients_;
+    AshikaseSetEnabled(true, false);
     [[$SBStatusBarController sharedStatusBarController] addStatusBarItem:@"Veency"];
 }
 
@@ -120,7 +168,10 @@ MSInstanceMessage2(void, VNCAlertItem, alertSheet,buttonClicked, id, sheet, int,
     switch (button) {
         case 1:
             action_ = RFB_CLIENT_ACCEPT;
-            [VNCBridge registerClient];
+
+            @synchronized (condition_) {
+                [VNCBridge registerClient];
+            }
         break;
 
         case 2:
@@ -175,6 +226,14 @@ static void VNCSettings() {
             if (NSString *password = [settings objectForKey:@"Password"])
                 if ([password length] != 0)
                     screen_->authPasswdData = [password retain];
+
+        NSNumber *cursor = [settings objectForKey:@"ShowCursor"];
+        cursor_ = cursor == nil ? true : [cursor boolValue];
+
+        if (clients_ != 0) {
+            AshikaseSetEnabled(cursor_, true);
+            AshikaseSendEvent(x_, y_);
+        }
     }
 }
 
@@ -206,6 +265,9 @@ static void VNCPointer(int buttons, int x, int y, rfbClientPtr client) {
 
     rfbDefaultPtrAddEvent(buttons, x, y, client);
 
+    if (AshikaseSendEvent(x, y, buttons))
+        return;
+
     mach_port_t purple(0);
 
     if ((diff & 0x10) != 0) {
@@ -352,8 +414,10 @@ static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) {
 }
 
 static void VNCDisconnect(rfbClientPtr client) {
-    if (--clients_ == 0)
-        [VNCBridge performSelectorOnMainThread:@selector(removeStatusBarItem) withObject:nil waitUntilDone:NO];
+    @synchronized (condition_) {
+        if (--clients_ == 0)
+            [VNCBridge performSelectorOnMainThread:@selector(removeStatusBarItem) withObject:nil waitUntilDone:YES];
+    }
 }
 
 static rfbNewClientAction VNCClient(rfbClientPtr client) {
@@ -410,9 +474,9 @@ static void VNCSetup() {
     screen_->newClientHook = &VNCClient;
     screen_->passwordCheck = &VNCCheck;
 
-    /*char data[0], mask[0];
+    char data[0], mask[0];
     rfbCursorPtr cursor = rfbMakeXCursor(0, 0, data, mask);
-    rfbSetCursor(screen_, cursor);*/
+    rfbSetCursor(screen_, cursor);
 }
 
 static void VNCEnabled() {
@@ -422,6 +486,7 @@ static void VNCEnabled() {
     if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Veency.plist", NSHomeDirectory()]])
         if (NSNumber *number = [settings objectForKey:@"Enabled"])
             enabled = [number boolValue];
+
     if (enabled != running_)
         if (enabled) {
             running_ = true;
@@ -454,7 +519,10 @@ MSHook(kern_return_t, IOMobileFramebufferSwapSetLayer,
     CGRect frame,
     int flags
 ) {
-    if (running_) {
+    if (_unlikely(screen_ == NULL)) {
+        VNCSetup();
+        VNCEnabled();
+    } else if (_unlikely(clients_ != 0)) {
         if (buffer == NULL)
             screen_->frameBuffer = reinterpret_cast<char *>(black_);
         else {
@@ -517,6 +585,13 @@ MSInitialize {
 
     [pool release];
 
-    VNCSetup();
-    VNCEnabled();
+    bool value;
+
+    value = true;
+    cfTrue_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&value), sizeof(value));
+
+    value = false;
+    cfFalse_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&value), sizeof(value));
+
+    cfEvent_ = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&event_), sizeof(event_), kCFAllocatorNull);
 }
diff --git a/control b/control
index 729808242634aefe4ee8271977385c847a3573ac..69b494ba9e6ae880a51b107ad79c2e46f5315727 100644 (file)
--- a/control
+++ b/control
@@ -5,10 +5,10 @@ Priority: optional
 Section: Networking
 Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
 Architecture: iphoneos-arm
-Version: 0.9.3023-1
+Version: 0.9.3143-1
 Description: a VNC /server/ for the iPhone
 Name: Veency
-Depends: mobilesubstrate (>= 0.9.2966-1), libvncserver, com.saurik.iphone.ske, preferenceloader
+Depends: mobilesubstrate (>= 0.9.2966-1), libvncserver, com.saurik.iphone.ske, preferenceloader, jp.ashikase.mousesupport | firmware (<< 3.0)
 Author: Jay Freeman (saurik) <saurik@saurik.com>
 Depiction: http://cydia.saurik.com/info/veency/
 Tag: purpose::daemon, role::enduser