forge
Explore
Log in

Don't you dare go Hollow

Extract allowed action checks

Browse files at this commit

4fefab7d6b8298cfcd1a022b9c1ceeb039ca8e63Ivan MolodetskikhParent: 675932c
src/input.rsmodified+34 -20
@@ -219,16 +219,7 @@ impl State {
219219 return;
220220 }
221221
222- if self.niri.is_locked()
223- && !matches!(
224- action,
225- Action::Quit
226- | Action::ChangeVt(_)
227- | Action::Suspend
228- | Action::PowerOffMonitors
229- | Action::SwitchLayout(_)
230- )
231- {
222+ if self.niri.is_locked() && !allowed_when_locked(&action) {
232223 return;
233224 }
234225
@@ -1073,16 +1064,21 @@ fn should_intercept_key(
10731064 }
10741065
10751066 let mut final_action = action(bindings, comp_mod, modified, raw, mods);
1076- if screenshot_ui.is_open()
1077- // Allow only a subset of compositor actions while the screenshot UI is open,
1078- // since the user cannot see the screen.
1079- && !matches!(
1080- final_action,
1081- Some(Action::Quit | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors)
1082- )
1083- {
1084- // Otherwise, use the screenshot UI action.
1085- final_action = screenshot_ui.action(raw, mods);
1067+
1068+ // Allow only a subset of compositor actions while the screenshot UI is open, since the user
1069+ // cannot see the screen.
1070+ if screenshot_ui.is_open() {
1071+ let mut use_screenshot_ui_action = true;
1072+
1073+ if let Some(action) = &final_action {
1074+ if allowed_during_screenshot(action) {
1075+ use_screenshot_ui_action = false;
1076+ }
1077+ }
1078+
1079+ if use_screenshot_ui_action {
1080+ final_action = screenshot_ui.action(raw, mods);
1081+ }
10861082 }
10871083
10881084 match (final_action, pressed) {
@@ -1181,6 +1177,24 @@ fn should_activate_monitors<I: InputBackend>(event: &InputEvent<I>) -> bool {
11811177 }
11821178 }
11831179
1180+fn allowed_when_locked(action: &Action) -> bool {
1181+ matches!(
1182+ action,
1183+ Action::Quit
1184+ | Action::ChangeVt(_)
1185+ | Action::Suspend
1186+ | Action::PowerOffMonitors
1187+ | Action::SwitchLayout(_)
1188+ )
1189+}
1190+
1191+fn allowed_during_screenshot(action: &Action) -> bool {
1192+ matches!(
1193+ action,
1194+ Action::Quit | Action::ChangeVt(_) | Action::Suspend | Action::PowerOffMonitors
1195+ )
1196+}
1197+
11841198 #[cfg(test)]
11851199 mod tests {
11861200 use super::*;