mirror of
https://github.com/YaLTeR/niri.git
synced 2024-09-11 12:35:58 +03:00
Add suspend key handling
This commit is contained in:
parent
2c1d2ce0d3
commit
14729f772b
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -1109,6 +1109,16 @@ version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "logind-zbus"
|
||||
version = "3.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c07a2542f6e91ea92780158654852190edb2ba0b232d9d00d649d0c691cb7eb3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "loom"
|
||||
version = "0.5.6"
|
||||
@ -1240,6 +1250,7 @@ dependencies = [
|
||||
"directories",
|
||||
"image",
|
||||
"keyframe",
|
||||
"logind-zbus",
|
||||
"profiling",
|
||||
"sd-notify",
|
||||
"smithay",
|
||||
|
@ -13,6 +13,7 @@ clap = { version = "4.3.21", features = ["derive"] }
|
||||
directories = "5.0.1"
|
||||
image = { version = "0.24.7", default-features = false, features = ["png"] }
|
||||
keyframe = { version = "1.1.1", default-features = false }
|
||||
logind-zbus = "3.1.2"
|
||||
profiling = "1.0.9"
|
||||
sd-notify = "0.4.1"
|
||||
smithay-drm-extras = { version = "0.1.0", path = "../smithay/smithay-drm-extras" }
|
||||
|
17
src/input.rs
17
src/input.rs
@ -24,6 +24,7 @@ enum Action {
|
||||
None,
|
||||
Quit,
|
||||
ChangeVt(i32),
|
||||
Suspend,
|
||||
Spawn(String),
|
||||
Screenshot,
|
||||
CloseWindow,
|
||||
@ -57,6 +58,7 @@ enum Action {
|
||||
pub enum BackendAction {
|
||||
None,
|
||||
ChangeVt(i32),
|
||||
Suspend,
|
||||
Screenshot,
|
||||
}
|
||||
|
||||
@ -78,9 +80,15 @@ fn action(comp_mod: CompositorMod, keysym: KeysymHandle, mods: ModifiersState) -
|
||||
use keysyms::*;
|
||||
|
||||
let modified = keysym.modified_sym();
|
||||
if matches!(modified, KEY_XF86Switch_VT_1..=KEY_XF86Switch_VT_12) {
|
||||
let vt = (modified - KEY_XF86Switch_VT_1 + 1) as i32;
|
||||
return Action::ChangeVt(vt);
|
||||
|
||||
#[allow(non_upper_case_globals)] // wat
|
||||
match modified {
|
||||
modified @ KEY_XF86Switch_VT_1..=KEY_XF86Switch_VT_12 => {
|
||||
let vt = (modified - KEY_XF86Switch_VT_1 + 1) as i32;
|
||||
return Action::ChangeVt(vt);
|
||||
}
|
||||
KEY_XF86PowerOff => return Action::Suspend,
|
||||
_ => (),
|
||||
}
|
||||
|
||||
let mod_down = match comp_mod {
|
||||
@ -182,6 +190,9 @@ impl Niri {
|
||||
Action::ChangeVt(vt) => {
|
||||
return BackendAction::ChangeVt(vt);
|
||||
}
|
||||
Action::Suspend => {
|
||||
return BackendAction::Suspend;
|
||||
}
|
||||
Action::Spawn(command) => {
|
||||
if let Err(err) = Command::new(command).spawn() {
|
||||
warn!("error spawning alacritty: {err}");
|
||||
|
14
src/tty.rs
14
src/tty.rs
@ -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")
|
||||
}
|
||||
|
@ -149,6 +149,7 @@ impl Winit {
|
||||
match niri.process_input_event(CompositorMod::Alt, event) {
|
||||
BackendAction::None => (),
|
||||
BackendAction::ChangeVt(_) => (),
|
||||
BackendAction::Suspend => (),
|
||||
BackendAction::Screenshot => {
|
||||
let active = niri.monitor_set.active_output().cloned();
|
||||
if let Some(active) = active {
|
||||
|
Loading…
Reference in New Issue
Block a user