input: Replace wake-monitors-on-input with wake-monitors whitelist
Browse files at this commit111f1cab2576e33768a6fcb6df1e16c5b5abe21dParent: c18d8154 changed files +127 -58
- docs/wiki/Configuration:-Input.md +35 -7
- niri-config/src/input.rs +48 -29
- niri-config/src/lib.rs +18 -3
- src/input/mod.rs +26 -19
docs/wiki/Configuration:-Input.mdmodified+35 -7
| @@ -103,7 +103,7 @@ input { | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | // disable-power-key-handling | 105 | // disable-power-key-handling |
| 106 | - // wake-monitors-on-input false | 106 | + // wake-monitors {} |
| 107 | // warp-mouse-to-focus | 107 | // warp-mouse-to-focus |
| 108 | // focus-follows-mouse max-scroll-amount="0%" | 108 | // focus-follows-mouse max-scroll-amount="0%" |
| 109 | // workspace-auto-back-and-forth | 109 | // workspace-auto-back-and-forth |
| @@ -315,20 +315,48 @@ input { | |||
| 315 | } | 315 | } |
| 316 | ``` | 316 | ``` |
| 317 | 317 | ||
| 318 | -#### `wake-monitors-on-input` | 318 | +#### `wake-monitors` |
| 319 | 319 | ||
| 320 | -By default, any input (a key press, mouse movement, etc.) powers the monitors back on after the `power-off-monitors` action. | 320 | +<sup>Since: next release</sup> |
| 321 | -Set this to `false` to keep them off until the `power-on-monitors` action runs, for example from a bind or from `niri msg action power-on-monitors`. | ||
| 322 | 321 | ||
| 323 | -Binds keep working while the monitors are off, and input still reaches the focused window. | 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. |
| 323 | + | ||
| 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`. | ||
| 336 | + | ||
| 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. | ||
| 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: | ||
| 324 | 351 | ||
| 325 | ```kdl | 352 | ```kdl |
| 326 | input { | 353 | input { |
| 327 | - wake-monitors-on-input false | 354 | + wake-monitors {} |
| 328 | } | 355 | } |
| 329 | 356 | ||
| 330 | binds { | 357 | binds { |
| 331 | - Mod+Ctrl+M { power-on-monitors; } | 358 | + Mod+Shift+P { power-off-monitors; } |
| 359 | + Mod+Shift+O { power-on-monitors; } | ||
| 332 | } | 360 | } |
| 333 | ``` | 361 | ``` |
| 334 | 362 | ||
niri-config/src/input.rsmodified+48 -29
| @@ -14,7 +14,7 @@ use crate::binds::Modifiers; | |||
| 14 | use crate::utils::{expand_home_path, Flag, MergeWith, Percent}; | 14 | use crate::utils::{expand_home_path, Flag, MergeWith, Percent}; |
| 15 | use crate::{FloatOrInt, Includes}; | 15 | use crate::{FloatOrInt, Includes}; |
| 16 | 16 | ||
| 17 | -#[derive(Debug, PartialEq)] | 17 | +#[derive(Debug, Default, PartialEq)] |
| 18 | pub struct Input { | 18 | pub struct Input { |
| 19 | pub keyboard: Keyboard, | 19 | pub keyboard: Keyboard, |
| 20 | pub touchpad: Touchpad, | 20 | pub touchpad: Touchpad, |
| @@ -24,7 +24,7 @@ pub struct Input { | |||
| 24 | pub tablet: Tablet, | 24 | pub tablet: Tablet, |
| 25 | pub touch: Touch, | 25 | pub touch: Touch, |
| 26 | pub disable_power_key_handling: bool, | 26 | pub disable_power_key_handling: bool, |
| 27 | - pub wake_monitors_on_input: bool, | 27 | + pub wake_monitors: Option<WakeMonitors>, |
| 28 | pub warp_mouse_to_focus: Option<WarpMouseToFocus>, | 28 | pub warp_mouse_to_focus: Option<WarpMouseToFocus>, |
| 29 | pub focus_follows_mouse: Option<FocusFollowsMouse>, | 29 | pub focus_follows_mouse: Option<FocusFollowsMouse>, |
| 30 | pub workspace_auto_back_and_forth: bool, | 30 | pub workspace_auto_back_and_forth: bool, |
| @@ -32,27 +32,6 @@ pub struct Input { | |||
| 32 | pub mod_key_nested: Option<ModKey>, | 32 | pub mod_key_nested: Option<ModKey>, |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | -impl Default for Input { | ||
| 36 | - fn default() -> Self { | ||
| 37 | - Self { | ||
| 38 | - keyboard: Default::default(), | ||
| 39 | - touchpad: Default::default(), | ||
| 40 | - mouse: Default::default(), | ||
| 41 | - trackpoint: Default::default(), | ||
| 42 | - trackball: Default::default(), | ||
| 43 | - tablet: Default::default(), | ||
| 44 | - touch: Default::default(), | ||
| 45 | - disable_power_key_handling: false, | ||
| 46 | - wake_monitors_on_input: true, | ||
| 47 | - warp_mouse_to_focus: None, | ||
| 48 | - focus_follows_mouse: None, | ||
| 49 | - workspace_auto_back_and_forth: false, | ||
| 50 | - mod_key: None, | ||
| 51 | - mod_key_nested: None, | ||
| 52 | - } | ||
| 53 | - } | ||
| 54 | -} | ||
| 55 | - | ||
| 56 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 35 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 57 | pub struct InputPart { | 36 | pub struct InputPart { |
| 58 | #[knuffel(child)] | 37 | #[knuffel(child)] |
| @@ -71,8 +50,8 @@ pub struct InputPart { | |||
| 71 | pub touch: Option<Touch>, | 50 | pub touch: Option<Touch>, |
| 72 | #[knuffel(child)] | 51 | #[knuffel(child)] |
| 73 | pub disable_power_key_handling: Option<Flag>, | 52 | pub disable_power_key_handling: Option<Flag>, |
| 74 | - #[knuffel(child, unwrap(argument))] | 53 | + #[knuffel(child)] |
| 75 | - pub wake_monitors_on_input: Option<bool>, | 54 | + pub wake_monitors: Option<WakeMonitors>, |
| 76 | #[knuffel(child)] | 55 | #[knuffel(child)] |
| 77 | pub warp_mouse_to_focus: Option<WarpMouseToFocus>, | 56 | pub warp_mouse_to_focus: Option<WarpMouseToFocus>, |
| 78 | #[knuffel(child)] | 57 | #[knuffel(child)] |
| @@ -94,10 +73,6 @@ impl MergeWith<InputPart> for Input { | |||
| 94 | workspace_auto_back_and_forth, | 73 | workspace_auto_back_and_forth, |
| 95 | ); | 74 | ); |
| 96 | 75 | ||
| 97 | - if let Some(x) = part.wake_monitors_on_input { | ||
| 98 | - self.wake_monitors_on_input = x; | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | merge_clone!( | 76 | merge_clone!( |
| 102 | (self, part), | 77 | (self, part), |
| 103 | touchpad, | 78 | touchpad, |
| @@ -112,6 +87,7 @@ impl MergeWith<InputPart> for Input { | |||
| 112 | (self, part), | 87 | (self, part), |
| 113 | warp_mouse_to_focus, | 88 | warp_mouse_to_focus, |
| 114 | focus_follows_mouse, | 89 | focus_follows_mouse, |
| 90 | + wake_monitors, | ||
| 115 | mod_key, | 91 | mod_key, |
| 116 | mod_key_nested, | 92 | mod_key_nested, |
| 117 | ); | 93 | ); |
| @@ -428,6 +404,49 @@ pub struct FocusFollowsMouse { | |||
| 428 | pub max_scroll_amount: Option<Percent>, | 404 | pub max_scroll_amount: Option<Percent>, |
| 429 | } | 405 | } |
| 430 | 406 | ||
| 407 | +#[derive(knuffel::Decode, Debug, Default, PartialEq, Eq, Clone, Copy)] | ||
| 408 | +pub struct WakeMonitors { | ||
| 409 | + #[knuffel(child)] | ||
| 410 | + pub keyboard: bool, | ||
| 411 | + #[knuffel(child)] | ||
| 412 | + pub pointer_button: bool, | ||
| 413 | + #[knuffel(child)] | ||
| 414 | + pub pointer_move: bool, | ||
| 415 | + #[knuffel(child)] | ||
| 416 | + pub pointer_scroll: bool, | ||
| 417 | + #[knuffel(child)] | ||
| 418 | + pub gesture: bool, | ||
| 419 | + #[knuffel(child)] | ||
| 420 | + pub touch: bool, | ||
| 421 | + #[knuffel(child)] | ||
| 422 | + pub tablet: bool, | ||
| 423 | +} | ||
| 424 | + | ||
| 425 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 426 | +pub enum WakeSource { | ||
| 427 | + Keyboard, | ||
| 428 | + PointerButton, | ||
| 429 | + PointerMove, | ||
| 430 | + PointerScroll, | ||
| 431 | + Gesture, | ||
| 432 | + Touch, | ||
| 433 | + Tablet, | ||
| 434 | +} | ||
| 435 | + | ||
| 436 | +impl WakeMonitors { | ||
| 437 | + pub fn allows(&self, source: WakeSource) -> bool { | ||
| 438 | + match source { | ||
| 439 | + WakeSource::Keyboard => self.keyboard, | ||
| 440 | + WakeSource::PointerButton => self.pointer_button, | ||
| 441 | + WakeSource::PointerMove => self.pointer_move, | ||
| 442 | + WakeSource::PointerScroll => self.pointer_scroll, | ||
| 443 | + WakeSource::Gesture => self.gesture, | ||
| 444 | + WakeSource::Touch => self.touch, | ||
| 445 | + WakeSource::Tablet => self.tablet, | ||
| 446 | + } | ||
| 447 | + } | ||
| 448 | +} | ||
| 449 | + | ||
| 431 | #[derive(knuffel::Decode, Debug, PartialEq, Eq, Clone, Copy)] | 450 | #[derive(knuffel::Decode, Debug, PartialEq, Eq, Clone, Copy)] |
| 432 | pub struct WarpMouseToFocus { | 451 | pub struct WarpMouseToFocus { |
| 433 | #[knuffel(property, str)] | 452 | #[knuffel(property, str)] |
niri-config/src/lib.rsmodified+18 -3
| @@ -50,7 +50,9 @@ pub use crate::binds::*; | |||
| 50 | pub use crate::debug::Debug; | 50 | pub use crate::debug::Debug; |
| 51 | pub use crate::error::{ConfigIncludeError, ConfigParseResult}; | 51 | pub use crate::error::{ConfigIncludeError, ConfigParseResult}; |
| 52 | pub use crate::gestures::Gestures; | 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 | pub use crate::layer_rule::LayerRule; | 56 | pub use crate::layer_rule::LayerRule; |
| 55 | pub use crate::layout::*; | 57 | pub use crate::layout::*; |
| 56 | pub use crate::misc::*; | 58 | pub use crate::misc::*; |
| @@ -1221,7 +1223,10 @@ mod tests { | |||
| 1221 | } | 1223 | } |
| 1222 | 1224 | ||
| 1223 | disable-power-key-handling | 1225 | disable-power-key-handling |
| 1224 | - wake-monitors-on-input false | 1226 | + wake-monitors { |
| 1227 | + keyboard | ||
| 1228 | + pointer-button | ||
| 1229 | + } | ||
| 1225 | 1230 | ||
| 1226 | warp-mouse-to-focus | 1231 | warp-mouse-to-focus |
| 1227 | focus-follows-mouse | 1232 | focus-follows-mouse |
| @@ -1634,7 +1639,17 @@ mod tests { | |||
| 1634 | ), | 1639 | ), |
| 1635 | }, | 1640 | }, |
| 1636 | disable_power_key_handling: true, | 1641 | disable_power_key_handling: true, |
| 1637 | - wake_monitors_on_input: false, | 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 | warp_mouse_to_focus: Some( | 1653 | warp_mouse_to_focus: Some( |
| 1639 | WarpMouseToFocus { | 1654 | WarpMouseToFocus { |
| 1640 | mode: None, | 1655 | mode: None, |
src/input/mod.rsmodified+26 -19
| @@ -8,7 +8,7 @@ use calloop::RegistrationToken; | |||
| 8 | use input::event::gesture::GestureEventCoordinates as _; | 8 | use input::event::gesture::GestureEventCoordinates as _; |
| 9 | use niri_config::{ | 9 | use niri_config::{ |
| 10 | Action, Bind, Binds, BoundAction, Config, Key, ModKey, Modifiers, MruDirection, MruFilter, | 10 | Action, Bind, Binds, BoundAction, Config, Key, ModKey, Modifiers, MruDirection, MruFilter, |
| 11 | - MruScope, SwitchBinds, Trigger, WorkspaceReference, | 11 | + MruScope, SwitchBinds, Trigger, WakeSource, WorkspaceReference, |
| 12 | }; | 12 | }; |
| 13 | use niri_ipc::LayoutSwitchTarget; | 13 | use niri_ipc::LayoutSwitchTarget; |
| 14 | use smithay::backend::input::{ | 14 | use smithay::backend::input::{ |
| @@ -188,11 +188,14 @@ impl State { | |||
| 188 | self.niri.notify_activity(); | 188 | self.niri.notify_activity(); |
| 189 | } | 189 | } |
| 190 | } else { | 190 | } else { |
| 191 | - // Power on monitors if they were off, unless the config leaves that to the | 191 | + // Power on monitors if they were off. |
| 192 | - // power-on-monitors action. | 192 | + let wake = wake_source(&event).is_some_and(|source| { |
| 193 | - if self.niri.config.borrow().input.wake_monitors_on_input | 193 | + match self.niri.config.borrow().input.wake_monitors { |
| 194 | - && should_activate_monitors(&event) | 194 | + None => true, |
| 195 | - { | 195 | + Some(wake_monitors) => wake_monitors.allows(source), |
| 196 | + } | ||
| 197 | + }); | ||
| 198 | + if wake { | ||
| 196 | self.niri.activate_monitors(&mut self.backend); | 199 | self.niri.activate_monitors(&mut self.backend); |
| 197 | 200 | ||
| 198 | // Notify the idle-notifier of activity only if we're also powering on the | 201 | // Notify the idle-notifier of activity only if we're also powering on the |
| @@ -5419,24 +5422,28 @@ fn modifiers_from_state(mods: ModifiersState) -> Modifiers { | |||
| 5419 | modifiers | 5422 | modifiers |
| 5420 | } | 5423 | } |
| 5421 | 5424 | ||
| 5422 | -fn should_activate_monitors<I: InputBackend>(event: &InputEvent<I>) -> bool { | 5425 | +fn wake_source<I: InputBackend>(event: &InputEvent<I>) -> Option<WakeSource> { |
| 5423 | match event { | 5426 | match event { |
| 5424 | - InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => true, | 5427 | + InputEvent::Keyboard { event } if event.state() == KeyState::Pressed => { |
| 5425 | - InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => true, | 5428 | + Some(WakeSource::Keyboard) |
| 5426 | - InputEvent::PointerMotion { .. } | 5429 | + } |
| 5427 | - | InputEvent::PointerMotionAbsolute { .. } | 5430 | + InputEvent::PointerButton { event } if event.state() == ButtonState::Pressed => { |
| 5428 | - | InputEvent::PointerAxis { .. } | 5431 | + Some(WakeSource::PointerButton) |
| 5429 | - | InputEvent::GestureSwipeBegin { .. } | 5432 | + } |
| 5433 | + InputEvent::PointerMotion { .. } | InputEvent::PointerMotionAbsolute { .. } => { | ||
| 5434 | + Some(WakeSource::PointerMove) | ||
| 5435 | + } | ||
| 5436 | + InputEvent::PointerAxis { .. } => Some(WakeSource::PointerScroll), | ||
| 5437 | + InputEvent::GestureSwipeBegin { .. } | ||
| 5430 | | InputEvent::GesturePinchBegin { .. } | 5438 | | InputEvent::GesturePinchBegin { .. } |
| 5431 | - | InputEvent::GestureHoldBegin { .. } | 5439 | + | InputEvent::GestureHoldBegin { .. } => Some(WakeSource::Gesture), |
| 5432 | - | InputEvent::TouchDown { .. } | 5440 | + InputEvent::TouchDown { .. } | InputEvent::TouchMotion { .. } => Some(WakeSource::Touch), |
| 5433 | - | InputEvent::TouchMotion { .. } | 5441 | + InputEvent::TabletToolAxis { .. } |
| 5434 | - | InputEvent::TabletToolAxis { .. } | ||
| 5435 | | InputEvent::TabletToolProximity { .. } | 5442 | | InputEvent::TabletToolProximity { .. } |
| 5436 | | InputEvent::TabletToolTip { .. } | 5443 | | InputEvent::TabletToolTip { .. } |
| 5437 | - | InputEvent::TabletToolButton { .. } => true, | 5444 | + | InputEvent::TabletToolButton { .. } => Some(WakeSource::Tablet), |
| 5438 | // Ignore events like device additions and removals, key releases, gesture ends. | 5445 | // Ignore events like device additions and removals, key releases, gesture ends. |
| 5439 | - _ => false, | 5446 | + _ => None, |
| 5440 | } | 5447 | } |
| 5441 | } | 5448 | } |
| 5442 | 5449 | ||