<commit_before>! Copyright (C) 2007, 2008 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types alien.data alien.strings arrays
byte-arrays hashtables io io.encodings.string kernel math
namespaces sequences strings continuations x11 x11.xlib
accessors io.encodings.utf8 literals ;
IN: x11.xim

SYMBOL: xim

: (init-xim) ( classname medifier -- im )
    XSetLocaleModifiers [ "XSetLocaleModifiers() failed" throw ] unless
    [ dpy get f ] dip dup XOpenIM ;

: init-xim ( classname -- )
    dup "" (init-xim)
    [ nip ]
    [ "@im=none" (init-xim) [ "XOpenIM() failed" throw ] unless* ] if*
    xim set-global ;

: close-xim ( -- )
    xim get-global XCloseIM drop f xim set-global ;

: with-xim ( quot -- )
    [ "Factor" init-xim ] dip [ close-xim ] [ ] cleanup ; inline

: create-xic ( window classname -- xic )
    [
        [ xim get-global XNClientWindow ] dip
        XNFocusWindow over
        XNInputStyle XIMPreeditNothing XIMStatusNothing bitor
        XNResourceName
    ] dip
    XNResourceClass over 0 XCreateIC
    [ "XCreateIC() failed" throw ] unless* ;

CONSTANT: buf-size 100
CONSTANT: buf $[ buf-size <byte-array> ]

: lookup-string ( event xic -- string keysym )
    swap buf buf-size { KeySym } [ 0 int <ref>
        Xutf8LookupString buf swap head utf8 decode
    ] with-out-parameters ;<commit_msg>x11.xim: fix "cannot execute a word before it has been compiled" bug.<commit_after>! Copyright (C) 2007, 2008 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types alien.data alien.strings arrays
byte-arrays hashtables io io.encodings.string kernel math
namespaces sequences strings continuations x11 x11.xlib
accessors io.encodings.utf8 literals ;
IN: x11.xim

SYMBOL: xim

: (init-xim) ( classname medifier -- im )
    XSetLocaleModifiers [ "XSetLocaleModifiers() failed" throw ] unless
    [ dpy get f ] dip dup XOpenIM ;

: init-xim ( classname -- )
    dup "" (init-xim)
    [ nip ]
    [ "@im=none" (init-xim) [ "XOpenIM() failed" throw ] unless* ] if*
    xim set-global ;

: close-xim ( -- )
    xim get-global XCloseIM drop f xim set-global ;

: with-xim ( quot -- )
    [ "Factor" init-xim ] dip [ close-xim ] [ ] cleanup ; inline

: create-xic ( window classname -- xic )
    [
        [ xim get-global XNClientWindow ] dip
        XNFocusWindow over
        XNInputStyle XIMPreeditNothing XIMStatusNothing bitor
        XNResourceName
    ] dip
    XNResourceClass over 0 XCreateIC
    [ "XCreateIC() failed" throw ] unless* ;

<<
CONSTANT: buf-size 100
>>

CONSTANT: buf $[ buf-size <byte-array> ]

: lookup-string ( event xic -- string keysym )
    swap buf buf-size { KeySym } [ 0 int <ref>
        Xutf8LookupString buf swap head utf8 decode
    ] with-out-parameters ;
{'fraction_non_alphanumeric': 0.11254944264653002, 'fraction_numerical': 0.01654081265731751, 'mean_word_length': 2.946099290780142, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4192820', 'n_tokens_mistral': 959, 'n_tokens_neox': 918, 'n_words': 274}