1 ! Copyright (C) 2010 Erik Charlebois.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types alien.syntax arrays kernel game.input namespaces
4 classes bit-arrays sequences vectors x11 x11.xlib ;
7 SINGLETON: linux-game-input-backend
9 linux-game-input-backend game-input-backend set-global
11 M: linux-game-input-backend (open-game-input)
14 M: linux-game-input-backend (close-game-input)
17 M: linux-game-input-backend (reset-game-input)
20 M: linux-game-input-backend get-controllers
23 M: linux-game-input-backend product-string
26 M: linux-game-input-backend product-id
29 M: linux-game-input-backend instance-id
32 M: linux-game-input-backend read-controller
33 drop controller-state new ;
35 M: linux-game-input-backend calibrate-controller
38 M: linux-game-input-backend vibrate-controller
41 CONSTANT: x>hid-bit-order {
43 0 41 30 31 32 33 34 35
44 36 37 38 39 45 46 42 43
45 20 26 8 21 23 28 24 12
46 18 19 47 48 40 224 4 22
48 52 53 225 49 29 27 6 25
49 5 17 16 54 55 56 229 85
50 226 44 57 58 59 60 61 62
51 63 64 65 66 67 83 71 95
52 96 97 86 92 93 94 87 91
55 228 84 70 0 0 74 82 75
56 80 79 77 81 78 73 76 127
57 129 128 102 103 0 72 0 0
76 : x-bits>hid-bits ( bit-array -- bit-array )
77 256 iota [ 2array ] 2map [ first ] filter [ second ] map
78 x>hid-bit-order [ nth ] with map
79 ?{ } swap [ t swap pick set-nth ] each ;
81 M: linux-game-input-backend read-keyboard
82 dpy get 256 <bit-array> [ XQueryKeymap drop ] keep
83 x-bits>hid-bits keyboard-state boa ;
85 M: linux-game-input-backend read-mouse
86 0 0 0 0 2 <vector> mouse-state boa ;
88 M: linux-game-input-backend reset-mouse