From ea4d261a45ba7c24bf2ca19d21c73a5fda13b22b Mon Sep 17 00:00:00 2001 From: William Schlieper Date: Sat, 20 Feb 2010 08:09:49 -0500 Subject: [PATCH 1/3] Added rudimentary x11 support in game.input --- basis/game/input/input.factor | 1 + basis/game/input/x11/x11.factor | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 basis/game/input/x11/x11.factor diff --git a/basis/game/input/input.factor b/basis/game/input/input.factor index a2afbe92a3..923d5d6107 100644 --- a/basis/game/input/input.factor +++ b/basis/game/input/input.factor @@ -93,5 +93,6 @@ M: mouse-state clone { { [ os windows? ] [ "game.input.xinput" require ] } { [ os macosx? ] [ "game.input.iokit" require ] } + { [ os linux? ] [ "game.input.x11" require ] } { [ t ] [ ] } } cond diff --git a/basis/game/input/x11/x11.factor b/basis/game/input/x11/x11.factor new file mode 100644 index 0000000000..c54fc4be5d --- /dev/null +++ b/basis/game/input/x11/x11.factor @@ -0,0 +1,67 @@ +USING: alien.c-types alien.syntax arrays bit-arrays game.input +kernel namespaces sequences x11 x11.xlib ; +IN: game.input.x11 + +SINGLETON: x11-game-input-backend + +x11-game-input-backend game-input-backend set-global + +LIBRARY: xlib +FUNCTION: int XQueryKeymap ( Display* display, char[32] keys_return ) ; + +CONSTANT: x>hid-bit-order { + 0 0 0 0 0 0 0 0 + 0 41 30 31 32 33 34 35 + 36 37 38 39 45 46 42 43 + 20 26 8 21 23 28 24 12 + 18 19 47 48 40 224 4 22 + 7 9 10 11 13 14 15 51 + 52 53 225 49 29 27 6 25 + 5 17 16 54 55 56 229 85 + 226 44 57 58 59 60 61 62 + 63 64 65 66 67 83 71 95 + 96 97 86 92 93 94 87 91 + 90 89 99 0 0 0 68 69 + 0 0 0 0 0 0 0 88 + 228 84 70 0 0 74 82 75 + 80 79 77 81 78 73 76 127 + 129 128 102 103 0 72 0 0 + 0 0 227 231 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 +} + +M: x11-game-input-backend (open-game-input) ; ! assume X was already started for now +M: x11-game-input-backend (close-game-input) ; ! let someone else stop X +M: x11-game-input-backend (reset-game-input) ; ! nothing to reset at this point + +! No controller support yet--if this works, I shouldn't even need to define the other methods +M: x11-game-input-backend get-controllers f ; + + +: x-bits>hid-bits ( bit-array -- bit-array ) + 256 iota [ 2array ] 2map [ first ] filter [ second ] map + x>hid-bit-order [ nth ] with map + ?{ } swap [ t swap pick set-nth ] each ; + +M: x11-game-input-backend read-keyboard + dpy get 256 [ XQueryKeymap drop ] keep + x-bits>hid-bits keyboard-state boa ; + +M: x11-game-input-backend read-mouse + 0 0 0 0 ?{ f f f } mouse-state boa ; + +M: x11-game-input-backend reset-mouse ; \ No newline at end of file From 47666f0049f045177956c43693ec0659b363b706 Mon Sep 17 00:00:00 2001 From: William Schlieper Date: Sat, 20 Feb 2010 08:35:02 -0500 Subject: [PATCH 2/3] Fixed a bug in the linux version of game.input --- basis/game/input/linux/linux.factor | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/basis/game/input/linux/linux.factor b/basis/game/input/linux/linux.factor index b307835d70..b6f3d43956 100644 --- a/basis/game/input/linux/linux.factor +++ b/basis/game/input/linux/linux.factor @@ -4,6 +4,9 @@ USING: alien.c-types alien.syntax arrays kernel game.input namespaces classes bit-arrays sequences vectors x11 x11.xlib ; IN: game.input.linux +LIBRARY: xlib +FUNCTION: int XQueryKeymap ( Display* display, char[32] keys_return ) ; + SINGLETON: linux-game-input-backend linux-game-input-backend game-input-backend set-global @@ -74,9 +77,9 @@ CONSTANT: x>hid-bit-order { } : x-bits>hid-bits ( bit-array -- bit-array ) - 256 iota [ 2array ] 2map [ first ] filter [ second ] map - x>hid-bit-order [ nth ] with map - ?{ } swap [ t swap pick set-nth ] each ; + 256 iota [ 2array ] { } 2map-as [ first ] filter [ second ] map + x>hid-bit-order [ nth ] curry map + 256 swap [ t swap pick set-nth ] each ; M: linux-game-input-backend read-keyboard dpy get 256 [ XQueryKeymap drop ] keep From f71e22eda57f6fccba98957b482a9a17d956fffd Mon Sep 17 00:00:00 2001 From: William Schlieper Date: Sat, 20 Feb 2010 09:36:58 -0500 Subject: [PATCH 3/3] Fixed ridiculously stupid error in Linux game.input library --- basis/game/input/linux/linux.factor | 65 +++++++++++++++-------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/basis/game/input/linux/linux.factor b/basis/game/input/linux/linux.factor index b6f3d43956..07889c8298 100644 --- a/basis/game/input/linux/linux.factor +++ b/basis/game/input/linux/linux.factor @@ -42,38 +42,39 @@ M: linux-game-input-backend vibrate-controller 3drop ; CONSTANT: x>hid-bit-order { - 0 0 0 0 0 0 0 0 - 0 41 30 31 32 33 34 35 - 36 37 38 39 45 46 42 43 - 20 26 8 21 23 28 24 12 - 18 19 47 48 40 224 4 22 - 7 9 10 11 13 14 15 51 - 52 53 225 49 29 27 6 25 - 5 17 16 54 55 56 229 85 - 226 44 57 58 59 60 61 62 - 63 64 65 66 67 83 71 95 - 96 97 86 92 93 94 87 91 - 90 89 99 0 0 0 68 69 - 0 0 0 0 0 0 0 88 - 228 84 70 0 0 74 82 75 - 80 79 77 81 78 73 76 127 - 129 128 102 103 0 72 0 0 - 0 0 227 231 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 + +0 0 0 0 0 0 0 0 +0 41 30 31 32 33 34 35 +36 37 38 39 45 46 42 43 +20 26 8 21 23 28 24 12 +18 19 47 48 40 224 4 22 +7 9 10 11 13 14 15 51 +52 53 225 49 29 27 6 25 +5 17 16 54 55 56 229 85 +226 44 57 58 59 60 61 62 +63 64 65 66 67 83 71 95 +96 97 86 92 93 94 87 91 +90 89 98 99 0 0 0 68 +69 0 0 0 0 0 0 0 +88 228 84 70 0 0 74 82 +75 80 79 77 81 78 73 76 +127 129 128 102 103 0 72 0 +0 0 0 227 231 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 } : x-bits>hid-bits ( bit-array -- bit-array )