Implement input grabbing for x11; add do-nothing game.input backend for linux. The game and gpu demos now run correctly.

db4
Erik Charlebois 2010-02-18 12:52:33 -08:00
parent f2e8128f5d
commit d3d7392fa9
7 changed files with 91 additions and 10 deletions

View 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

View File

@ -0,0 +1 @@
Erik Charlebois

View File

@ -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
;

View File

@ -0,0 +1 @@
Linux backend for game input.

View File

@ -0,0 +1 @@
games

View 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" ? ]

View 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
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!