+ uint32_t handm;
+ uint32_t fingerm;
+
+ if (twas == 0 && tis == 1) {
+ handm = kIOHIDDigitizerEventRange | kIOHIDDigitizerEventTouch | kIOHIDDigitizerEventIdentity;
+ fingerm = kIOHIDDigitizerEventRange | kIOHIDDigitizerEventTouch;
+ } else if (twas == 1 && tis == 1) {
+ handm = kIOHIDDigitizerEventPosition;
+ fingerm = kIOHIDDigitizerEventPosition;
+ } else if (twas == 1 && tis == 0) {
+ handm = kIOHIDDigitizerEventRange | kIOHIDDigitizerEventTouch | kIOHIDDigitizerEventIdentity | kIOHIDDigitizerEventPosition;
+ fingerm = kIOHIDDigitizerEventRange | kIOHIDDigitizerEventTouch;
+ } else return;
+
+ CAWindowServer *server([CAWindowServer serverIfRunning]);
+ if (server == nil)
+ return;
+
+ CAWindowServerDisplay *display([[server displays] objectAtIndex:0]);
+ if (display == nil)
+ return;
+
+ unsigned context([display contextIdAtPosition:CGPointMake(x, y)]);
+ mach_port_t port([display taskPortOfContextId:context]);
+ if (port == MACH_PORT_NULL)
+ return;
+
+ IOHIDEventSystemConnectionRef connection([[$BKAccessibility _eventRoutingClientConnectionManager] clientForTaskPort:port]);
+ if (connection == NULL)
+ return;
+
+ // XXX: I guess this isn't ambiguous, and it works
+ IOHIDFloat xf(x);
+ IOHIDFloat yf(y);
+
+ IOHIDEventRef hand(IOHIDEventCreateDigitizerEvent(kCFAllocatorDefault, mach_absolute_time(), kIOHIDDigitizerTransducerTypeHand, 1<<22, 1, handm, 0, xf, yf, 0, 0, 0, 0, 0, 0));
+ IOHIDEventSetIntegerValue(hand, kIOHIDEventFieldIsBuiltIn, true);
+ IOHIDEventSetIntegerValue(hand, kIOHIDEventFieldDigitizerIsDisplayIntegrated, true);
+
+ IOHIDEventRef finger(IOHIDEventCreateDigitizerFingerEvent(kCFAllocatorDefault, mach_absolute_time(), 3, 2, fingerm, xf, yf, 0, 0, 0, tis, tis, 0));
+ IOHIDEventAppendEvent(hand, finger);
+ CFRelease(finger);
+
+ VNCSetSender(hand);
+ IOHIDEventSystemConnectionDispatchEvent(connection, hand);
+ CFRelease(hand);