diff --git a/docs/wiki/Configuration:-Input.md b/docs/wiki/Configuration:-Input.md
index 2e0c877a..f5620df7 100644
--- a/docs/wiki/Configuration:-Input.md
+++ b/docs/wiki/Configuration:-Input.md
@@ -103,7 +103,7 @@ input {
}
// disable-power-key-handling
- // wake-monitors-on-input false
+ // wake-monitors {}
// warp-mouse-to-focus
// focus-follows-mouse max-scroll-amount="0%"
// workspace-auto-back-and-forth
@@ -315,20 +315,48 @@ input {
}
```
-#### `wake-monitors-on-input`
+#### `wake-monitors`
-By default, any input (a key press, mouse movement, etc.) powers the monitors back on after the `power-off-monitors` action.
-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`.
+Since: next release
-Binds keep working while the monitors are off, and input still reaches the focused window.
+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 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 {
- wake-monitors-on-input false
+ wake-monitors {}
}
binds {
- Mod+Ctrl+M { power-on-monitors; }
+ Mod+Shift+P { power-off-monitors; }
+ Mod+Shift+O { power-on-monitors; }
}
```
diff --git a/niri-config/src/input.rs b/niri-config/src/input.rs
index 89d95bb1..8e10a683 100644
--- a/niri-config/src/input.rs
+++ b/niri-config/src/input.rs
@@ -14,7 +14,7 @@ use crate::binds::Modifiers;
use crate::utils::{expand_home_path, Flag, MergeWith, Percent};
use crate::{FloatOrInt, Includes};
-#[derive(Debug, PartialEq)]
+#[derive(Debug, Default, PartialEq)]
pub struct Input {
pub keyboard: Keyboard,
pub touchpad: Touchpad,
@@ -24,7 +24,7 @@ pub struct Input {
pub tablet: Tablet,
pub touch: Touch,
pub disable_power_key_handling: bool,
- pub wake_monitors_on_input: bool,
+ pub wake_monitors: Option,
pub warp_mouse_to_focus: Option,
pub focus_follows_mouse: Option,
pub workspace_auto_back_and_forth: bool,
@@ -32,27 +32,6 @@ pub struct Input {
pub mod_key_nested: Option,
}
-impl Default for Input {
- fn default() -> Self {
- Self {
- keyboard: Default::default(),
- touchpad: Default::default(),
- mouse: Default::default(),
- trackpoint: Default::default(),
- trackball: Default::default(),
- tablet: Default::default(),
- touch: Default::default(),
- disable_power_key_handling: false,
- wake_monitors_on_input: true,
- warp_mouse_to_focus: None,
- focus_follows_mouse: None,
- workspace_auto_back_and_forth: false,
- mod_key: None,
- mod_key_nested: None,
- }
- }
-}
-
#[derive(knuffel::Decode, Debug, Default, PartialEq)]
pub struct InputPart {
#[knuffel(child)]
@@ -71,8 +50,8 @@ pub struct InputPart {
pub touch: Option,
#[knuffel(child)]
pub disable_power_key_handling: Option,
- #[knuffel(child, unwrap(argument))]
- pub wake_monitors_on_input: Option,
+ #[knuffel(child)]
+ pub wake_monitors: Option,
#[knuffel(child)]
pub warp_mouse_to_focus: Option,
#[knuffel(child)]
@@ -94,10 +73,6 @@ impl MergeWith for Input {
workspace_auto_back_and_forth,
);
- if let Some(x) = part.wake_monitors_on_input {
- self.wake_monitors_on_input = x;
- }
-
merge_clone!(
(self, part),
touchpad,
@@ -112,6 +87,7 @@ impl MergeWith for Input {
(self, part),
warp_mouse_to_focus,
focus_follows_mouse,
+ wake_monitors,
mod_key,
mod_key_nested,
);
@@ -428,6 +404,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 f573d9d3..c8a885b0 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
- wake-monitors-on-input false
+ wake-monitors {
+ keyboard
+ pointer-button
+ }
warp-mouse-to-focus
focus-follows-mouse
@@ -1634,7 +1639,17 @@ mod tests {
),
},
disable_power_key_handling: true,
- wake_monitors_on_input: false,
+ 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 0199ef9c..e1e0fc3c 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, MruFilter,
- MruScope, SwitchBinds, Trigger, WorkspaceReference,
+ MruScope, SwitchBinds, Trigger, WakeSource, WorkspaceReference,
};
use niri_ipc::LayoutSwitchTarget;
use smithay::backend::input::{
@@ -188,11 +188,14 @@ impl State {
self.niri.notify_activity();
}
} else {
- // Power on monitors if they were off, unless the config leaves that to the
- // power-on-monitors action.
- if self.niri.config.borrow().input.wake_monitors_on_input
- && should_activate_monitors(&event)
- {
+ // Power on monitors if they were off.
+ 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
@@ -5419,24 +5422,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,
}
}