diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-03 07:31:44 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-03 07:31:44 +0400 |
| commit | 14729f772bfc049cfe04d43b5a5ab7186c2bc021 (patch) | |
| tree | 1529d773c747a8f865ad87f28c9df50cf908275c /src/tty.rs | |
| parent | 2c1d2ce0d33401990734d07d5910def97dc82998 (diff) | |
| download | niri-14729f772bfc049cfe04d43b5a5ab7186c2bc021.tar.gz niri-14729f772bfc049cfe04d43b5a5ab7186c2bc021.tar.bz2 niri-14729f772bfc049cfe04d43b5a5ab7186c2bc021.zip | |
Add suspend key handling
Diffstat (limited to 'src/tty.rs')
| -rw-r--r-- | src/tty.rs | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -3,7 +3,7 @@ use std::os::fd::FromRawFd; use std::path::{Path, PathBuf}; use std::time::Duration; -use anyhow::anyhow; +use anyhow::{anyhow, Context}; use smithay::backend::allocator::dmabuf::Dmabuf; use smithay::backend::allocator::gbm::{GbmAllocator, GbmBufferFlags, GbmDevice}; use smithay::backend::allocator::{Format as DrmFormat, Fourcc}; @@ -179,6 +179,11 @@ impl Tty { match niri.process_input_event(CompositorMod::Super, event) { BackendAction::None => (), BackendAction::ChangeVt(vt) => tty.change_vt(vt), + BackendAction::Suspend => { + if let Err(err) = suspend() { + warn!("error suspending: {err:?}"); + } + } BackendAction::Screenshot => { let active = niri.monitor_set.active_output().cloned(); if let Some(active) = active { @@ -609,3 +614,10 @@ fn refresh_interval(mode: DrmMode) -> Duration { let refresh_interval = (numerator + denominator / 2) / denominator; Duration::from_nanos(refresh_interval) } + +fn suspend() -> anyhow::Result<()> { + let conn = zbus::blocking::Connection::system().context("error connecting to system bus")?; + let manager = logind_zbus::manager::ManagerProxyBlocking::new(&conn) + .context("error creating login manager proxy")?; + manager.suspend(true).context("error suspending") +} |
