input: Replace disable-monitor-wake with wake-monitors whitelist
Browse files at this commitb56079b7698eca90a5b9e9774c92ff223fb4a328Parent: ae1ecbf4 changed files +117 -27
- docs/wiki/Configuration:-Input.md +28 -4
- niri-config/src/input.rs +46 -3
- niri-config/src/lib.rs +18 -3
- src/input/mod.rs +25 -17
docs/wiki/Configuration:-Input.mdmodified+28 -4
| @@ -103,6 +103,7 @@ input { | ||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // disable-power-key-handling |
| 106 | + // wake-monitors {} | |
| 106 | 107 | // warp-mouse-to-focus |
| 107 | 108 | // focus-follows-mouse max-scroll-amount="0%" |
| 108 | 109 | // workspace-auto-back-and-forth |
| @@ -314,20 +315,43 @@ input { | ||
| 314 | 315 | } |
| 315 | 316 | ``` |
| 316 | 317 | |
| 317 | -#### `disable-monitor-wake` | |
| 318 | +#### `wake-monitors` | |
| 318 | 319 | |
| 319 | 320 | <sup>Since: next release</sup> |
| 320 | 321 | |
| 321 | 322 | 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. |
| 322 | 323 | |
| 323 | -Set this flag to keep the monitors off regardless of input. | |
| 324 | -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`. | |
| 324 | +Set this block to choose which input kinds power them back on. When it is set, only the listed kinds wake the monitors: | |
| 325 | + | |
| 326 | +- `keyboard`: key press | |
| 327 | +- `pointer-button`: mouse button press | |
| 328 | +- `pointer-move`: mouse movement | |
| 329 | +- `pointer-scroll`: mouse scroll | |
| 330 | +- `gesture`: touchpad gestures | |
| 331 | +- `touch`: touchscreen | |
| 332 | +- `tablet`: graphics tablet | |
| 333 | + | |
| 334 | +An empty block disables waking from input entirely. | |
| 335 | +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`. | |
| 325 | 336 | |
| 326 | 337 | 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. |
| 327 | 338 | |
| 339 | +Wake on keys and clicks, but not mouse movement or scroll: | |
| 340 | + | |
| 341 | +```kdl | |
| 342 | +input { | |
| 343 | + wake-monitors { | |
| 344 | + keyboard | |
| 345 | + pointer-button | |
| 346 | + } | |
| 347 | +} | |
| 348 | +``` | |
| 349 | + | |
| 350 | +Never wake from input, only with the `power-on-monitors` action: | |
| 351 | + | |
| 328 | 352 | ```kdl |
| 329 | 353 | input { |
| 330 | - disable-monitor-wake | |
| 354 | + wake-monitors {} | |
| 331 | 355 | } |
| 332 | 356 | |
| 333 | 357 | binds { |
niri-config/src/input.rsmodified+46 -3
| @@ -24,7 +24,7 @@ pub struct Input { | ||
| 24 | 24 | pub tablet: Tablet, |
| 25 | 25 | pub touch: Touch, |
| 26 | 26 | pub disable_power_key_handling: bool, |
| 27 | - pub disable_monitor_wake: bool, | |
| 27 | + pub wake_monitors: Option<WakeMonitors>, | |
| 28 | 28 | pub warp_mouse_to_focus: Option<WarpMouseToFocus>, |
| 29 | 29 | pub focus_follows_mouse: Option<FocusFollowsMouse>, |
| 30 | 30 | pub workspace_auto_back_and_forth: bool, |
| @@ -51,7 +51,7 @@ pub struct InputPart { | ||
| 51 | 51 | #[knuffel(child)] |
| 52 | 52 | pub disable_power_key_handling: Option<Flag>, |
| 53 | 53 | #[knuffel(child)] |
| 54 | - pub disable_monitor_wake: Option<Flag>, | |
| 54 | + pub wake_monitors: Option<WakeMonitors>, | |
| 55 | 55 | #[knuffel(child)] |
| 56 | 56 | pub warp_mouse_to_focus: Option<WarpMouseToFocus>, |
| 57 | 57 | #[knuffel(child)] |
| @@ -70,7 +70,6 @@ impl MergeWith<InputPart> for Input { | ||
| 70 | 70 | (self, part), |
| 71 | 71 | keyboard, |
| 72 | 72 | disable_power_key_handling, |
| 73 | - disable_monitor_wake, | |
| 74 | 73 | workspace_auto_back_and_forth, |
| 75 | 74 | ); |
| 76 | 75 | |
| @@ -88,6 +87,7 @@ impl MergeWith<InputPart> for Input { | ||
| 88 | 87 | (self, part), |
| 89 | 88 | warp_mouse_to_focus, |
| 90 | 89 | focus_follows_mouse, |
| 90 | + wake_monitors, | |
| 91 | 91 | mod_key, |
| 92 | 92 | mod_key_nested, |
| 93 | 93 | ); |
| @@ -402,6 +402,49 @@ pub struct FocusFollowsMouse { | ||
| 402 | 402 | pub max_scroll_amount: Option<Percent>, |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | +#[derive(knuffel::Decode, Debug, Default, PartialEq, Eq, Clone, Copy)] | |
| 406 | +pub struct WakeMonitors { | |
| 407 | + #[knuffel(child)] | |
| 408 | + pub keyboard: bool, | |
| 409 | + #[knuffel(child)] | |
| 410 | + pub pointer_button: bool, | |
| 411 | + #[knuffel(child)] | |
| 412 | + pub pointer_move: bool, | |
| 413 | + #[knuffel(child)] | |
| 414 | + pub pointer_scroll: bool, | |
| 415 | + #[knuffel(child)] | |
| 416 | + pub gesture: bool, | |
| 417 | + #[knuffel(child)] | |
| 418 | + pub touch: bool, | |
| 419 | + #[knuffel(child)] | |
| 420 | + pub tablet: bool, | |
| 421 | +} | |
| 422 | + | |
| 423 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
| 424 | +pub enum WakeSource { | |
| 425 | + Keyboard, | |
| 426 | + PointerButton, | |
| 427 | + PointerMove, | |
| 428 | + PointerScroll, | |
| 429 | + Gesture, | |
| 430 | + Touch, | |
| 431 | + Tablet, | |
| 432 | +} | |
| 433 | + | |
| 434 | +impl WakeMonitors { | |
| 435 | + pub fn allows(&self, source: WakeSource) -> bool { | |
| 436 | + match source { | |
| 437 | + WakeSource::Keyboard => self.keyboard, | |
| 438 | + WakeSource::PointerButton => self.pointer_button, | |
| 439 | + WakeSource::PointerMove => self.pointer_move, | |
| 440 | + WakeSource::PointerScroll => self.pointer_scroll, | |
| 441 | + WakeSource::Gesture => self.gesture, | |
| 442 | + WakeSource::Touch => self.touch, | |
| 443 | + WakeSource::Tablet => self.tablet, | |
| 444 | + } | |
| 445 | + } | |
| 446 | +} | |
| 447 | + | |
| 405 | 448 | #[derive(knuffel::Decode, Debug, PartialEq, Eq, Clone, Copy)] |
| 406 | 449 | pub struct WarpMouseToFocus { |
| 407 | 450 | #[knuffel(property, str)] |
niri-config/src/lib.rsmodified+18 -3
| @@ -50,7 +50,9 @@ pub use crate::binds::*; | ||
| 50 | 50 | pub use crate::debug::Debug; |
| 51 | 51 | pub use crate::error::{ConfigIncludeError, ConfigParseResult}; |
| 52 | 52 | pub use crate::gestures::Gestures; |
| 53 | -pub use crate::input::{Input, ModKey, ScrollMethod, TrackLayout, WarpMouseToFocusMode, Xkb}; | |
| 53 | +pub use crate::input::{ | |
| 54 | + Input, ModKey, ScrollMethod, TrackLayout, WakeMonitors, WakeSource, WarpMouseToFocusMode, Xkb, | |
| 55 | +}; | |
| 54 | 56 | pub use crate::layer_rule::LayerRule; |
| 55 | 57 | pub use crate::layout::*; |
| 56 | 58 | pub use crate::misc::*; |
| @@ -1221,7 +1223,10 @@ mod tests { | ||
| 1221 | 1223 | } |
| 1222 | 1224 | |
| 1223 | 1225 | disable-power-key-handling |
| 1224 | - disable-monitor-wake | |
| 1226 | + wake-monitors { | |
| 1227 | + keyboard | |
| 1228 | + pointer-button | |
| 1229 | + } | |
| 1225 | 1230 | |
| 1226 | 1231 | warp-mouse-to-focus |
| 1227 | 1232 | focus-follows-mouse |
| @@ -1634,7 +1639,17 @@ mod tests { | ||
| 1634 | 1639 | ), |
| 1635 | 1640 | }, |
| 1636 | 1641 | disable_power_key_handling: true, |
| 1637 | - disable_monitor_wake: true, | |
| 1642 | + wake_monitors: Some( | |
| 1643 | + WakeMonitors { | |
| 1644 | + keyboard: true, | |
| 1645 | + pointer_button: true, | |
| 1646 | + pointer_move: false, | |
| 1647 | + pointer_scroll: false, | |
| 1648 | + gesture: false, | |
| 1649 | + touch: false, | |
| 1650 | + tablet: false, | |
| 1651 | + }, | |
| 1652 | + ), | |
| 1638 | 1653 | warp_mouse_to_focus: Some( |
| 1639 | 1654 | WarpMouseToFocus { |
| 1640 | 1655 | mode: None, |
src/input/mod.rsmodified+25 -17
| @@ -8,7 +8,7 @@ use calloop::RegistrationToken; | ||
| 8 | 8 | use input::event::gesture::GestureEventCoordinates as _; |
| 9 | 9 | use niri_config::{ |
| 10 | 10 | Action, Bind, Binds, BoundAction, Config, Key, ModKey, Modifiers, MruDirection, SwitchBinds, |
| 11 | - Trigger, | |
| 11 | + Trigger, WakeSource, | |
| 12 | 12 | }; |
| 13 | 13 | use niri_ipc::LayoutSwitchTarget; |
| 14 | 14 | use smithay::backend::input::{ |
| @@ -164,9 +164,13 @@ impl State { | ||
| 164 | 164 | } |
| 165 | 165 | } else { |
| 166 | 166 | // Power on monitors if they were off. |
| 167 | - if !self.niri.config.borrow().input.disable_monitor_wake | |
| 168 | - && should_activate_monitors(&event) | |
| 169 | - { | |
| 167 | + let wake = wake_source(&event).is_some_and(|source| { | |
| 168 | + match self.niri.config.borrow().input.wake_monitors { | |
| 169 | + None => true, | |
| 170 | + Some(wake_monitors) => wake_monitors.allows(source), | |
| 171 | + } | |
| 172 | + }); | |
| 173 | + if wake { | |
| 170 | 174 | self.niri.activate_monitors(&mut self.backend); |
| 171 | 175 | |
| 172 | 176 | // 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 { | ||
| 5087 | 5091 | modifiers |
| 5088 | 5092 | } |
| 5089 | 5093 | |
| 5090 | -fn should_activate_monitors<I: InputBackend>(event: &InputEvent<I>) -> bool { | |
| 5094 | +fn wake_source<I: InputBackend>(event: &InputEvent<I>) -> Option<WakeSource> { | |
| 5091 | 5095 | match event { |
| 5092 | - InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true, | |
| 5093 | - InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => true, | |
| 5094 | - InputEvent::PointerMotion { .. } | |
| 5095 | - | InputEvent::PointerMotionAbsolute { .. } | |
| 5096 | - | InputEvent::PointerAxis { .. } | |
| 5097 | - | InputEvent::GestureSwipeBegin { .. } | |
| 5096 | + InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => { | |
| 5097 | + Some(WakeSource::Keyboard) | |
| 5098 | + } | |
| 5099 | + InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => { | |
| 5100 | + Some(WakeSource::PointerButton) | |
| 5101 | + } | |
| 5102 | + InputEvent::PointerMotion { .. } | InputEvent::PointerMotionAbsolute { .. } => { | |
| 5103 | + Some(WakeSource::PointerMove) | |
| 5104 | + } | |
| 5105 | + InputEvent::PointerAxis { .. } => Some(WakeSource::PointerScroll), | |
| 5106 | + InputEvent::GestureSwipeBegin { .. } | |
| 5098 | 5107 | | InputEvent::GesturePinchBegin { .. } |
| 5099 | - | InputEvent::GestureHoldBegin { .. } | |
| 5100 | - | InputEvent::TouchDown { .. } | |
| 5101 | - | InputEvent::TouchMotion { .. } | |
| 5102 | - | InputEvent::TabletToolAxis { .. } | |
| 5108 | + | InputEvent::GestureHoldBegin { .. } => Some(WakeSource::Gesture), | |
| 5109 | + InputEvent::TouchDown { .. } | InputEvent::TouchMotion { .. } => Some(WakeSource::Touch), | |
| 5110 | + InputEvent::TabletToolAxis { .. } | |
| 5103 | 5111 | | InputEvent::TabletToolProximity { .. } |
| 5104 | 5112 | | InputEvent::TabletToolTip { .. } |
| 5105 | - | InputEvent::TabletToolButton { .. } => true, | |
| 5113 | + | InputEvent::TabletToolButton { .. } => Some(WakeSource::Tablet), | |
| 5106 | 5114 | // Ignore events like device additions and removals, key releases, gesture ends. |
| 5107 | - _ => false, | |
| 5115 | + _ => None, | |
| 5108 | 5116 | } |
| 5109 | 5117 | } |
| 5110 | 5118 |