From 1f2454f567fb9294bf50d0e3bc020b0dd872915a Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 29 Apr 2010 08:58:17 +0000 Subject: [PATCH] Somewhat got the iPad keyboard working. --- Tweak.mm | 44 +++++++++++++++++++++++++++++++++++++------- control | 2 +- makefile | 2 +- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Tweak.mm b/Tweak.mm index f64bcc4..0046708 100644 --- a/Tweak.mm +++ b/Tweak.mm @@ -394,6 +394,9 @@ static void VNCPointer(int buttons, int x, int y, rfbClientPtr client) { mach_port_deallocate(mach_task_self(), purple); } +GSEventRef (*$GSEventCreateKeyEvent)(int, CGPoint, CFStringRef, CFStringRef, id, UniChar, short, short); +GSEventRef (*$GSCreateSyntheticKeyEvent)(UniChar, BOOL, BOOL); + static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) { if (!down) return; @@ -406,9 +409,21 @@ static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) { if (key > 0xfff) return; - GSEventRef event(_GSCreateSyntheticKeyEvent(key, YES, YES)); - GSEventRecord *record(_GSEventGetGSEventRecord(event)); - record->type = GSEventTypeKeyDown; + CGPoint point(CGPointMake(x_, y_)); + + UniChar unicode(key); + CFStringRef string(NULL); + + GSEventRef event0, event1(NULL); + if ($GSEventCreateKeyEvent != NULL) { + string = CFStringCreateWithCharacters(kCFAllocatorDefault, &unicode, 1); + event0 = (*$GSEventCreateKeyEvent)(10, point, string, string, nil, unicode, 0, 1); + event1 = (*$GSEventCreateKeyEvent)(11, point, string, string, nil, unicode, 0, 1); + } else if ($GSCreateSyntheticKeyEvent != NULL) { + event0 = (*$GSCreateSyntheticKeyEvent)(unicode, YES, YES); + GSEventRecord *record(_GSEventGetGSEventRecord(event0)); + record->type = GSEventTypeKeyDown; + } else return; mach_port_t port(0); @@ -416,7 +431,7 @@ static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) { NSArray *displays([server displays]); if (displays != nil && [displays count] != 0) if (CAWindowServerDisplay *display = [displays objectAtIndex:0]) - port = [display clientPortAtPosition:CGPointMake(x_, y_)]; + port = [display clientPortAtPosition:point]; } mach_port_t purple(0); @@ -427,13 +442,20 @@ static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) { port = purple; } - if (port != 0) - GSSendEvent(record, port); + if (port != 0) { + GSSendEvent(_GSEventGetGSEventRecord(event0), port); + if (event1 != NULL) + GSSendEvent(_GSEventGetGSEventRecord(event1), port); + } if (purple != 0 && PurpleAllocated) mach_port_deallocate(mach_task_self(), purple); - CFRelease(event); + CFRelease(event0); + if (event1 != NULL) + CFRelease(event1); + if (string != NULL) + CFRelease(string); } static void VNCDisconnect(rfbClientPtr client) { @@ -604,6 +626,11 @@ MSHook(void, rfbRegisterSecurityHandler, rfbSecurityHandler *handler) { [pool release]; } +template +static void dlset(Type_ &function, const char *name) { + function = reinterpret_cast(dlsym(RTLD_DEFAULT, name)); +} + MSInitialize { NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); @@ -620,6 +647,9 @@ MSInitialize { else Level_ = 0; + dlset($GSEventCreateKeyEvent, "GSEventCreateKeyEvent"); + dlset($GSCreateSyntheticKeyEvent, "_GSCreateSyntheticKeyEvent"); + MSHookFunction(&IOMobileFramebufferSwapSetLayer, MSHake(IOMobileFramebufferSwapSetLayer)); MSHookFunction(&rfbRegisterSecurityHandler, MSHake(rfbRegisterSecurityHandler)); diff --git a/control b/control index 8c20f8d..bd14fd9 100644 --- a/control +++ b/control @@ -5,7 +5,7 @@ Priority: optional Section: Networking Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 0.9.3165-1 +Version: 0.9.3167-1 Description: a VNC /server/ for the iPhone Name: Veency Depends: mobilesubstrate (>= 0.9.2966-1), libvncserver, com.saurik.iphone.ske, preferenceloader, jp.ashikase.mousesupport | firmware (<< 3.0) diff --git a/makefile b/makefile index 3f0ac4b..03f593a 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,6 @@ name := Veency id := vncs -flags := -lvncserver -framework IOMobileFramebuffer -framework CoreSurface -framework IOKit -framework GraphicsServices -I/apl/inc/iPhoneOS-2.0 -framework QuartzCore +flags := -lvncserver -framework IOMobileFramebuffer -framework CoreSurface -framework IOKit -framework GraphicsServices -I/apl/inc/iPhoneOS-2.0 -framework QuartzCore -weak_reference_mismatches weak base := ../tweaks include ../tweaks/tweak.mk -- 2.45.2