Skip to content

Commit 8b49072

Browse files
hoshinolinaslp
authored andcommitted
env: Pass through locale & IM stuff
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]>
1 parent ec6f60d commit 8b49072

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

crates/muvm/src/env.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,27 @@ use log::debug;
1010

1111
/// Automatically pass these environment variables to the microVM, if they are
1212
/// set.
13-
const WELL_KNOWN_ENV_VARS: [&str; 5] = [
13+
const WELL_KNOWN_ENV_VARS: [&str; 20] = [
14+
"LANG",
15+
"LC_ADDRESS",
16+
"LC_ALL",
17+
"LC_COLLATE",
18+
"LC_CTYPE",
19+
"LC_IDENTIFICATION",
20+
"LC_MEASUREMENT",
21+
"LC_MESSAGES",
22+
"LC_MONETARY",
23+
"LC_NAME",
24+
"LC_NUMERIC",
25+
"LC_PAPER",
26+
"LC_TELEPHONE",
27+
"LC_TIME",
1428
"LD_LIBRARY_PATH",
1529
"LIBGL_DRIVERS_PATH",
1630
"MESA_LOADER_DRIVER_OVERRIDE", // needed for asahi
1731
"PATH", // needed by `muvm-guest` program
1832
"RUST_LOG",
33+
"XMODIFIERS",
1934
];
2035

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

74+
if !(env_map.contains_key("LANG")
75+
|| env_map.contains_key("LC_CTYPE")
76+
|| env_map.contains_key("LC_ALL"))
77+
{
78+
// Set a default UTF-8 locale if none
79+
env_map.insert("LANG".to_owned(), "C.UTF-8".to_owned());
80+
}
81+
82+
// Force XIM usage for GTK2/3 and QT4/QT5 (QT6 and GTK4 drop this).
83+
// This actually works with muvm-x11bridge for input methods in Steam,
84+
// since it ships the xim plugin for its bundled gtk3.
85+
// Once we have wayland, the Wayland transport should work for newer stuff.
86+
// This way we don't need to support passing through the dbus/socket based
87+
// direct plugin support.
88+
env_map.insert("GTK_IM_MODULE".to_owned(), "xim".to_owned());
89+
env_map.insert("QT_IM_MODULE".to_owned(), "xim".to_owned());
90+
5991
for (key, value) in env {
6092
let value = value.map_or_else(
6193
|| env::var(&key).with_context(|| format!("Failed to get `{key}` env var")),

0 commit comments

Comments
 (0)