From 209f8f66e0c761155ca5ba189de5aab723917ca4 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 27 Mar 2010 23:58:22 +0000 Subject: [PATCH] Added support for Ashikase MouseSupport. --- Settings.plist | 23 +++++++++++ Tweak.mm | 105 ++++++++++++++++++++++++++++++++++++++++++------- control | 4 +- 3 files changed, 115 insertions(+), 17 deletions(-) diff --git a/Settings.plist b/Settings.plist index 991e190..2635a6c 100644 --- a/Settings.plist +++ b/Settings.plist @@ -11,12 +11,14 @@ label Veency + items cell PSGroupCell + cell PSSwitchCell @@ -31,10 +33,27 @@ PostNotification com.saurik.Veency-Enabled + + + cell + PSSwitchCell + default + + defaults + com.saurik.Veency + key + ShowCursor + label + Show Cursor + PostNotification + com.saurik.Veency-Settings + + cell PSGroupCell + cell PSSecureEditTextCell @@ -47,19 +66,23 @@ PostNotification com.saurik.Veency-Settings + cell PSGroupCell isStaticText + cell PSTitleValueCell label Leaving the password blank will prompt you to accept each incoming connection. + + title Veency diff --git a/Tweak.mm b/Tweak.mm index f969bf6..4329106 100644 --- 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 @@ -59,15 +61,12 @@ #import #import -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(black_); else { @@ -517,6 +585,13 @@ MSInitialize { [pool release]; - VNCSetup(); - VNCEnabled(); + bool value; + + value = true; + cfTrue_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast(&value), sizeof(value)); + + value = false; + cfFalse_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast(&value), sizeof(value)); + + cfEvent_ = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast(&event_), sizeof(event_), kCFAllocatorNull); } diff --git a/control b/control index 7298082..69b494b 100644 --- a/control +++ b/control @@ -5,10 +5,10 @@ Priority: optional Section: Networking Maintainer: Jay Freeman (saurik) 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) Depiction: http://cydia.saurik.com/info/veency/ Tag: purpose::daemon, role::enduser -- 2.45.2