factor/basis/x11/xim/xim.factor

58 lines
1.5 KiB
Factor
Raw Normal View History

2008-12-03 01:05:46 -05:00
! Copyright (C) 2007, 2008 Slava Pestov
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-12-03 01:05:46 -05:00
USING: alien alien.c-types alien.strings arrays byte-arrays
hashtables io io.encodings.string kernel math namespaces
sequences strings continuations x11 x11.xlib
specialized-arrays accessors io.encodings.utf16n ;
SPECIALIZED-ARRAY: uint
2007-09-20 18:09:08 -04:00
IN: x11.xim
SYMBOL: xim
2008-02-11 01:41:41 -05:00
: (init-xim) ( classname medifier -- im )
2008-12-18 19:09:22 -05:00
XSetLocaleModifiers [ "XSetLocaleModifiers() failed" throw ] unless
[ dpy get f ] dip dup XOpenIM ;
2008-02-11 01:41:41 -05:00
2007-09-20 18:09:08 -04:00
: init-xim ( classname -- )
2008-12-18 19:09:22 -05:00
dup "" (init-xim)
[ nip ]
[ "@im=none" (init-xim) [ "XOpenIM() failed" throw ] unless* ] if*
xim set-global ;
2007-09-20 18:09:08 -04:00
: close-xim ( -- )
xim get-global XCloseIM drop f xim set-global ;
: with-xim ( quot -- )
2009-04-15 20:03:44 -04:00
[ "Factor" init-xim ] dip [ close-xim ] [ ] cleanup ; inline
2007-09-20 18:09:08 -04:00
: create-xic ( window classname -- xic )
2008-12-03 01:05:46 -05:00
[
[ xim get-global XNClientWindow ] dip
XNFocusWindow over
XNInputStyle XIMPreeditNothing XIMStatusNothing bitor
XNResourceName
] dip
2007-09-20 18:09:08 -04:00
XNResourceClass over 0 XCreateIC
[ "XCreateIC() failed" throw ] unless* ;
CONSTANT: buf-size 100
2007-09-20 18:09:08 -04:00
SYMBOL: keybuf
SYMBOL: keysym
: prepare-lookup ( -- )
2008-11-14 21:18:16 -05:00
buf-size <uint-array> keybuf set
2007-09-20 18:09:08 -04:00
0 <KeySym> keysym set ;
: finish-lookup ( len -- string keysym )
2008-11-14 21:18:16 -05:00
keybuf get swap 2 * head utf16n decode
2007-09-20 18:09:08 -04:00
keysym get *KeySym ;
: lookup-string ( event xic -- string keysym )
[
prepare-lookup
swap keybuf get buf-size keysym get 0 <int>
2007-09-20 18:09:08 -04:00
XwcLookupString
finish-lookup
] with-scope ;