]> gitweb.factorcode.org Git - factor.git/blob - basis/game/input/x11/x11.factor
Merge branch 's3' of git://github.com/littledan/Factor into s3
[factor.git] / basis / game / input / x11 / x11.factor
1 ! Copyright (C) 2010 Erik Charlebois, William Schlieper.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays kernel game.input namespaces
4 classes bit-arrays system sequences vectors x11 x11.xlib ;
5 IN: game.input.x11
6
7 SINGLETON: x11-game-input-backend
8
9 x11-game-input-backend game-input-backend set-global
10
11 M: x11-game-input-backend (open-game-input)
12     ;
13
14 M: x11-game-input-backend (close-game-input)
15     ;
16
17 M: x11-game-input-backend (reset-game-input)
18     ;
19
20 M: x11-game-input-backend get-controllers
21     { } ;
22
23 M: x11-game-input-backend product-string
24     drop "" ;
25      
26 M: x11-game-input-backend product-id
27     drop f ;
28      
29 M: x11-game-input-backend instance-id
30     drop f ;
31      
32 M: x11-game-input-backend read-controller
33     drop controller-state new ;
34      
35 M: x11-game-input-backend calibrate-controller
36     drop ;
37      
38 M: x11-game-input-backend vibrate-controller
39     3drop ;
40
41 HOOK: x>hid-bit-order os ( -- x )
42
43 M: linux x>hid-bit-order
44     {
45         0 0 0 0 0 0 0 0 
46         0 41 30 31 32 33 34 35 
47         36 37 38 39 45 46 42 43 
48         20 26 8 21 23 28 24 12 
49         18 19 47 48 40 224 4 22 
50         7 9 10 11 13 14 15 51 
51         52 53 225 49 29 27 6 25 
52         5 17 16 54 55 56 229 85 
53         226 44 57 58 59 60 61 62 
54         63 64 65 66 67 83 71 95 
55         96 97 86 92 93 94 87 91 
56         90 89 98 99 0 0 0 68 
57         69 0 0 0 0 0 0 0 
58         88 228 84 70 0 0 74 82 
59         75 80 79 77 81 78 73 76 
60         127 129 128 102 103 0 72 0 
61         0 0 0 227 231 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         0 0 0 0 0 0 0 0 
75         0 0 0 0 0 0 0 0 
76         0 0 0 0 0 0 0 0 
77     } ; inline
78      
79 : x-bits>hid-bits ( bit-array -- bit-array )
80     256 iota [ 2array ] { } 2map-as [ first ] filter [ second ] map
81     x>hid-bit-order [ nth ] curry map
82     256 <bit-array> swap [ t swap pick set-nth ] each ;
83         
84 M: x11-game-input-backend read-keyboard
85     dpy get 256 <bit-array> [ XQueryKeymap drop ] keep
86     x-bits>hid-bits keyboard-state boa ;
87      
88 M: x11-game-input-backend read-mouse
89     0 0 0 0 2 <vector> mouse-state boa ;
90      
91 M: x11-game-input-backend reset-mouse
92     ;