game.input.iokit: deal with Lion's breakage of the IOHID* API
parent
62332cfa17
commit
f6d90ce51f
|
@ -3,7 +3,7 @@
|
||||||
USING: alien.c-types alien.data alien.syntax alien.strings
|
USING: alien.c-types alien.data alien.syntax alien.strings
|
||||||
io.encodings.string kernel sequences byte-arrays
|
io.encodings.string kernel sequences byte-arrays
|
||||||
io.encodings.utf8 math core-foundation core-foundation.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
|
IN: core-foundation.strings
|
||||||
|
|
||||||
TYPEDEF: void* CFStringRef
|
TYPEDEF: void* CFStringRef
|
||||||
|
@ -60,6 +60,9 @@ FUNCTION: CFStringRef CFStringCreateWithCString (
|
||||||
CFStringEncoding encoding
|
CFStringEncoding encoding
|
||||||
) ;
|
) ;
|
||||||
|
|
||||||
|
FUNCTION: CFStringRef CFCopyDescription ( CFTypeRef cf ) ;
|
||||||
|
FUNCTION: CFStringRef CFCopyTypeIDDescription ( CFTypeID type_id ) ;
|
||||||
|
|
||||||
: prepare-CFString ( string -- byte-array )
|
: prepare-CFString ( string -- byte-array )
|
||||||
[
|
[
|
||||||
dup HEX: 10ffff >
|
dup HEX: 10ffff >
|
||||||
|
@ -88,6 +91,11 @@ FUNCTION: CFStringRef CFStringCreateWithCString (
|
||||||
: <CFStringArray> ( seq -- alien )
|
: <CFStringArray> ( seq -- alien )
|
||||||
[ [ <CFString> &CFRelease ] map <CFArray> ] with-destructors ;
|
[ [ <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:
|
SYNTAX: CFSTRING:
|
||||||
CREATE scan-object
|
CREATE scan-object
|
||||||
[ drop ] [ '[ _ [ _ <CFString> ] initialize-alien ] ] 2bi
|
[ drop ] [ '[ _ [ _ <CFString> ] initialize-alien ] ] 2bi
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
USING: cocoa cocoa.plists core-foundation iokit iokit.hid
|
USING: cocoa cocoa.plists core-foundation iokit iokit.hid
|
||||||
kernel cocoa.enumeration destructors math.parser cocoa.application
|
kernel cocoa.enumeration destructors math.parser cocoa.application
|
||||||
|
core-foundation.data core-foundation.strings
|
||||||
sequences locals combinators.short-circuit threads
|
sequences locals combinators.short-circuit threads
|
||||||
namespaces assocs arrays combinators hints alien
|
namespaces assocs arrays combinators hints alien
|
||||||
core-foundation.run-loop accessors sequences.private
|
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 ( -- alien )
|
||||||
[ (device-removed-callback) ] IOHIDDeviceCallback ;
|
[ (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 -- )
|
:: (device-input-callback) ( context result sender value -- )
|
||||||
|
sender get-input-device :> device
|
||||||
{
|
{
|
||||||
{ [ sender mouse-device? ] [ +mouse-state+ get-global value record-mouse ] }
|
{ [ device mouse-device? ] [ +mouse-state+ get-global value record-mouse ] }
|
||||||
{ [ sender controller-device? ] [
|
{ [ device controller-device? ] [
|
||||||
sender +controller-states+ get-global at value record-controller
|
device +controller-states+ get-global at value record-controller
|
||||||
] }
|
] }
|
||||||
[ +keyboard-state+ get-global value record-keyboard ]
|
[ +keyboard-state+ get-global value record-keyboard ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
|
@ -125,6 +125,7 @@ TYPEDEF: uint IOHIDQueueOptionsType
|
||||||
TYPEDEF: uint IOHIDElementFlags
|
TYPEDEF: uint IOHIDElementFlags
|
||||||
TYPEDEF: void* IOHIDDeviceRef
|
TYPEDEF: void* IOHIDDeviceRef
|
||||||
TYPEDEF: void* IOHIDElementRef
|
TYPEDEF: void* IOHIDElementRef
|
||||||
|
TYPEDEF: void* IOHIDQueueRef
|
||||||
TYPEDEF: void* IOHIDValueRef
|
TYPEDEF: void* IOHIDValueRef
|
||||||
TYPEDEF: void* IOHIDManagerRef
|
TYPEDEF: void* IOHIDManagerRef
|
||||||
TYPEDEF: void* IOHIDTransactionRef
|
TYPEDEF: void* IOHIDTransactionRef
|
||||||
|
@ -253,3 +254,7 @@ FUNCTION: IOReturn IOHIDTransactionCommit ( IOHIDTransactionRef transaction ) ;
|
||||||
FUNCTION: IOReturn IOHIDTransactionCommitWithCallback ( IOHIDTransactionRef transaction, CFTimeInterval timeout, IOHIDCallback callback, void* context ) ;
|
FUNCTION: IOReturn IOHIDTransactionCommitWithCallback ( IOHIDTransactionRef transaction, CFTimeInterval timeout, IOHIDCallback callback, void* context ) ;
|
||||||
FUNCTION: void IOHIDTransactionClear ( IOHIDTransactionRef transaction ) ;
|
FUNCTION: void IOHIDTransactionClear ( IOHIDTransactionRef transaction ) ;
|
||||||
|
|
||||||
|
! IOHIDQueue
|
||||||
|
|
||||||
|
FUNCTION: CFTypeID IOHIDQueueGetTypeID ( ) ;
|
||||||
|
FUNCTION: IOHIDDeviceRef IOHIDQueueGetDevice ( IOHIDQueueRef queue ) ;
|
||||||
|
|
Loading…
Reference in New Issue