]> gitweb.factorcode.org Git - factor.git/commitdiff
Implement input grabbing for x11; add do-nothing game.input backend for linux. The...
authorErik Charlebois <erikcharlebois@gmail.com>
Thu, 18 Feb 2010 20:52:33 +0000 (12:52 -0800)
committerErik Charlebois <erikcharlebois@gmail.com>
Thu, 18 Feb 2010 20:52:33 +0000 (12:52 -0800)
basis/game/input/input.factor
basis/game/input/linux/authors.txt [new file with mode: 0644]
basis/game/input/linux/linux.factor [new file with mode: 0644]
basis/game/input/linux/summary.txt [new file with mode: 0644]
basis/game/input/linux/tags.txt [new file with mode: 0644]
basis/ui/backend/x11/x11.factor
basis/x11/xlib/xlib.factor

index a2afbe92a31f1cf0e21cf618221de5b955f6f866..7543a05c608f76a2d69d37e05c62e4eaf5b1fed5 100644 (file)
@@ -93,5 +93,5 @@ M: mouse-state clone
 {
     { [ os windows? ] [ "game.input.xinput" require ] }
     { [ os macosx? ] [ "game.input.iokit" require ] }
-    { [ t ] [ ] }
+    { [ os linux? ] [ "game.input.linux" require ] }
 } cond
diff --git a/basis/game/input/linux/authors.txt b/basis/game/input/linux/authors.txt
new file mode 100644 (file)
index 0000000..67cf648
--- /dev/null
@@ -0,0 +1 @@
+Erik Charlebois
\ No newline at end of file
diff --git a/basis/game/input/linux/linux.factor b/basis/game/input/linux/linux.factor
new file mode 100644 (file)
index 0000000..465cefa
--- /dev/null
@@ -0,0 +1,49 @@
+! Copyright (C) 2010 Erik Charlebois.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel game.input namespaces classes windows.com.syntax
+bit-arrays
+vectors ;
+IN: game.input.linux
+
+SINGLETON: linux-game-input-backend
+
+linux-game-input-backend game-input-backend set-global
+
+M: linux-game-input-backend (open-game-input)
+    ;
+
+M: linux-game-input-backend (close-game-input)
+    ;
+
+M: linux-game-input-backend (reset-game-input)
+    ;
+
+M: linux-game-input-backend get-controllers
+    { } ;
+
+M: linux-game-input-backend product-string
+    drop "" ;
+     
+M: linux-game-input-backend product-id
+    drop GUID: {00000000-0000-0000-0000-000000000000} ;
+     
+M: linux-game-input-backend instance-id
+    drop GUID: {00000000-0000-0000-0000-000000000000} ;
+     
+M: linux-game-input-backend read-controller
+    drop controller-state new ;
+     
+M: linux-game-input-backend calibrate-controller
+    drop ;
+     
+M: linux-game-input-backend vibrate-controller
+    3drop ;
+     
+M: linux-game-input-backend read-keyboard
+    256 <bit-array> keyboard-state boa ;
+     
+M: linux-game-input-backend read-mouse
+    0 0 0 0 2 <vector> mouse-state boa ;
+     
+M: linux-game-input-backend reset-mouse
+    ;
diff --git a/basis/game/input/linux/summary.txt b/basis/game/input/linux/summary.txt
new file mode 100644 (file)
index 0000000..5c88274
--- /dev/null
@@ -0,0 +1 @@
+Linux backend for game input.
diff --git a/basis/game/input/linux/tags.txt b/basis/game/input/linux/tags.txt
new file mode 100644 (file)
index 0000000..84d4140
--- /dev/null
@@ -0,0 +1 @@
+games
index 4c977f17a4110a00a2c3b0a770a771a18b13da86..673dd8e9c3899a592e42bdcca393a1f8b7ea4c35 100644 (file)
@@ -1,14 +1,13 @@
 ! Copyright (C) 2005, 2009 Eduardo Cavazos and Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays ascii assocs colors
-classes.struct combinators io.encodings.ascii
-io.encodings.string io.encodings.utf8 kernel literals math
-namespaces sequences strings ui ui.backend ui.clipboards
-ui.event-loop ui.gadgets ui.gadgets.private ui.gadgets.worlds
-ui.gestures ui.pixel-formats ui.pixel-formats.private
-ui.private x11 x11.clipboard x11.constants x11.events x11.glx
-x11.io x11.windows x11.xim x11.xlib environment command-line
-combinators.short-circuit ;
+USING: accessors alien.c-types ascii assocs classes.struct combinators
+combinators.short-circuit command-line environment io.encodings.ascii
+io.encodings.string io.encodings.utf8 kernel literals locals math
+namespaces sequences specialized-arrays.instances.alien.c-types.uchar
+strings ui ui.backend ui.clipboards ui.event-loop ui.gadgets
+ui.gadgets.private ui.gadgets.worlds ui.gestures ui.pixel-formats
+ui.pixel-formats.private ui.private x11 x11.clipboard x11.constants
+x11.events x11.glx x11.io x11.windows x11.xim x11.xlib ;
 IN: ui.backend.x11
 
 SINGLETON: x11-ui-backend
@@ -328,6 +327,22 @@ M: x11-ui-backend (with-ui) ( quot -- )
 M: x11-ui-backend beep ( -- )
     dpy get 100 XBell drop ;
 
+: black ( -- xcolor ) 0 0 0 0 0 0 XColor <struct-boa> ; inline
+
+M:: x11-ui-backend (grab-input) ( handle -- )
+    handle window>>                                                  :> wnd
+    dpy get                                                          :> dpy
+    dpy wnd uchar-array{ 0 0 0 0 0 0 0 0 } 8 8 XCreateBitmapFromData :> pixmap
+    dpy pixmap dup black dup 0 0 XCreatePixmapCursor                 :> cursor
+
+    dpy wnd 1 NoEventMask GrabModeAsync dup wnd cursor CurrentTime XGrabPointer drop
+
+    dpy cursor XFreeCursor drop
+    dpy pixmap XFreePixmap drop ;
+
+M: x11-ui-backend (ungrab-input)
+    drop dpy get CurrentTime XUngrabPointer drop ;
+
 x11-ui-backend ui-backend set-global
 
 [ "DISPLAY" os-env "ui.tools" "listener" ? ]
index a6097c9dadde2fab2fec0c4ae01eda8ae7500338..7235aaf67960dce7a68cb43ae4124f5ad3059525 100644 (file)
@@ -284,6 +284,11 @@ X-FUNCTION: int XConvertSelection ( Display* display, Atom selection, Atom targe
 X-FUNCTION: Pixmap XCreatePixmap ( Display* display, Drawable d, uint width, uint height, uint depth ) ;
 X-FUNCTION: int XFreePixmap ( Display* display, Pixmap pixmap ) ;
 
+! 5.2 - Creating, Recoloring, and Freeing Cursors
+
+C-TYPE: XColor
+X-FUNCTION: Cursor XCreatePixmapCursor ( Display* display, Pixmap source, Pixmap mask, XColor* foreground_color, XColor* background_color, uint x, uint y ) ;
+X-FUNCTION: int XFreeCursor ( Display* display, Cursor cursor ) ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 ! 6 - Color Management Functions
@@ -1096,6 +1101,7 @@ X-FUNCTION: int XGrabPointer (
 X-FUNCTION: Status XUngrabPointer ( Display* display, Time time ) ;
 X-FUNCTION: Status XChangeActivePointerGrab ( Display* display, uint event_mask, Cursor cursor, Time time ) ;
 X-FUNCTION: Status XGrabKey ( Display* display, int keycode, uint modifiers, Window grab_window, Bool owner_events, int pointer_mode, int keyboard_mode ) ;
+X-FUNCTION: int XGrabKeyboard ( Display* display, Window grab_window, Bool owner_events, int pointer_mode, int keyboard_mode, Time time ) ;
 X-FUNCTION: Status XSetInputFocus ( Display* display, Window focus, int revert_to, Time time ) ;
 
 X-FUNCTION: Status XGetInputFocus ( Display* display,
@@ -1210,6 +1216,14 @@ STRUCT: XVisualInfo
         { colormap_size int }
         { bits_per_rgb int } ;
 
+! 16.9 Manipulating Bitmaps
+X-FUNCTION: Pixmap XCreateBitmapFromData (
+    Display* display,
+    Drawable d,
+    char* data,
+    uint width,
+    uint height ) ;
+
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 ! Appendix D - Compatibility Functions
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!