How to complete a IM for Lisp

94 views
Skip to first unread message

C-E

unread,
Jan 6, 2021, 11:23:55 AM1/6/21
to fcitx-dev
I'm using McCLIM a  GUI written using Lisp, which doesn't support fcitx. I'm wondering how to add support for it. I have done some google, but look likes I can't find  much useful info. Can you point me some guides, examples on this?
By now, I'm thinking about binding XIM to it, is this a good idea?
Or should I use McCLIM itself to write a new one?
BTW, lisp is just my personal fun. :)

Weng Xuetian

unread,
Jan 6, 2021, 12:59:59 PM1/6/21
to fcitx-dev
I briefly checked the source code, so it looks like McCLIM is based on
CLX, which does not use libX11. And obviously it is lacking the
support for xim (by searching for some required string literal in
source code).
This page seems to have some information for it, but the whole thing
is not only about xkeyboard anyway.
https://github.com/stumpwm/stumpwm/wiki/International-Input-and-XKeyboard-Development

XIM is quite complex.
https://www.x.org/releases/X11R7.6/doc/libX11/specs/XIM/xim.html The
spec won't help you too much on the implementation details.
All I can do is point you to a library that I wrote based on XCB
https://github.com/fcitx/xcb-imdkit/ . You may just focus on the
client side code.
It is relatively lower level so probably much clearer compared to
digging into complex libX11 code and the logic behind XFilterEvent
magic.

Alternatively, if you just want to use lisp for GUI, you may want to
check the lisp binding for common toolkit libraries like gtk/qt that
have good input method support.
> --
> You received this message because you are subscribed to the Google Groups "fcitx-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fcitx-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fcitx-dev/d1813407-28d2-42b9-a70d-7da2418c5110n%40googlegroups.com.

C—E

unread,
Jan 7, 2021, 12:32:28 AM1/7/21
to fcitx-dev

Thanks. Looks like I have to achieve something like "clx-IM", along with x keyboard things.

C—E

unread,
Feb 3, 2021, 5:04:18 AM2/3/21
to fcitx-dev
Hi, sorry to bother
While in xcb, this can get property reply(which is not NULL):
 ```
    int screen_default_nbr;
    xcb_connection_t *connection = xcb_connect(NULL, &screen_default_nbr);
    xcb_screen_t *screen = xcb_aux_get_screen(connection, screen_default_nbr);
    xcb_intern_atom_cookie_t atom_cookie = xcb_intern_atom(connection, false, strlen("XIM_SERVERS"), "XIM_SERVERS");
    xcb_intern_atom_reply_t *atom_reply = xcb_intern_atom_reply(connection, atom_cookie, NULL);
    xcb_atom_t atom = atom_reply->atom;
    xcb_get_property_cookie_t cookie = xcb_get_property(connection, false, screen->root, atom,XCB_ATOM_ATOM, 0L,100000L);
    xcb_get_property_reply_t *reply = xcb_get_property_reply(connection, cookie, NULL);
```
But this in xlib gives none:

```
  dpy = XOpenDisplay(NULL);
    scr = DefaultScreen(dpy);
    win = XCreateSimpleWindow(dpy,
            XDefaultRootWindow(dpy),
            0, 0, 100, 100, 5,
            BlackPixel(dpy, scr),
            BlackPixel(dpy, scr));
    XMapWindow(dpy, win);

    int count;
    Atom *atoms = XListProperties(dpy, win, &count);
    printf("%d\n", count);
    while (count--)
      {
    printf("%s\n", XGetAtomName(dpy, atoms[count]));
      }
```
what happen here, what should I do to get the property

C—E

unread,
Feb 3, 2021, 10:06:24 AM2/3/21
to fcitx-dev
Orzk, I should use the root window. I am foolish

C—E

unread,
Feb 15, 2021, 7:29:59 AM2/15/21
to fcitx-dev

Sorry to brother again. After call corresponding function of _xcb_xim_sync inside _xcb_xim_handle_forward_event when get key-press/release event,   it start loop getting key press/release event, and set_event_mask, while I don't typed anything. And the event key is what I typed last before open the corresponding cliend_demo. Can you tell me what may cause this?
On Thursday, January 7, 2021 at 1:59:59 AM UTC+8 CS Slayer wrote:

Weng Xuetian

unread,
Feb 17, 2021, 10:35:04 PM2/17/21
to fcitx-dev
You may want to check "Sample Protocol Flow" in this page to get a
better view about how this works:
https://www.x.org/releases/X11R7.6/doc/libX11/specs/XIM/xim.html

What client_demo you're talking about? Do you have the link to code?

So basically, _xcb_xim_handle_forward_event receives a xKeyEvent
(lower case, means the on-wire format) from the input method server.
You need to make sure you don't put it back into the event handler
(means sending it back to the input method again), this is the result
you're waiting for.

In gtk API, the "filter" returns a true or false about whether the key
is handled by the input method server. While in XIM, the server
doesn't return a result of simple "true" or "false", but just the
original key event.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fcitx-dev/bde64ba6-5c71-4120-8d9f-09475aaa4772n%40googlegroups.com.

C—E

unread,
Feb 18, 2021, 12:40:14 AM2/18/21
to fcitx-dev
I'm working on clx-xim clx-xim, the corresponding function of _xcb_xim_sync from xcb-imdkit is from clx-xim. So you mean that XIM will just send the xKeyEvent back after receive xim_sync_reply ,  so I have to filter the xKeyEvent myself?

C—E

unread,
Feb 18, 2021, 2:12:33 AM2/18/21
to fcitx-dev
I think I may don't explain myself clearly. I mean, in clx, event-case, which you can treat like xcb_wait_for_event in xcb, keeping receiving xKeyEvent, once the im_sync_reply is sent. I'm sure that I didn't put the xKeyEvent back into the event handler, since I comment everthing beside the function to send im_sync_reply in handler function of forward event.

Weng Xuetian

unread,
Feb 18, 2021, 7:34:45 PM2/18/21
to fcitx-dev
Do you have any instruction about how to test your code?
> To view this discussion on the web visit https://groups.google.com/d/msgid/fcitx-dev/28d9dad8-f951-44d9-95be-05e7e8f0cef9n%40googlegroups.com.

C—E

unread,
Feb 18, 2021, 10:16:36 PM2/18/21
to fcitx-dev
1.1 make sure you are using the most recent version, the version should be found in respository of your linux distribution.
2. install quicklisp https://www.quicklisp.org/beta/
2.2 $ sbcl --load quicklisp.lisp
2.3 (now you are in sbcl)type:  (quicklisp-quickstart:install),( the parentheses too)
2.4 Ctrl+d to exit
3. clone clx-xim, and put it to ~/quicklisp/local-projects
4.1. type sbcl in shell
4.2(ql:quickload :clx-xim/demo)
4.3(demo:start-demo)
this should do.

C—E

unread,
Feb 18, 2021, 10:20:39 PM2/18/21
to fcitx-dev
Btw, you may need to run `source /etc/profile`, if you can come into something like this: ` can't find core file at /usr/lib/sbcl//sbcl.core` when you run sbcl

C—E

unread,
Feb 19, 2021, 12:32:10 AM2/19/21
to fcitx-dev
It seems that this may have something to do with `event-case` in clx, since if I use `process-event`, then I can successfully get fcitx to open.

C—E

unread,
Feb 19, 2021, 12:44:49 AM2/19/21
to fcitx-dev
Thanks you @CS Slayer! And here comes new questions, how to get fcitx work with programs doesn't use xorg, e.g. programs written using opengl, mentioned https://github.com/McCLIM/McCLIM/issues/1128

Weng Xuetian

unread,
Feb 19, 2021, 1:23:56 AM2/19/21
to fcitx-dev
Even if you're using OpenGL, you still use xorg. You can't bypass xorg
if the application is running under Xorg. (unless on wayland, which is
just another different display server, or directly use framebuffer,
which is an extremely rare case).

On linux it would simply be GLX or EGL, but you're still using X if
it's running under Xorg.

You need to figure out the relevant X window and display. For example,
https://github.com/alacritty/alacritty is using opengl but also
support input method.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fcitx-dev/c5af6ea2-a687-43d1-ad8e-a31244c50715n%40googlegroups.com.

C—E

unread,
Feb 19, 2021, 4:29:28 AM2/19/21
to fcitx-dev
Ok, get it.
And can fcitx using UTF-8 instead of compound text when sending committed string? I have not found compund text library in lisp, and it seems complex to write one.

Weng Xuetian

unread,
Feb 25, 2021, 6:15:31 PM2/25/21
to fcitx-dev
Yeah, the compound text is indeed tricky. I don't know if you could
use xcb-imdkit code via ffi to implement this. The compound text
interface is actually very simple.
https://github.com/fcitx/xcb-imdkit/blob/41a6647da8e345f195be08411b2e89f5a3a50022/src/encoding.h

Also, even if you could get fcitx to work with utf8 (I think it is
do-able), but it would just like a custom protocol between fcitx
because libx11 doesn't work with non-compound text. I'm not so sure
extending a dead protocol like xim would be a safe option to do.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fcitx-dev/43eb96b0-98fa-443a-b79d-7367020680e2n%40googlegroups.com.
Message has been deleted

C—E

unread,
Feb 28, 2021, 6:32:17 AM2/28/21
to fcitx-dev
Thanks to your advice!
But the clx is asking for a pure lisp clx-xim, mention here. So I think it may not be a good idea to use ffi.

And according to The Input Method Protocol, section Encoding Negotiation, it say that encoding  can be set using XIM_ENCODING_NEGOTIATION.(If I understand it correctly).
So I'm wondering if this could be used to ask for utf-8 stream.
If this can't work. I will have try writing a compound-text processer myself.

Weng Xuetian

unread,
Feb 28, 2021, 8:44:32 PM2/28/21
to fcitx-dev
I think it certainly can use the encoding negotiation to do the
implementation, the thing is
* There is no implementation till today that supports
non-compound-text encoding. *

Also: The name of encoding may be registered with X Consortium.

I could write some code for you, certainly.
https://github.com/fcitx/fcitx5/commit/9dd694248cbdb11030637493c6708ad815cb0010
https://github.com/fcitx/xcb-imdkit/commit/a16d25ea1ff084c63fea698601687d8142908b2c
I hope this can help you test your code when you don't have your own
compound text implementation.

But wouldn't you want your implementation to work with more input
method servers that do not have the feature?

Here's some documentation that might be helpful:
Emacs's compound text implementation
https://github.com/emacs-mirror/emacs/blob/4825ea3c5d067accad1e714531799f1836b548b5/lisp/international/mule.el#L1550
https://www.x.org/releases/X11R7.6/doc/xorg-docs/specs/CTEXT/ctext.html
https://en.wikipedia.org/wiki/ISO/IEC_2022 (Basically compound is a
variant of iso 2022)

On Sun, Feb 28, 2021 at 3:31 AM C—E <lear...@gmail.com> wrote:
>
> Thanks to your advice!
> But the clx is asking for a pure lisp clx-xim, mention here. So I don't think it may not be a good idea to use ffi.
>
> And according to The Input Method Protocol, section Encoding Negotiation, it say that encoding can be set using XIM_ENCODING_NEGOTIATION.(If I understand it correctly).
> So I'm wondering if this could be used to ask for utf-8 stream.
> If this can't work. I will have try writing a compound-text processer myself.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fcitx-dev/e39007e5-44f8-484b-bb5d-65642ad47508n%40googlegroups.com.

C—E

unread,
Mar 2, 2021, 7:09:49 AM3/2/21
to fcitx-dev
It's so kind of you, thank you very much!
I will check it out once I'm free.
Reply all
Reply to author
Forward
0 new messages