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 ;
10 : (init-xim) ( classname medifier -- im )
11 XSetLocaleModifiers [ "XSetLocaleModifiers() failed" throw ] unless
12 dpy get f rot 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 >r "Factor" init-xim r> [ close-xim ] [ ] cleanup ;
26 : create-xic ( window classname -- xic )
30 XNInputStyle XIMPreeditNothing XIMStatusNothing bitor
32 XNResourceClass over 0 XCreateIC
33 [ "XCreateIC() failed" throw ] unless* ;
40 : prepare-lookup ( -- )
41 buf-size "uint" <c-array> keybuf set
42 0 <KeySym> keysym set ;
44 : finish-lookup ( len -- string keysym )
45 keybuf get swap c-uint-array> >string
48 : lookup-string ( event xic -- string keysym )
51 swap keybuf get buf-size keysym get 0 <int>