feat: inhibit poweroff button
This commit is contained in:
parent
f187e8d767
commit
b2f4277122
3 changed files with 483 additions and 737 deletions
1173
Cargo.lock
generated
1173
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -37,17 +37,19 @@ tokio = { version = "1", features = [
|
||||||
"sync",
|
"sync",
|
||||||
"time",
|
"time",
|
||||||
] }
|
] }
|
||||||
zbus_systemd = { version = "0.25600.0", optional = true, features = [
|
zbus_systemd = { version = "0.25701.0", optional = true, features = [
|
||||||
"systemd1",
|
"systemd1",
|
||||||
] }
|
] }
|
||||||
tokio-util = "0.7"
|
tokio-util = "0.7"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-journald = { version = "0.3", optional = true }
|
tracing-journald = { version = "0.3", optional = true }
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
zbus = { version = "4.3.0", default-features = false, features = ["tokio"] }
|
zbus = { version = "5.7.0", default-features = false, features = ["tokio"] }
|
||||||
cosmic-notifications-util = { git = "https://github.com/pop-os/cosmic-notifications" }
|
cosmic-notifications-util = { git = "https://github.com/pop-os/cosmic-notifications" }
|
||||||
|
logind-zbus = { version = "5.3.2", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
systemd = ["dep:zbus_systemd", "dep:tracing-journald"]
|
systemd = ["dep:zbus_systemd", "dep:tracing-journald"]
|
||||||
default = ["systemd"]
|
logind = ["systemd", "logind-zbus"]
|
||||||
|
default = ["logind"]
|
||||||
autostart = ["dep:shell-words", "dep:dirs", "dep:freedesktop-desktop-entry"]
|
autostart = ["dep:shell-words", "dep:dirs", "dep:freedesktop-desktop-entry"]
|
||||||
|
|
|
||||||
39
src/main.rs
39
src/main.rs
|
|
@ -43,7 +43,6 @@ use tokio::{
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
use tracing::{metadata::LevelFilter, Instrument};
|
use tracing::{metadata::LevelFilter, Instrument};
|
||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
use zbus::ConnectionBuilder;
|
|
||||||
|
|
||||||
use crate::notifications::notifications_process;
|
use crate::notifications::notifications_process;
|
||||||
const XDP_COSMIC: Option<&'static str> = option_env!("XDP_COSMIC");
|
const XDP_COSMIC: Option<&'static str> = option_env!("XDP_COSMIC");
|
||||||
|
|
@ -89,7 +88,7 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let (session_tx, mut session_rx) = tokio::sync::mpsc::channel(10);
|
let (session_tx, mut session_rx) = tokio::sync::mpsc::channel(10);
|
||||||
let session_tx_clone = session_tx.clone();
|
let session_tx_clone = session_tx.clone();
|
||||||
let _conn = ConnectionBuilder::session()?
|
let _conn = zbus::connection::Builder::session()?
|
||||||
.name("com.system76.CosmicSession")?
|
.name("com.system76.CosmicSession")?
|
||||||
.serve_at(
|
.serve_at(
|
||||||
"/com/system76/CosmicSession",
|
"/com/system76/CosmicSession",
|
||||||
|
|
@ -172,7 +171,7 @@ async fn start(
|
||||||
systemd::set_systemd_environment("XDG_SESSION_TYPE", "wayland").await;
|
systemd::set_systemd_environment("XDG_SESSION_TYPE", "wayland").await;
|
||||||
|
|
||||||
#[cfg(feature = "systemd")]
|
#[cfg(feature = "systemd")]
|
||||||
if *is_systemd_used() {
|
let _inhibit_fd = if *is_systemd_used() {
|
||||||
match get_systemd_env().await {
|
match get_systemd_env().await {
|
||||||
Ok(env) => {
|
Ok(env) => {
|
||||||
for systemd_env in env {
|
for systemd_env in env {
|
||||||
|
|
@ -198,8 +197,40 @@ async fn start(
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("Failed to sync systemd environment {}.", err);
|
warn!("Failed to sync systemd environment {}.", err);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
#[cfg(feature = "logind")]
|
||||||
|
match zbus::Connection::system().await {
|
||||||
|
Ok(connection) => match logind_zbus::manager::ManagerProxy::new(&connection).await {
|
||||||
|
Ok(proxy) => match proxy
|
||||||
|
.inhibit(
|
||||||
|
logind_zbus::manager::InhibitType::HandlePowerKey,
|
||||||
|
"Cosmic Session",
|
||||||
|
"Show confirmation dialog.",
|
||||||
|
"block",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(fd) => Some(fd),
|
||||||
|
Err(err) => {
|
||||||
|
error!("Failed to inhibit power key {err:?}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
error!("Failed to connect to logind manager {err:?}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
error!("Failed to connect to system dbus {err:?}");
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
#[cfg(not(feature = "logind"))]
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let stdout_span = info_span!(parent: None, "cosmic-settings-daemon");
|
let stdout_span = info_span!(parent: None, "cosmic-settings-daemon");
|
||||||
let stderr_span = stdout_span.clone();
|
let stderr_span = stdout_span.clone();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue