Extract allowed action checks
Browse files at this commit4fefab7d6b8298cfcd1a022b9c1ceeb039ca8e63Parent: 675932c1 changed file +34 -20
- src/input.rs +34 -20
src/input.rsmodified+34 -20
| @@ -219,16 +219,7 @@ impl State { | ||
| 219 | 219 | return; |
| 220 | 220 | } |
| 221 | 221 | |
| 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) { | |
| 232 | 223 | return; |
| 233 | 224 | } |
| 234 | 225 | |
| @@ -1073,16 +1064,21 @@ fn should_intercept_key( | ||
| 1073 | 1064 | } |
| 1074 | 1065 | |
| 1075 | 1066 | 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 | + } | |
| 1086 | 1082 | } |
| 1087 | 1083 | |
| 1088 | 1084 | match (final_action, pressed) { |
| @@ -1181,6 +1177,24 @@ fn should_activate_monitors<I: InputBackend>(event: &InputEvent<I>) -> bool { | ||
| 1181 | 1177 | } |
| 1182 | 1178 | } |
| 1183 | 1179 | |
| 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 | + | |
| 1184 | 1198 | #[cfg(test)] |
| 1185 | 1199 | mod tests { |
| 1186 | 1200 | use super::*; |