1 ! Copyright (C) 2007, 2008 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types alien.data byte-arrays continuations
4 io.encodings.string io.encodings.utf8 kernel literals math namespaces
5 sequences x11 x11.X x11.xlib ;
10 : (init-xim) ( classname medifier -- im )
11 XSetLocaleModifiers [ "XSetLocaleModifiers() failed" throw ] unless
12 [ dpy get f ] dip dup XOpenIM ;
14 : init-xim ( classname -- )
17 [ "@im=none" (init-xim) [ "XOpenIM() failed" throw ] unless* ] if*
21 xim get-global XCloseIM drop f xim set-global ;
23 : with-xim ( quot -- )
24 [ "Factor" init-xim ] dip [ close-xim ] finally ; inline
26 : create-xic ( window classname -- xic )
28 [ xim get-global XNClientWindow ] dip
30 flags{ XNInputStyle XIMPreeditNothing XIMStatusNothing }
33 XNResourceClass over 0 XCreateIC
34 [ "XCreateIC() failed" throw ] unless* ;
37 CONSTANT: buf-size 100
40 CONSTANT: buf $[ buf-size <byte-array> ]
42 : lookup-string ( event xic -- string keysym )
43 swap buf buf-size { KeySym } [ 0 int <ref>
44 Xutf8LookupString buf swap head utf8 decode
45 ] with-out-parameters ;