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
CFStringEncoding encoding
) ;
+FUNCTION: CFStringRef CFCopyDescription ( CFTypeRef cf ) ;
+FUNCTION: CFStringRef CFCopyTypeIDDescription ( CFTypeID type_id ) ;
+
: prepare-CFString ( string -- byte-array )
[
dup HEX: 10ffff >
: <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
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
: 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 ;
TYPEDEF: uint IOHIDElementFlags
TYPEDEF: void* IOHIDDeviceRef
TYPEDEF: void* IOHIDElementRef
+TYPEDEF: void* IOHIDQueueRef
TYPEDEF: void* IOHIDValueRef
TYPEDEF: void* IOHIDManagerRef
TYPEDEF: void* IOHIDTransactionRef
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 ) ;