Skip to content

Commit

Permalink
env: Pass through locale & IM stuff
Browse files Browse the repository at this point in the history
Leaving the default C locale can break stuff that expect UTF-8, so pass
through all the locale env vars and set a default C.UTF-8 locale if
nothing is set.

For input methods, it turns out that the old legacy XIM does work with
our X11 passthrough solution (direct GTK/QT plugin methods will not,
since they use side-channels to communicate with the IM server). So,
force xim usage for GTK2/3 and QT4/5, which actually works with Steam
(!) for CJK input if the system is configured properly.

The future is Wayland protocols, which will work with GTK4 and QT6 once
we have Wayland passthrough. Hopefully that means we never have to
support input methods with the shared library mechanisms, which means
our rootfs will never have to include IM-specific libraries and the
input method user choice will happen entirely outside of muvm.

Signed-off-by: Asahi Lina <[email protected]>
  • Loading branch information
asahilina authored and slp committed Nov 19, 2024
1 parent ec6f60d commit 8b49072
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion crates/muvm/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,27 @@ use log::debug;

/// Automatically pass these environment variables to the microVM, if they are
/// set.
const WELL_KNOWN_ENV_VARS: [&str; 5] = [
const WELL_KNOWN_ENV_VARS: [&str; 20] = [
"LANG",
"LC_ADDRESS",
"LC_ALL",
"LC_COLLATE",
"LC_CTYPE",
"LC_IDENTIFICATION",
"LC_MEASUREMENT",
"LC_MESSAGES",
"LC_MONETARY",
"LC_NAME",
"LC_NUMERIC",
"LC_PAPER",
"LC_TELEPHONE",
"LC_TIME",
"LD_LIBRARY_PATH",
"LIBGL_DRIVERS_PATH",
"MESA_LOADER_DRIVER_OVERRIDE", // needed for asahi
"PATH", // needed by `muvm-guest` program
"RUST_LOG",
"XMODIFIERS",
];

/// See https://github.com/AsahiLinux/docs/wiki/Devices
Expand Down Expand Up @@ -56,6 +71,23 @@ pub fn prepare_env_vars(env: Vec<(String, Option<String>)>) -> Result<HashMap<St
env_map.insert(key.to_owned(), value);
}

if !(env_map.contains_key("LANG")
|| env_map.contains_key("LC_CTYPE")
|| env_map.contains_key("LC_ALL"))
{
// Set a default UTF-8 locale if none
env_map.insert("LANG".to_owned(), "C.UTF-8".to_owned());
}

// Force XIM usage for GTK2/3 and QT4/QT5 (QT6 and GTK4 drop this).
// This actually works with muvm-x11bridge for input methods in Steam,
// since it ships the xim plugin for its bundled gtk3.
// Once we have wayland, the Wayland transport should work for newer stuff.
// This way we don't need to support passing through the dbus/socket based
// direct plugin support.
env_map.insert("GTK_IM_MODULE".to_owned(), "xim".to_owned());
env_map.insert("QT_IM_MODULE".to_owned(), "xim".to_owned());

for (key, value) in env {
let value = value.map_or_else(
|| env::var(&key).with_context(|| format!("Failed to get `{key}` env var")),
Expand Down

0 comments on commit 8b49072

Please sign in to comment.