Skip to content

Commit

Permalink
main: Update D-Bus activation environment also on non-systemd systems
Browse files Browse the repository at this point in the history
On systems without systemd, use zbus to update D-Bus activation
environment with `WAYLAND_DISPLAY` and `DISPLAY` variables.

Fixes #1037
  • Loading branch information
vadorovsky authored and Drakulix committed Dec 9, 2024
1 parent 7829e76 commit 9b50d0f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/dbus/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -64,3 +66,24 @@ pub fn init(evlh: &LoopHandle<'static, State>) -> Result<Vec<RegistrationToken>>

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(())
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b50d0f

Please sign in to comment.