]> gitweb.factorcode.org Git - factor.git/blob - basis/x11/xim/xim.factor
35e1906b2b786069a0a7e04904bcd17cc563ada1
[factor.git] / basis / x11 / xim / xim.factor
1 ! Copyright (C) 2007 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types arrays byte-arrays hashtables
4 io kernel math namespaces sequences strings
5 continuations 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 rot 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     >r "Factor" init-xim r> [ close-xim ] [ ] cleanup ;
25
26 : create-xic ( window classname -- xic )
27     >r >r xim get-global
28     XNClientWindow r>
29     XNFocusWindow over
30     XNInputStyle XIMPreeditNothing XIMStatusNothing bitor
31     XNResourceName r>
32     XNResourceClass over 0 XCreateIC
33     [ "XCreateIC() failed" throw ] unless* ;
34
35 : buf-size 100 ;
36
37 SYMBOL: keybuf
38 SYMBOL: keysym
39
40 : prepare-lookup ( -- )
41     buf-size "uint" <c-array> keybuf set
42     0 <KeySym> keysym set ;
43
44 : finish-lookup ( len -- string keysym )
45     keybuf get swap c-uint-array> >string
46     keysym get *KeySym ;
47
48 : lookup-string ( event xic -- string keysym )
49     [
50         prepare-lookup
51         swap keybuf get buf-size keysym get 0 <int>
52         XwcLookupString
53         finish-lookup
54     ] with-scope ;