Skip to content

XSetLocaleModifiers breaks XOpenIM if you have XMODIFIERS #379

@FauxFaux

Description

@FauxFaux

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:

let empty_string = b"\0";
(d.lib.XSetLocaleModifiers)(empty_string.as_ptr() as _);
let xim = (d.lib.XOpenIM)(
d.display,
0 as XrmDatabase,
std::ptr::null_mut::<c_char>(),
std::ptr::null_mut::<c_char>(),
);
if (xim as usize) == 0 {
return Err(Error::WindowCreate(
"Failed to setup X IM via XOpenIM.".to_owned(),

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions