From 5e83be0dbf9667f7d11a167f9eacc31837ed4c7d Mon Sep 17 00:00:00 2001 From: Marius Eriksen Date: Mon, 20 Jun 2011 14:14:53 -0400 Subject: devdraw: dynamic discovery of MultiTouch devices R=rsc CC=plan9port.codebot http://codereview.appspot.com/4653041 --- CONTRIBUTORS | 1 + src/cmd/devdraw/osx-screen-carbon.m | 114 +++++++++++++++++++++++++++++++++--- 2 files changed, 107 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 414fa9b3..c188fc74 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -17,6 +17,7 @@ Fazlul Shahriar J.R. Mauro Jeff Sickel Kris Maglione +Marius Eriksen Mathieu Lonjaret Mathieu Lonjaret Michael Teichgräber diff --git a/src/cmd/devdraw/osx-screen-carbon.m b/src/cmd/devdraw/osx-screen-carbon.m index 2f295a03..93d58ce0 100644 --- a/src/cmd/devdraw/osx-screen-carbon.m +++ b/src/cmd/devdraw/osx-screen-carbon.m @@ -2,6 +2,10 @@ #define Rect OSXRect #define Cursor OSXCursor #include +#ifdef MULTITOUCH +#include +#include +#endif #undef Rect #undef Point #undef Cursor @@ -26,6 +30,7 @@ AUTOFRAMEWORK(Cocoa) #ifdef MULTITOUCH AUTOFRAMEWORK(MultitouchSupport) +AUTOFRAMEWORK(IOKit) #endif #define panic sysfatal @@ -115,11 +120,15 @@ CFMutableArrayRef MTDeviceCreateList(void); //registers a device's frame callback to your callback function void MTRegisterContactFrameCallback(MTDeviceRef, MTContactCallbackFunction); +void MTUnregisterContactFrameCallback(MTDeviceRef, MTContactCallbackFunction); //start sending events void MTDeviceStart(MTDeviceRef, int); void MTDeviceStop(MTDeviceRef); +MTDeviceRef MTDeviceCreateFromService(io_service_t); +io_service_t MTDeviceGetService(MTDeviceRef); + #define kNTracks 10 struct TouchTrack { int id; @@ -280,25 +289,114 @@ enum void screeninit(void); void _flushmemscreen(Rectangle r); +#ifdef MULTITOUCH +static void +RegisterMultitouch(void *ctx, io_iterator_t iter) +{ + io_object_t io; + MTDeviceRef dev; + + while((io = IOIteratorNext(iter)) != 0){ + dev = MTDeviceCreateFromService(io); + if (dev != nil){ + MTRegisterContactFrameCallback(dev, touchCallback); + [osx.devicelist addObject:dev]; + if(osx.active) + MTDeviceStart(dev, 0); + } + + IOObjectRelease(io); + } +} + static void -InitMultiTouch(void) +UnregisterMultitouch(void *ctx, io_iterator_t iter) +{ + io_object_t io; + MTDeviceRef dev; + int i; + + while((io = IOIteratorNext(iter)) != 0){ + for(i = 0; i < [osx.devicelist count]; i++){ + dev = [osx.devicelist objectAtIndex:i]; + if(IOObjectIsEqualTo(MTDeviceGetService(dev), io)){ + if(osx.active) + MTDeviceStop(dev); + MTUnregisterContactFrameCallback(dev, touchCallback); + [osx.devicelist removeObjectAtIndex:i]; + break; + } + } + + IOObjectRelease(io); + } +} + +#endif /*MULTITOUCH*/ + +static void +InitMultiTouch() { #ifdef MULTITOUCH + IONotificationPortRef port; + CFRunLoopSourceRef source; + io_iterator_t iter; + kern_return_t kr; + io_object_t obj; int i; - /* - * Setup multitouch queues - */ if(!multitouch) return; - for(i = 0; i