From 9b50d0f50606891440cf9844304ae3c8b14034db Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Sun, 8 Dec 2024 14:40:52 +0100 Subject: [PATCH] main: Update D-Bus activation environment also on non-systemd systems On systems without systemd, use zbus to update D-Bus activation environment with `WAYLAND_DISPLAY` and `DISPLAY` variables. Fixes #1037 --- src/dbus/mod.rs | 25 ++++++++++++++++++++++++- src/main.rs | 6 +++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/dbus/mod.rs b/src/dbus/mod.rs index cea8c261..13b2bcc5 100644 --- a/src/dbus/mod.rs +++ b/src/dbus/mod.rs @@ -1,6 +1,8 @@ -use crate::state::{BackendData, State}; +use crate::state::{BackendData, Common, State}; use anyhow::{Context, Result}; use calloop::{InsertError, LoopHandle, RegistrationToken}; +use std::collections::HashMap; +use zbus::blocking::{fdo::DBusProxy, Connection}; mod power; @@ -64,3 +66,24 @@ pub fn init(evlh: &LoopHandle<'static, State>) -> Result> Ok(tokens) } + +/// Updated the D-Bus activation environment with `WAYLAND_DISPLAY` and +/// `DISPLAY` variables. +pub fn ready(common: &Common) -> Result<()> { + let conn = Connection::session()?; + let proxy = DBusProxy::new(&conn)?; + + proxy.update_activation_environment(HashMap::from([ + ("WAYLAND_DISPLAY", common.socket.to_str().unwrap()), + ( + "DISPLAY", + &common + .xwayland_state + .as_ref() + .map(|s| format!(":{}", s.display)) + .unwrap_or(String::new()), + ), + ]))?; + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index aba0727e..43b8a698 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,9 +45,13 @@ impl State { // into systemd and the session? self.ready.call_once(|| { // potentially tell systemd we are setup now - #[cfg(feature = "systemd")] if let state::BackendData::Kms(_) = &self.backend { + #[cfg(feature = "systemd")] systemd::ready(&self.common); + #[cfg(not(feature = "systemd"))] + if let Err(err) = dbus::ready(&self.common) { + error!(?err, "Failed to update the D-Bus activation environment"); + } } // potentially tell the session we are setup now