]> gitweb.factorcode.org Git - factor.git/blob - basis/game/input/linux/linux.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / game / input / linux / linux.factor
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 ;
5 IN: game.input.linux
6
7 SINGLETON: linux-game-input-backend
8
9 linux-game-input-backend game-input-backend set-global
10
11 M: linux-game-input-backend (open-game-input)
12     ;
13
14 M: linux-game-input-backend (close-game-input)
15     ;
16
17 M: linux-game-input-backend (reset-game-input)
18     ;
19
20 M: linux-game-input-backend get-controllers
21     { } ;
22
23 M: linux-game-input-backend product-string
24     drop "" ;
25      
26 M: linux-game-input-backend product-id
27     drop f ;
28      
29 M: linux-game-input-backend instance-id
30     drop f ;
31      
32 M: linux-game-input-backend read-controller
33     drop controller-state new ;
34      
35 M: linux-game-input-backend calibrate-controller
36     drop ;
37      
38 M: linux-game-input-backend vibrate-controller
39     3drop ;
40
41 CONSTANT: x>hid-bit-order {
42     0 0 0 0 0 0 0 0 
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 
47     7 9 10 11 13 14 15 51 
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 
53     90 89 99 0 0 0 68 69 
54     0 0 0 0 0 0 0 88 
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 
58     0 0 227 231 0 0 0 0 
59     0 0 0 0 0 0 0 0 
60     0 0 0 0 0 0 0 0 
61     0 0 0 0 0 0 0 0 
62     0 0 0 0 0 0 0 0 
63     0 0 0 0 0 0 0 0 
64     0 0 0 0 0 0 0 0 
65     0 0 0 0 0 0 0 0 
66     0 0 0 0 0 0 0 0 
67     0 0 0 0 0 0 0 0 
68     0 0 0 0 0 0 0 0 
69     0 0 0 0 0 0 0 0 
70     0 0 0 0 0 0 0 0 
71     0 0 0 0 0 0 0 0 
72     0 0 0 0 0 0 0 0 
73     0 0 0 0 0 0 0 0 
74 }
75      
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 ;
80         
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 ;
84      
85 M: linux-game-input-backend read-mouse
86     0 0 0 0 2 <vector> mouse-state boa ;
87      
88 M: linux-game-input-backend reset-mouse
89     ;