]> gitweb.factorcode.org Git - factor.git/blob - basis/x11/xim/xim.factor
core/basis/extra: use flags{ } in places.
[factor.git] / basis / x11 / xim / xim.factor
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 ;
6 IN: x11.xim
7
8 SYMBOL: xim
9
10 : (init-xim) ( classname medifier -- im )
11     XSetLocaleModifiers [ "XSetLocaleModifiers() failed" throw ] unless
12     [ dpy get f ] dip dup XOpenIM ;
13
14 : init-xim ( classname -- )
15     dup "" (init-xim)
16     [ nip ]
17     [ "@im=none" (init-xim) [ "XOpenIM() failed" throw ] unless* ] if*
18     xim set-global ;
19
20 : close-xim ( -- )
21     xim get-global XCloseIM drop f xim set-global ;
22
23 : with-xim ( quot -- )
24     [ "Factor" init-xim ] dip [ close-xim ] finally ; inline
25
26 : create-xic ( window classname -- xic )
27     [
28         [ xim get-global XNClientWindow ] dip
29         XNFocusWindow over
30         flags{ XNInputStyle XIMPreeditNothing XIMStatusNothing }
31         XNResourceName
32     ] dip
33     XNResourceClass over 0 XCreateIC
34     [ "XCreateIC() failed" throw ] unless* ;
35
36 <<
37 CONSTANT: buf-size 100
38 >>
39
40 CONSTANT: buf $[ buf-size <byte-array> ]
41
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 ;