]> gitweb.factorcode.org Git - factor.git/commitdiff
game.input.iokit: deal with Lion's breakage of the IOHID* API
authorJoe Groff <arcata@gmail.com>
Fri, 29 Jul 2011 20:24:10 +0000 (13:24 -0700)
committerJoe Groff <arcata@gmail.com>
Fri, 29 Jul 2011 20:24:10 +0000 (13:24 -0700)
basis/core-foundation/strings/strings.factor
basis/game/input/iokit/iokit.factor
basis/iokit/hid/hid.factor

index 24bb38e09c5a15347c4547f2ea5f4c824296eddc..11d28024f875d2eabfebe0120b32adc9c0ee7ac1 100644 (file)
@@ -3,7 +3,7 @@
 USING: alien.c-types alien.data alien.syntax alien.strings
 io.encodings.string kernel sequences byte-arrays
 io.encodings.utf8 math core-foundation core-foundation.arrays
-destructors parser fry alien words ;
+core-foundation.data destructors parser fry alien words ;
 IN: core-foundation.strings
 
 TYPEDEF: void* CFStringRef
@@ -60,6 +60,9 @@ FUNCTION: CFStringRef CFStringCreateWithCString (
     CFStringEncoding encoding
 ) ;
 
+FUNCTION: CFStringRef CFCopyDescription ( CFTypeRef cf ) ;
+FUNCTION: CFStringRef CFCopyTypeIDDescription ( CFTypeID type_id ) ;
+
 : prepare-CFString ( string -- byte-array )
     [
         dup HEX: 10ffff >
@@ -88,6 +91,11 @@ FUNCTION: CFStringRef CFStringCreateWithCString (
 : <CFStringArray> ( seq -- alien )
     [ [ <CFString> &CFRelease ] map <CFArray> ] with-destructors ;
 
+: CF>description ( cf -- description )
+    [ CFCopyDescription &CFRelease CF>string ] with-destructors ;
+: CFType>description ( cf -- description )
+    CFGetTypeID [ CFCopyTypeIDDescription &CFRelease CF>string ] with-destructors ;
+
 SYNTAX: CFSTRING: 
     CREATE scan-object 
     [ drop ] [ '[ _ [ _ <CFString> ] initialize-alien ] ] 2bi
index 083be8e74f9979580d65f4bc6bc7fdd9a102246b..3a953e8babf4993c8143e782bfb27554d4da6ac4 100644 (file)
@@ -1,5 +1,6 @@
 USING: cocoa cocoa.plists core-foundation iokit iokit.hid
 kernel cocoa.enumeration destructors math.parser cocoa.application 
+core-foundation.data core-foundation.strings
 sequences locals combinators.short-circuit threads
 namespaces assocs arrays combinators hints alien
 core-foundation.run-loop accessors sequences.private
@@ -270,11 +271,26 @@ M: iokit-game-input-backend reset-mouse
 : device-removed-callback ( -- alien )
     [ (device-removed-callback) ] IOHIDDeviceCallback ;
 
+! Lion sends the input callback an IOHIDQueue as the "sender".
+! Leopard and Snow Leopard send an IOHIDDevice.
+! This function gets the IOHIDDevice regardless of which is received
+: get-input-device ( sender -- device )
+    dup CFGetTypeID {
+        { [ dup IOHIDDeviceGetTypeID = ] [ drop ] }
+        { [ dup IOHIDQueueGetTypeID = ] [ drop IOHIDQueueGetDevice ] }
+        [
+            drop
+            "input callback doesn't know how to deal with "
+            swap CF>description append throw
+        ]
+    } cond ;
+
 :: (device-input-callback) ( context result sender value -- )
+    sender get-input-device :> device
     {
-        { [ sender mouse-device? ] [ +mouse-state+ get-global value record-mouse ] }
-        { [ sender controller-device? ] [
-            sender +controller-states+ get-global at value record-controller
+        { [ device mouse-device? ] [ +mouse-state+ get-global value record-mouse ] }
+        { [ device controller-device? ] [
+            device +controller-states+ get-global at value record-controller
         ] }
         [ +keyboard-state+ get-global value record-keyboard ]
     } cond ;
index a2ac0d5e6f359ad3b81de2a2bc58751cc1781ae0..e72a3517ba4b6df7285da2c1642ce9fbb5696b64 100644 (file)
@@ -125,6 +125,7 @@ TYPEDEF: uint IOHIDQueueOptionsType
 TYPEDEF: uint IOHIDElementFlags
 TYPEDEF: void* IOHIDDeviceRef
 TYPEDEF: void* IOHIDElementRef
+TYPEDEF: void* IOHIDQueueRef
 TYPEDEF: void* IOHIDValueRef
 TYPEDEF: void* IOHIDManagerRef
 TYPEDEF: void* IOHIDTransactionRef
@@ -253,3 +254,7 @@ FUNCTION: IOReturn IOHIDTransactionCommit ( IOHIDTransactionRef transaction ) ;
 FUNCTION: IOReturn IOHIDTransactionCommitWithCallback ( IOHIDTransactionRef transaction, CFTimeInterval timeout, IOHIDCallback callback, void* context ) ;
 FUNCTION: void IOHIDTransactionClear ( IOHIDTransactionRef transaction ) ;
 
+! IOHIDQueue
+
+FUNCTION: CFTypeID IOHIDQueueGetTypeID ( ) ;
+FUNCTION: IOHIDDeviceRef IOHIDQueueGetDevice ( IOHIDQueueRef queue ) ;