1 ! Copyright (C) 2007, 2008 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types alien.strings arrays byte-arrays
4 hashtables io io.encodings.string kernel math namespaces
5 sequences strings continuations x11.xlib specialized-arrays.uint
6 accessors io.encodings.utf16n ;
11 : (init-xim) ( classname medifier -- im )
12 XSetLocaleModifiers [ "XSetLocaleModifiers() failed" throw ] unless
13 [ dpy get f ] dip dup XOpenIM ;
15 : init-xim ( classname -- )
18 [ "@im=none" (init-xim) [ "XOpenIM() failed" throw ] unless* ] if*
22 xim get-global XCloseIM drop f xim set-global ;
24 : with-xim ( quot -- )
25 [ "Factor" init-xim ] dip [ close-xim ] [ ] cleanup ;
27 : create-xic ( window classname -- xic )
29 [ xim get-global XNClientWindow ] dip
31 XNInputStyle XIMPreeditNothing XIMStatusNothing bitor
34 XNResourceClass over 0 XCreateIC
35 [ "XCreateIC() failed" throw ] unless* ;
42 : prepare-lookup ( -- )
43 buf-size <uint-array> keybuf set
44 0 <KeySym> keysym set ;
46 : finish-lookup ( len -- string keysym )
47 keybuf get swap 2 * head utf16n decode
50 : lookup-string ( event xic -- string keysym )
53 swap keybuf get underlying>> buf-size keysym get 0 <int>