diff --git a/docs/wiki/Configuration:-Input.md b/docs/wiki/Configuration:-Input.md index 972153bd..7612f831 100644 --- a/docs/wiki/Configuration:-Input.md +++ b/docs/wiki/Configuration:-Input.md @@ -103,6 +103,7 @@ input { } // disable-power-key-handling + // wake-monitors {} // warp-mouse-to-focus // focus-follows-mouse max-scroll-amount="0%" // workspace-auto-back-and-forth @@ -314,20 +315,43 @@ input { } ``` -#### `disable-monitor-wake` +#### `wake-monitors` Since: next release By default, when monitors are powered off (for example, with the `power-off-monitors` action), any input like moving the mouse or pressing a key powers them back on. -Set this flag to keep the monitors off regardless of input. -Then, the only way to power them back on is the `power-on-monitors` action, for example bound to a key or invoked with `niri msg action power-on-monitors`. +Set this block to choose which input kinds power them back on. When it is set, only the listed kinds wake the monitors: + +- `keyboard`: key press +- `pointer-button`: mouse button press +- `pointer-move`: mouse movement +- `pointer-scroll`: mouse scroll +- `gesture`: touchpad gestures +- `touch`: touchscreen +- `tablet`: graphics tablet + +An empty block disables waking from input entirely. +Then, the only way to power the monitors back on is the `power-on-monitors` action, for example bound to a key or invoked with `niri msg action power-on-monitors`. Keep in mind that other input keeps working normally while the monitors are off: keys will go to the focused window, and binds will trigger their actions. +Wake on keys and clicks, but not mouse movement or scroll: + +```kdl +input { + wake-monitors { + keyboard + pointer-button + } +} +``` + +Never wake from input, only with the `power-on-monitors` action: + ```kdl input { - disable-monitor-wake + wake-monitors {} } binds { diff --git a/niri-config/src/input.rs b/niri-config/src/input.rs index 696d5219..99356a4d 100644 --- a/niri-config/src/input.rs +++ b/niri-config/src/input.rs @@ -24,7 +24,7 @@ pub struct Input { pub tablet: Tablet, pub touch: Touch, pub disable_power_key_handling: bool, - pub disable_monitor_wake: bool, + pub wake_monitors: Option, pub warp_mouse_to_focus: Option, pub focus_follows_mouse: Option, pub workspace_auto_back_and_forth: bool, @@ -51,7 +51,7 @@ pub struct InputPart { #[knuffel(child)] pub disable_power_key_handling: Option, #[knuffel(child)] - pub disable_monitor_wake: Option, + pub wake_monitors: Option, #[knuffel(child)] pub warp_mouse_to_focus: Option, #[knuffel(child)] @@ -70,7 +70,6 @@ impl MergeWith for Input { (self, part), keyboard, disable_power_key_handling, - disable_monitor_wake, workspace_auto_back_and_forth, ); @@ -88,6 +87,7 @@ impl MergeWith for Input { (self, part), warp_mouse_to_focus, focus_follows_mouse, + wake_monitors, mod_key, mod_key_nested, ); @@ -402,6 +402,49 @@ pub struct FocusFollowsMouse { pub max_scroll_amount: Option, } +#[derive(knuffel::Decode, Debug, Default, PartialEq, Eq, Clone, Copy)] +pub struct WakeMonitors { + #[knuffel(child)] + pub keyboard: bool, + #[knuffel(child)] + pub pointer_button: bool, + #[knuffel(child)] + pub pointer_move: bool, + #[knuffel(child)] + pub pointer_scroll: bool, + #[knuffel(child)] + pub gesture: bool, + #[knuffel(child)] + pub touch: bool, + #[knuffel(child)] + pub tablet: bool, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum WakeSource { + Keyboard, + PointerButton, + PointerMove, + PointerScroll, + Gesture, + Touch, + Tablet, +} + +impl WakeMonitors { + pub fn allows(&self, source: WakeSource) -> bool { + match source { + WakeSource::Keyboard => self.keyboard, + WakeSource::PointerButton => self.pointer_button, + WakeSource::PointerMove => self.pointer_move, + WakeSource::PointerScroll => self.pointer_scroll, + WakeSource::Gesture => self.gesture, + WakeSource::Touch => self.touch, + WakeSource::Tablet => self.tablet, + } + } +} + #[derive(knuffel::Decode, Debug, PartialEq, Eq, Clone, Copy)] pub struct WarpMouseToFocus { #[knuffel(property, str)] diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index ab2ba4a6..64658cc7 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -50,7 +50,9 @@ pub use crate::binds::*; pub use crate::debug::Debug; pub use crate::error::{ConfigIncludeError, ConfigParseResult}; pub use crate::gestures::Gestures; -pub use crate::input::{Input, ModKey, ScrollMethod, TrackLayout, WarpMouseToFocusMode, Xkb}; +pub use crate::input::{ + Input, ModKey, ScrollMethod, TrackLayout, WakeMonitors, WakeSource, WarpMouseToFocusMode, Xkb, +}; pub use crate::layer_rule::LayerRule; pub use crate::layout::*; pub use crate::misc::*; @@ -1221,7 +1223,10 @@ mod tests { } disable-power-key-handling - disable-monitor-wake + wake-monitors { + keyboard + pointer-button + } warp-mouse-to-focus focus-follows-mouse @@ -1634,7 +1639,17 @@ mod tests { ), }, disable_power_key_handling: true, - disable_monitor_wake: true, + wake_monitors: Some( + WakeMonitors { + keyboard: true, + pointer_button: true, + pointer_move: false, + pointer_scroll: false, + gesture: false, + touch: false, + tablet: false, + }, + ), warp_mouse_to_focus: Some( WarpMouseToFocus { mode: None, diff --git a/src/input/mod.rs b/src/input/mod.rs index d5ad5921..9f0db3af 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -8,7 +8,7 @@ use calloop::RegistrationToken; use input::event::gesture::GestureEventCoordinates as _; use niri_config::{ Action, Bind, Binds, BoundAction, Config, Key, ModKey, Modifiers, MruDirection, SwitchBinds, - Trigger, + Trigger, WakeSource, }; use niri_ipc::LayoutSwitchTarget; use smithay::backend::input::{ @@ -164,9 +164,13 @@ impl State { } } else { // Power on monitors if they were off. - if !self.niri.config.borrow().input.disable_monitor_wake - && should_activate_monitors(&event) - { + let wake = wake_source(&event).is_some_and(|source| { + match self.niri.config.borrow().input.wake_monitors { + None => true, + Some(wake_monitors) => wake_monitors.allows(source), + } + }); + if wake { self.niri.activate_monitors(&mut self.backend); // Notify the idle-notifier of activity only if we're also powering on the @@ -5087,24 +5091,28 @@ fn modifiers_from_state(mods: ModifiersState) -> Modifiers { modifiers } -fn should_activate_monitors(event: &InputEvent) -> bool { +fn wake_source(event: &InputEvent) -> Option { match event { - InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true, - InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => true, - InputEvent::PointerMotion { .. } - | InputEvent::PointerMotionAbsolute { .. } - | InputEvent::PointerAxis { .. } - | InputEvent::GestureSwipeBegin { .. } + InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => { + Some(WakeSource::Keyboard) + } + InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => { + Some(WakeSource::PointerButton) + } + InputEvent::PointerMotion { .. } | InputEvent::PointerMotionAbsolute { .. } => { + Some(WakeSource::PointerMove) + } + InputEvent::PointerAxis { .. } => Some(WakeSource::PointerScroll), + InputEvent::GestureSwipeBegin { .. } | InputEvent::GesturePinchBegin { .. } - | InputEvent::GestureHoldBegin { .. } - | InputEvent::TouchDown { .. } - | InputEvent::TouchMotion { .. } - | InputEvent::TabletToolAxis { .. } + | InputEvent::GestureHoldBegin { .. } => Some(WakeSource::Gesture), + InputEvent::TouchDown { .. } | InputEvent::TouchMotion { .. } => Some(WakeSource::Touch), + InputEvent::TabletToolAxis { .. } | InputEvent::TabletToolProximity { .. } | InputEvent::TabletToolTip { .. } - | InputEvent::TabletToolButton { .. } => true, + | InputEvent::TabletToolButton { .. } => Some(WakeSource::Tablet), // Ignore events like device additions and removals, key releases, gesture ends. - _ => false, + _ => None, } }