xwayland: Expose DISPLAY variable to clients

This commit is contained in:
Victoria Brekenfeld 2023-01-24 18:08:52 +01:00
parent 51f53aa899
commit e5f4911bb6
3 changed files with 23 additions and 2 deletions

View file

@ -900,6 +900,15 @@ impl State {
.arg("-c")
.arg(command)
.env("WAYLAND_DISPLAY", &self.common.socket)
.env(
"DISPLAY",
&self
.common
.xwayland_state
.values()
.find_map(|s| s.display.map(|v| format!(":{}", v)))
.unwrap_or(String::new()),
)
.env_remove("COSMIC_SESSION_SOCK")
.spawn()
{

View file

@ -77,6 +77,9 @@ pub fn setup_socket(handle: LoopHandle<Data>, state: &State) -> Result<()> {
.into_string()
.map_err(|_| anyhow!("wayland socket is no valid utf-8 string?"))?,
);
if let Some(display) = state.common.xwayland_state.values().find_map(|s| s.display) {
env.insert(String::from("DISPLAY"), format!(":{}", display));
}
let message = serde_json::to_string(&Message::SetEnv { variables: env })
.with_context(|| "Failed to encode environment variables into json")?;
let bytes = message.into_bytes();

View file

@ -7,13 +7,22 @@ use std::process::Command;
pub fn ready(state: &State) {
if booted() {
match Command::new("systemctl")
.args(["--user", "import-environment", "WAYLAND_DISPLAY"])
.args(["--user", "import-environment", "WAYLAND_DISPLAY", "DISPLAY"])
.env("WAYLAND_DISPLAY", &state.common.socket)
.env(
"DISPLAY",
&state
.common
.xwayland_state
.values()
.find_map(|s| s.display.map(|v| format!(":{}", v)))
.unwrap_or(String::new()),
)
.status()
{
Ok(x) if x.success() => {}
Ok(x) => slog_scope::warn!(
"Failed to import WAYLAND_DISPLAY into systemd (exit code {:?})",
"Failed to import WAYLAND_DISPLAY/DISPLAY into systemd (exit code {:?})",
x.code()
),
Err(err) => slog_scope::error!(