aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-10-10 09:02:33 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-10 09:02:33 +0400
commit66533ae0b1b84c0d5acbc5e6618fb1700eeb61db (patch)
tree2bc74e64ce5550fccd2fbb46db3c54c46339623f /src
parentd66bd87c66d7942037a74a8298716322ebe22adf (diff)
downloadniri-66533ae0b1b84c0d5acbc5e6618fb1700eeb61db.tar.gz
niri-66533ae0b1b84c0d5acbc5e6618fb1700eeb61db.tar.bz2
niri-66533ae0b1b84c0d5acbc5e6618fb1700eeb61db.zip
Extract inhibit_power_key()
Diffstat (limited to 'src')
-rw-r--r--src/main.rs5
-rw-r--r--src/niri.rs47
2 files changed, 24 insertions, 28 deletions
diff --git a/src/main.rs b/src/main.rs
index 42656f80..6680e11b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -100,6 +100,11 @@ fn main() {
if is_systemd_service {
// We're starting as a systemd service. Export our variables.
import_env_to_systemd();
+
+ // Inhibit power key handling so we can suspend on it.
+ if let Err(err) = state.niri.inhibit_power_key() {
+ warn!("error inhibiting power key: {err:?}");
+ }
}
state.niri.start_dbus(&state.backend, is_systemd_service);
diff --git a/src/niri.rs b/src/niri.rs
index ad0159f9..ad5973e7 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -571,7 +571,6 @@ impl Niri {
let screenshot = gnome_shell_screenshot::Screenshot::new(to_niri, from_niri);
let mut zbus_conn = None;
- let mut inhibit_power_key_fd = None;
if is_session_instance {
let conn = zbus::blocking::ConnectionBuilder::session()
.unwrap()
@@ -617,32 +616,6 @@ impl Niri {
}
zbus_conn = Some(conn);
-
- // Inhibit power key handling so we can suspend on it.
- let zbus_system_conn = zbus::blocking::ConnectionBuilder::system()
- .unwrap()
- .build()
- .unwrap();
-
- // logind-zbus has a wrong signature for this method, so do it manually.
- // https://gitlab.com/flukejones/logind-zbus/-/merge_requests/5
- let message = zbus_system_conn
- .call_method(
- Some("org.freedesktop.login1"),
- "/org/freedesktop/login1",
- Some("org.freedesktop.login1.Manager"),
- "Inhibit",
- &("handle-power-key", "niri", "Power key handling", "block"),
- )
- .unwrap();
- match message.body() {
- Ok(fd) => {
- inhibit_power_key_fd = Some(fd);
- }
- Err(err) => {
- warn!("error inhibiting power key: {err:?}");
- }
- }
} else if config.debug.dbus_interfaces_in_non_session_instances {
let conn = zbus::blocking::Connection::session().unwrap();
let flags = RequestNameFlags::AllowReplacement
@@ -681,7 +654,25 @@ impl Niri {
}
self.zbus_conn = zbus_conn;
- self.inhibit_power_key_fd = inhibit_power_key_fd;
+ }
+
+ pub fn inhibit_power_key(&mut self) -> anyhow::Result<()> {
+ let conn = zbus::blocking::ConnectionBuilder::system()?.build()?;
+
+ // logind-zbus has a wrong signature for this method, so do it manually.
+ // https://gitlab.com/flukejones/logind-zbus/-/merge_requests/5
+ let message = conn.call_method(
+ Some("org.freedesktop.login1"),
+ "/org/freedesktop/login1",
+ Some("org.freedesktop.login1.Manager"),
+ "Inhibit",
+ &("handle-power-key", "niri", "Power key handling", "block"),
+ )?;
+
+ let fd = message.body()?;
+ self.inhibit_power_key_fd = Some(fd);
+
+ Ok(())
}
pub fn add_output(&mut self, output: Output, refresh_interval: Option<Duration>) {