August 3rd, 2024

Emotional about X11: I'm creating a pure X11 "emoji keyboard"

Xmoji is an emoji keyboard for X11 environments, allowing easy emoji insertion, organization, and customization. It is in development to replace qXmoji and requires specific libraries for building.

Read original articleLink Icon
Emotional about X11: I'm creating a pure X11 "emoji keyboard"

Xmoji is an emoji keyboard designed for X11 environments, enabling users to insert emojis into applications without the need for additional toolkits or input methods. Currently in development, Xmoji aims to replace the older tool qXmoji, which was based on Qt. The application allows users to insert emojis by left-clicking, while middle-clicking enables selection for transfer using the X11 primary selection mechanism. Emojis are organized into tabs by category, with skin-tone variants accessible through a right-click menu. Users can also search for emojis by name and track recently used emojis. The appearance of Xmoji can be customized using X resources, which allow adjustments to fonts, colors, and other UI elements. The application monitors a configuration file for changes, which can be specified via the command line. To build Xmoji, users need a C compiler, GNU make, and several libraries, including fontconfig, freetype, and libxcb. The source code can be compiled using `make` and installed with `make install`. An example configuration is provided to help users customize the application's appearance.

- Xmoji is designed for easy emoji insertion in X11 applications.

- It features emoji organization, search functionality, and history tracking.

- Customization is possible through X resources for UI elements.

- Building requires a C compiler and specific libraries.

- The application is currently a work in progress, succeeding qXmoji.

Link Icon 16 comments
By @Zirias - 9 months
In case someone wonders what's "special" about it:

user perspective: As far as I know, it's the only tool offering somewhat reliable emoji input using faked X11 keyboard events. "x11-emoji-picker" comes close, but delegates faking events to "xdotool", with weird consequences like having to restart it to direct emojis to a different window ;)

hacker perspective: It directly integrates xcb in a different event loop (here based on pselect()) and actually works – xcb is IMHO pretty great except for pretty much enforcing its own async model, internally using poll() and reading from the X server into buffers at many occassions, hidden from the consumer. If all your app does is communicate with the X server, you just happily use xcb's model. As soon as you need different things (e.g. local timers), you have a problem. The typical way to address that is dedicating another thread to xcb (AFAIK also done that way by toolkits offering an X11 backend). I hated that idea enough to be stubborn about doing it directly in my main thread, and with quite some trial-and-error, finally succeeded.

By @codedokode - 8 months
Please let me rant a bit about X11 input APIs.

One of the major flaws in X11 is its poorly designed keyboard input system. When a key is pressed, the keypress event sends a "keycode" - an 8-bit number that references the current layout. This means you're limited to injecting characters that are present in the current layout.

The implications of this design are frustrating. For instance, if you're connecting to a remote system via VNC and the client and server have different keyboard layouts, you'll run into all sorts of issues. Similarly, how do you create an on-screen keyboard that can inject keypresses for characters not available in the current layout? And what if you want to programmatically send some text, but the user has the wrong layout active? It's a mess.

I guess because of this in Debian most of characters in on-screen keyboard didn't work (they "fixed" it by showing only characters present in active layouts instead of fixing the root issue).

The common workaround for this is an ugly hack: you modify the keyboard layout, find unused spots, add desired characters, send key press event and restore the keyboard layout back. See the code: [2]

Also, Wayland which was supposed to get rid of legacy problems, seems to have inherited this ugly design. Also, there seem to be no sane API for managing layouts or switching them programatically, or subscribing to layout change event. Also, you cannot use modifiers like Ctrl to switch layouts because then combinations like Ctrl + C stop working. Keyboard APIs on Linux are broken in the worst way possible since beginning, probably because most developers use only ASCII and do not have experience using multiple layouts.

A better idea would be to allow to send arbitrary Unicode strings and maybe integrate regular input and IME input (input system for typing Asian characters).

[1] https://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.ht...

[2] https://github.com/Zirias/xmoji/blob/master/src/bin/xmoji/ke...

By @avidseeker - 8 months
Reminds me of Tom Scott's "Art of Bodge up" video where he attempts to make an emoji keyboard on Windows.

https://www.youtube.com/watch?v=lIFE7h3m40U

It's funny at the end he says "and don't ever suggest me I use Linux, just don't." I felt he expected it to be really hard project on Linux, while iterally his project is a single keyboard layout file.

By @freedomben - 8 months
Fun project, thanks for sharing!

On Gnome there is the "Characters" application which is pretty handy. I do want to make a few improvement to search, but otherwise it's pretty good. You copy the unicode character to the clipboard and can then paste it wherever you need.

If you run Gnome it's probably already installed. If not: https://gitlab.gnome.org/GNOME/gnome-characters

By @dark-star - 8 months
Writing a pure X11 application in 2024 is an interesting choice, given the recent push to Wayland.

Nevertheless, it looks like a pretty cool tool!

By @simon_acca - 8 months
Nice project!

Made me think of the emoji physical keyboard from Tom Scott https://youtu.be/3AtBE9BOvvk

By @Jach - 8 months
I just use IBus, since I was already using it for Japanese IME input. It has its own emoji picker but has been kinda buggy before, instead I just use the "Typing Booster" keyboard option. I can type "wolf" and it'll popup a menu including the emoji or related emojis; I guess "cat:" is a better example since there's a lot more (e.g. shows tiger eventually) and I can scroll through them.
By @jandrese - 8 months
This is a cool project, but hard to show off since HN doesn't like Emoji.
By @codedokode - 8 months
Also, I am curious: why in X11 and Wayland keyboard code translation happens on the client side? Wouldn't it make more sense if the layout was stored only on the server and server did the translation? There would be no need to broadcast layout changes, for example.
By @fao_ - 8 months
> As far as I know, it's the only tool offering somewhat reliable emoji input using faked X11 keyboard events.

A few years ago I wrote https://gitlab.com/finnoleary/zhmenu (excuse the deadname in the URL there). I'm reasonably sure it partially counts? I'd meant to build an emoji database for it but never got around to it.

By @elflaune - 8 months
as long as i need to run nvidia with multiple monitors, i'll hang on to x11.
By @3np - 8 months
Looks promising!

I think I did managed to wrangle fcitx into some reasonable emoji input in the past but at some point it broke / I lost it and configuring that tool is just an unpredictable mess...

Will keep an eye on yours!

By @yoavm - 8 months
I just have this one liner for Wayland:

  cat ~/.local/share/emojis/emojis| wofi -i -d -M fuzzy -H 700 | cut -d " " -f 1 | tr -d '\040\011\012\015' | wtype -
It shows an overlay fuzzy-searchable list of all emojis, and it writes selected one to the input regardless of the toolkit. assign it to a keyboard shortcut and you're good to go.

the ~/.local/share/emojis/emojis file is just a list of all emojis:

  cat ~/.local/share/emojis/emojis | head -n 3
         Grinning Face
         Grinning Face with Big Eyes
         Grinning Face with Smiling Eyes
(HN is removing the emojis but each line starts with the emoji self, followed by the description)
By @amelius - 8 months
Unicode sucks. There is a glyph for a hammer, for a screwdriver, but not a soldering iron.

During COVID, people were using a golf club as a substitute for a cotton swab.

We now have generative AI that can make any desired emoticon you can dream of, except you can't use it because of Unicode.