Fix X11 input problems

db4
slava 2008-11-22 00:23:56 -06:00
parent 0efa5e09c9
commit ae8e3ecb78
2 changed files with 15 additions and 7 deletions

View File

@ -82,7 +82,7 @@ SYMBOLS: C+ A+ M+ S+ ;
TUPLE: key-down mods sym ;
: <key-gesture> ( mods sym action? class -- mods' sym' )
[ [ S+ rot remove swap ] unless ] dip boa ; inline
[ [ [ S+ swap remove f like ] dip ] unless ] dip boa ; inline
: <key-down> ( mods sym action? -- key-down )
key-down <key-gesture> ;

View File

@ -7,7 +7,7 @@ x11.events x11.xim x11.glx x11.clipboard x11.constants
x11.windows io.encodings.string io.encodings.ascii
io.encodings.utf8 combinators debugger command-line qualified
math.vectors classes.tuple opengl.gl threads math.geometry.rect
environment ;
environment ascii ;
IN: ui.x11
SINGLETON: x11-ui-backend
@ -67,18 +67,26 @@ M: world configure-event
: event-modifiers ( event -- seq )
XKeyEvent-state modifiers modifier ;
: valid-input? ( string gesture -- ? )
over empty? [ 2drop f ] [
mods>> { f { S+ } } member? [
[ [ 127 = not ] [ CHAR: \s >= ] bi and ] all?
] [
[ [ 127 = not ] [ CHAR: \s >= ] [ alpha? not ] tri and and ] all?
] if
] if ;
: key-down-event>gesture ( event world -- string gesture )
dupd
handle>> xic>> lookup-string
>r swap event-modifiers r> key-code <key-down> ;
: valid-input? ( string -- ? )
[ f ] [ [ [ 127 = not ] [ CHAR: \s >= ] bi and ] all? ] if-empty ;
M: world key-down-event
[ key-down-event>gesture ] keep
world-focus [ propagate-gesture ] keep
over valid-input? [ user-input ] [ 2drop ] if ;
world-focus
[ propagate-gesture drop ]
[ 2over valid-input? [ nip user-input ] [ 3drop ] if ]
3bi ;
: key-up-event>gesture ( event -- gesture )
dup event-modifiers swap 0 XLookupKeysym key-code <key-up> ;