diff --git a/basis/game/input/gtk/authors.txt b/basis/game/input/gtk/authors.txt new file mode 100644 index 0000000000..d73be90188 --- /dev/null +++ b/basis/game/input/gtk/authors.txt @@ -0,0 +1,2 @@ +Erik Charlebois +William Schlieper diff --git a/basis/game/input/gtk/gtk.factor b/basis/game/input/gtk/gtk.factor new file mode 100644 index 0000000000..9eac60022a --- /dev/null +++ b/basis/game/input/gtk/gtk.factor @@ -0,0 +1,114 @@ +! Copyright (C) 2010 Erik Charlebois, William Schlieper. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors alien.c-types alien.data alien.syntax assocs +bit-arrays game.input gdk.ffi generalizations kernel math +namespaces sequences system x11.xlib ; +IN: game.input.gtk + +SINGLETON: gtk-game-input-backend + +gtk-game-input-backend game-input-backend set-global + +LIBRARY: gdk +FUNCTION: Display* gdk_x11_display_get_xdisplay ( GdkDisplay* display ) ; + +: get-dpy ( -- dpy ) + gdk_display_get_default gdk_x11_display_get_xdisplay ; + +M: gtk-game-input-backend (open-game-input) + ; + +M: gtk-game-input-backend (close-game-input) + ; + +M: gtk-game-input-backend (reset-game-input) + ; + +M: gtk-game-input-backend get-controllers + { } ; + +M: gtk-game-input-backend product-string + drop "" ; + +M: gtk-game-input-backend product-id + drop f ; + +M: gtk-game-input-backend instance-id + drop f ; + +M: gtk-game-input-backend read-controller + drop controller-state new ; + +M: gtk-game-input-backend calibrate-controller + drop ; + +M: gtk-game-input-backend vibrate-controller + 3drop ; + +HOOK: x>hid-bit-order os ( -- x ) + +M: linux 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 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 + } ; inline + +: x-bits>hid-bits ( bit-array -- bit-array ) + 256 iota zip [ first ] filter values + x>hid-bit-order [ nth ] curry map + 256 swap [ t swap pick set-nth ] each ; + +M: gtk-game-input-backend read-keyboard + get-dpy 256 [ XQueryKeymap drop ] keep + x-bits>hid-bits keyboard-state boa ; + +: query-pointer ( -- x y buttons ) + get-dpy dup XDefaultRootWindow + { int int int int int int int } + [ XQueryPointer drop ] with-out-parameters + [ 4 ndrop ] 3dip ; + +SYMBOL: mouse-reset? + +M: gtk-game-input-backend read-mouse + mouse-reset? get [ reset-mouse ] unless + query-pointer + mouse-state new + swap 256 /i >>buttons + swap 400 - >>dy + swap 400 - >>dx + 0 >>scroll-dy 0 >>scroll-dx ; + +M: gtk-game-input-backend reset-mouse + get-dpy dup XDefaultRootWindow dup + 0 0 0 0 400 400 XWarpPointer drop t mouse-reset? set-global ; diff --git a/basis/game/input/gtk/platforms.txt b/basis/game/input/gtk/platforms.txt new file mode 100644 index 0000000000..a08e1f35eb --- /dev/null +++ b/basis/game/input/gtk/platforms.txt @@ -0,0 +1 @@ +linux diff --git a/basis/game/input/gtk/summary.txt b/basis/game/input/gtk/summary.txt new file mode 100644 index 0000000000..5c88274722 --- /dev/null +++ b/basis/game/input/gtk/summary.txt @@ -0,0 +1 @@ +Linux backend for game input. diff --git a/basis/game/input/gtk/tags.txt b/basis/game/input/gtk/tags.txt new file mode 100644 index 0000000000..84d4140a70 --- /dev/null +++ b/basis/game/input/gtk/tags.txt @@ -0,0 +1 @@ +games diff --git a/basis/game/input/input.factor b/basis/game/input/input.factor index 213b638574..eb01e94b99 100644 --- a/basis/game/input/input.factor +++ b/basis/game/input/input.factor @@ -108,6 +108,6 @@ SYMBOLS: pressed released ; { { [ os windows? ] [ "game.input.dinput" require ] } { [ os macosx? ] [ "game.input.iokit" require ] } - { [ os linux? ] [ "game.input.x11" require ] } + { [ os linux? ] [ "game.input.gtk" require ] } [ ] } cond