aboutsummaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-12-09 09:43:26 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-12-09 09:43:26 +0400
commit4fefab7d6b8298cfcd1a022b9c1ceeb039ca8e63 (patch)
treebd8b3bca5f3574f1d728b0cc4899222f8cc73996 /src/input.rs
parent675932c05b6c9a99c7d7403f66b2d31b0fd99933 (diff)
downloadniri-4fefab7d6b8298cfcd1a022b9c1ceeb039ca8e63.tar.gz
niri-4fefab7d6b8298cfcd1a022b9c1ceeb039ca8e63.tar.bz2
niri-4fefab7d6b8298cfcd1a022b9c1ceeb039ca8e63.zip
Extract allowed action checks
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/input.rs b/src/input.rs
index 08cb5f46..6532f4a5 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -219,16 +219,7 @@ impl State {
return;
}
- if self.niri.is_locked()
- && !matches!(
- action,
- Action::Quit
- | Action::ChangeVt(_)
- | Action::Suspend
- | Action::PowerOffMonitors
- | Action::SwitchLayout(_)
- )
- {
+ if self.niri.is_locked() && !allowed_when_locked(&action) {
return;
}
@@ -1073,16 +1064,21 @@ fn should_intercept_key(
}
let mut final_action = action(bindings, comp_mod, modified, raw, mods);
- if screenshot_ui.is_open()
- // Allow only a subset of compositor actions while the screenshot UI is open,
- // since the user cannot see the screen.
- && !matches!(
- final_action,
- Some(Action::Quit | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors)
- )
- {
- // Otherwise, use the screenshot UI action.
- final_action = screenshot_ui.action(raw, mods);
+
+ // Allow only a subset of compositor actions while the screenshot UI is open, since the user
+ // cannot see the screen.
+ if screenshot_ui.is_open() {
+ let mut use_screenshot_ui_action = true;
+
+ if let Some(action) = &final_action {
+ if allowed_during_screenshot(action) {
+ use_screenshot_ui_action = false;
+ }
+ }
+
+ if use_screenshot_ui_action {
+ final_action = screenshot_ui.action(raw, mods);
+ }
}
match (final_action, pressed) {
@@ -1181,6 +1177,24 @@ fn should_activate_monitors<I: InputBackend>(event: &InputEvent<I>) -> bool {
}
}
+fn allowed_when_locked(action: &Action) -> bool {
+ matches!(
+ action,
+ Action::Quit
+ | Action::ChangeVt(_)
+ | Action::Suspend
+ | Action::PowerOffMonitors
+ | Action::SwitchLayout(_)
+ )
+}
+
+fn allowed_during_screenshot(action: &Action) -> bool {
+ matches!(
+ action,
+ Action::Quit | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors
+ )
+}
+
#[cfg(test)]
mod tests {
use super::*;