forge
Explore
Log in

Don't you dare go Hollow

input: Replace disable-monitor-wake with wake-monitors whitelist

Browse files at this commit

b56079b7698eca90a5b9e9774c92ff223fb4a328Ahmet Kaan GümüşParent: ae1ecbf
Without the block every input wakes monitors as before. With it, only
the listed input kinds wake them, and an empty block leaves waking to the
power-on-monitors action.
docs/wiki/Configuration:-Input.mdmodified+28 -4
@@ -103,6 +103,7 @@ input {
103103 }
104104
105105 // disable-power-key-handling
106+ // wake-monitors {}
106107 // warp-mouse-to-focus
107108 // focus-follows-mouse max-scroll-amount="0%"
108109 // workspace-auto-back-and-forth
@@ -314,20 +315,43 @@ input {
314315 }
315316 ```
316317
317-#### `disable-monitor-wake`
318+#### `wake-monitors`
318319
319320 <sup>Since: next release</sup>
320321
321322 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.
322323
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`.
325336
326337 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.
327338
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+
328352 ```kdl
329353 input {
330- disable-monitor-wake
354+ wake-monitors {}
331355 }
332356
333357 binds {
niri-config/src/input.rsmodified+46 -3
@@ -24,7 +24,7 @@ pub struct Input {
2424 pub tablet: Tablet,
2525 pub touch: Touch,
2626 pub disable_power_key_handling: bool,
27- pub disable_monitor_wake: bool,
27+ pub wake_monitors: Option<WakeMonitors>,
2828 pub warp_mouse_to_focus: Option<WarpMouseToFocus>,
2929 pub focus_follows_mouse: Option<FocusFollowsMouse>,
3030 pub workspace_auto_back_and_forth: bool,
@@ -51,7 +51,7 @@ pub struct InputPart {
5151 #[knuffel(child)]
5252 pub disable_power_key_handling: Option<Flag>,
5353 #[knuffel(child)]
54- pub disable_monitor_wake: Option<Flag>,
54+ pub wake_monitors: Option<WakeMonitors>,
5555 #[knuffel(child)]
5656 pub warp_mouse_to_focus: Option<WarpMouseToFocus>,
5757 #[knuffel(child)]
@@ -70,7 +70,6 @@ impl MergeWith<InputPart> for Input {
7070 (self, part),
7171 keyboard,
7272 disable_power_key_handling,
73- disable_monitor_wake,
7473 workspace_auto_back_and_forth,
7574 );
7675
@@ -88,6 +87,7 @@ impl MergeWith<InputPart> for Input {
8887 (self, part),
8988 warp_mouse_to_focus,
9089 focus_follows_mouse,
90+ wake_monitors,
9191 mod_key,
9292 mod_key_nested,
9393 );
@@ -402,6 +402,49 @@ pub struct FocusFollowsMouse {
402402 pub max_scroll_amount: Option<Percent>,
403403 }
404404
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+
405448 #[derive(knuffel::Decode, Debug, PartialEq, Eq, Clone, Copy)]
406449 pub struct WarpMouseToFocus {
407450 #[knuffel(property, str)]
niri-config/src/lib.rsmodified+18 -3
@@ -50,7 +50,9 @@ pub use crate::binds::*;
5050 pub use crate::debug::Debug;
5151 pub use crate::error::{ConfigIncludeError, ConfigParseResult};
5252 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+};
5456 pub use crate::layer_rule::LayerRule;
5557 pub use crate::layout::*;
5658 pub use crate::misc::*;
@@ -1221,7 +1223,10 @@ mod tests {
12211223 }
12221224
12231225 disable-power-key-handling
1224- disable-monitor-wake
1226+ wake-monitors {
1227+ keyboard
1228+ pointer-button
1229+ }
12251230
12261231 warp-mouse-to-focus
12271232 focus-follows-mouse
@@ -1634,7 +1639,17 @@ mod tests {
16341639 ),
16351640 },
16361641 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+ ),
16381653 warp_mouse_to_focus: Some(
16391654 WarpMouseToFocus {
16401655 mode: None,
src/input/mod.rsmodified+25 -17
@@ -8,7 +8,7 @@ use calloop::RegistrationToken;
88 use input::event::gesture::GestureEventCoordinates as _;
99 use niri_config::{
1010 Action, Bind, Binds, BoundAction, Config, Key, ModKey, Modifiers, MruDirection, SwitchBinds,
11- Trigger,
11+ Trigger, WakeSource,
1212 };
1313 use niri_ipc::LayoutSwitchTarget;
1414 use smithay::backend::input::{
@@ -164,9 +164,13 @@ impl State {
164164 }
165165 } else {
166166 // 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 {
170174 self.niri.activate_monitors(&mut self.backend);
171175
172176 // 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 {
50875091 modifiers
50885092 }
50895093
5090-fn should_activate_monitors<I: InputBackend>(event: &InputEvent<I>) -> bool {
5094+fn wake_source<I: InputBackend>(event: &InputEvent<I>) -> Option<WakeSource> {
50915095 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 { .. }
50985107 | 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 { .. }
51035111 | InputEvent::TabletToolProximity { .. }
51045112 | InputEvent::TabletToolTip { .. }
5105- | InputEvent::TabletToolButton { .. } => true,
5113+ | InputEvent::TabletToolButton { .. } => Some(WakeSource::Tablet),
51065114 // Ignore events like device additions and removals, key releases, gesture ends.
5107- _ => false,
5115+ _ => None,
51085116 }
51095117 }
51105118