]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/game-input/iokit/iokit.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / basis / game-input / iokit / iokit.factor
index 32440e92b2bb1eabc7471e24411617070c006a81..71d547ad29ed7521f7ac1c78678a524ea117cc9f 100755 (executable)
@@ -1,7 +1,7 @@
 USING: cocoa cocoa.plists core-foundation iokit iokit.hid
 kernel cocoa.enumeration destructors math.parser cocoa.application 
 sequences locals combinators.short-circuit threads
-namespaces assocs vectors arrays combinators hints alien
+namespaces assocs arrays combinators hints alien
 core-foundation.run-loop accessors sequences.private
 alien.c-types math parser game-input vectors bit-arrays ;
 IN: game-input.iokit
@@ -12,10 +12,11 @@ SYMBOLS: +hid-manager+ +keyboard-state+ +mouse-state+ +controller-states+ ;
 
 iokit-game-input-backend game-input-backend set-global
 
-: hid-manager-matching ( matching-seq -- alien )
-    f 0 IOHIDManagerCreate
-    [ swap >plist IOHIDManagerSetDeviceMatchingMultiple ]
-    keep ;
+: make-hid-manager ( -- alien )
+    f 0 IOHIDManagerCreate ;
+
+: set-hid-manager-matching ( alien matching-seq -- )
+    >plist IOHIDManagerSetDeviceMatchingMultiple ;
 
 : devices-from-hid-manager ( manager -- vector )
     [
@@ -85,9 +86,6 @@ CONSTANT: hat-switch-matching-hash
 : ?hat-switch ( device -- ? )
     hat-switch-matching-hash ?axis ;
 
-: hid-manager-matching-game-devices ( -- alien )
-    game-devices-matching-seq hid-manager-matching ;
-
 : device-property ( device key -- value )
     <NSString> IOHIDDeviceGetProperty [ plist> ] [ f ] if* ;
 : element-property ( element key -- value )
@@ -155,7 +153,7 @@ CONSTANT: pov-values
     IOHIDValueGetIntegerValue pov-values ?nth [ pov-neutral ] unless* ;
 
 : record-button ( state hid-value element -- )
-    [ buttons>> ] [ button-value ] [ IOHIDElementGetUsage 1- ] tri* rot set-nth ;
+    [ buttons>> ] [ button-value ] [ IOHIDElementGetUsage 1 - ] tri* rot set-nth ;
 
 : record-controller ( controller-state value -- )
     dup IOHIDValueGetElement {
@@ -288,12 +286,13 @@ M: iokit-game-input-backend reset-mouse
     256 <bit-array> +keyboard-state+ set-global ;
 
 M: iokit-game-input-backend (open-game-input)
-    hid-manager-matching-game-devices {
+    make-hid-manager {
         [ initialize-variables ]
         [ device-matched-callback f IOHIDManagerRegisterDeviceMatchingCallback ]
         [ device-removed-callback f IOHIDManagerRegisterDeviceRemovalCallback ]
         [ device-input-callback f IOHIDManagerRegisterInputValueCallback ]
         [ 0 IOHIDManagerOpen mach-error ]
+        [ game-devices-matching-seq set-hid-manager-matching ]
         [
             CFRunLoopGetMain CFRunLoopDefaultMode
             IOHIDManagerScheduleWithRunLoop