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 x11.xlib
6 specialized-arrays accessors io.encodings.utf16n ;
7 SPECIALIZED-ARRAY: uint
12 : (init-xim) ( classname medifier -- im )
13 XSetLocaleModifiers [ "XSetLocaleModifiers() failed" throw ] unless
14 [ dpy get f ] dip dup XOpenIM ;
16 : init-xim ( classname -- )
19 [ "@im=none" (init-xim) [ "XOpenIM() failed" throw ] unless* ] if*
23 xim get-global XCloseIM drop f xim set-global ;
25 : with-xim ( quot -- )
26 [ "Factor" init-xim ] dip [ close-xim ] [ ] cleanup ; inline
28 : create-xic ( window classname -- xic )
30 [ xim get-global XNClientWindow ] dip
32 XNInputStyle XIMPreeditNothing XIMStatusNothing bitor
35 XNResourceClass over 0 XCreateIC
36 [ "XCreateIC() failed" throw ] unless* ;
38 CONSTANT: buf-size 100
43 : prepare-lookup ( -- )
44 buf-size <uint-array> keybuf set
45 0 <KeySym> keysym set ;
47 : finish-lookup ( len -- string keysym )
48 keybuf get swap 2 * head utf16n decode
51 : lookup-string ( event xic -- string keysym )
54 swap keybuf get buf-size keysym get 0 <int>