rust_minifb icon indicating copy to clipboard operation
rust_minifb copied to clipboard

XSetLocaleModifiers breaks XOpenIM if you have XMODIFIERS

Open FauxFaux opened this issue 7 months ago • 2 comments

On my setup, which I understand is probably vanishingly uncommon by now, all minifb apps crash on startup with:

thread 'main' panicked at examples/char_callback.rs:29:6:
Unable to create the window: Failed to create window, "Failed to setup X IM via XOpenIM."
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is coming from here:

https://github.com/emoon/rust_minifb/blob/056c5afef1388247ca976f0edabd171a4393f3ed/src/os/posix/x11.rs#L363-L374

It appears that, on my system, im-config (an ubuntu-ism, maybe?), has set XMODIFIERS=@im=ibus in:

% fgrep -r XMODIFIERS /etc 2>/dev/null
/etc/X11/Xsession.d/70im-config_launch:if [ -z "$XMODIFIERS" ] && \
/etc/X11/Xsession.d/70im-config_launch:    export XMODIFIERS

..and that the XSetLocaleModifiers undoes this, and XOpenIm isn't happy about it.

I couldn't really work out what's going on here:

https://github.com/mirror/libX11/blob/ff8706a5eae25b8bafce300527079f68a201d27f/src/xlibi18n/lcWrap.c#L291-L295

The documentation for XSetLocaleModifiers mentions the XMODIFIERS environment variable, but it's not super clear to me if it's supposed to be overridden or appended or ...

Possible fixes:

  1. remove that XSetLocaleModifiers call, which works fine on my machine, it appears to work fine with or without the environment variable set.
  2. don't do it if the environment variable is set, assuming the user knows what they're doing (lol not me)
  3. workaround: document that you have to clear XMODIFIERS= to run any minifb app

environment:

  • amd64 ubuntu 24.04
  • i3wm HEAD 'cos the packaged one has weird issues with screen blanking on my amd card (???)
  • LC_*: en_GB.UTF-8, but not fixed by LC_ALL=C
  • im-config pointing at ibus
  • explicitly launching ibus-daemon -d -r on startup
  • using setxkbmap to switch between keyboard layouts

FauxFaux avatar May 17 '25 13:05 FauxFaux

Thanks for the report. I will have a look.

emoon avatar May 19 '25 05:05 emoon

I'm experiencing the same issue, I'm running CachyOS as my operating system

Bombfuse avatar Jul 18 '25 16:07 Bombfuse