input: Remove bindings_suppress_keys() test
Browse files at this commite3c52255f226a666ec85cbef21bd7a3e18433891Parent: 027256c1 changed file +0 -189
- src/input/mod.rs +0 -189
src/input/mod.rsmodified+0 -189
| @@ -5317,196 +5317,7 @@ fn make_binds_iter<'a>( | |||
| 5317 | 5317 | ||
| 5318 | #[cfg(test)] | 5318 | #[cfg(test)] |
| 5319 | mod tests { | 5319 | mod tests { |
| 5320 | - use std::cell::Cell; | ||
| 5321 | - | ||
| 5322 | use super::*; | 5320 | use super::*; |
| 5323 | - use crate::animation::Clock; | ||
| 5324 | - | ||
| 5325 | - #[test] | ||
| 5326 | - fn bindings_suppress_keys() { | ||
| 5327 | - let close_keysym = Keysym::q; | ||
| 5328 | - let bindings = Binds(vec![Bind { | ||
| 5329 | - key: Key { | ||
| 5330 | - trigger: Trigger::Keysym(close_keysym), | ||
| 5331 | - modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL, | ||
| 5332 | - }, | ||
| 5333 | - action: Action::CloseWindow, | ||
| 5334 | - repeat: true, | ||
| 5335 | - cooldown: None, | ||
| 5336 | - allow_when_locked: false, | ||
| 5337 | - allow_inhibiting: true, | ||
| 5338 | - hotkey_overlay_title: None, | ||
| 5339 | - }]); | ||
| 5340 | - | ||
| 5341 | - let comp_mod = ModKey::Super; | ||
| 5342 | - let mut suppressed_keys = HashSet::new(); | ||
| 5343 | - | ||
| 5344 | - let screenshot_ui = ScreenshotUi::new(Clock::default(), Default::default()); | ||
| 5345 | - let disable_power_key_handling = false; | ||
| 5346 | - let is_inhibiting_shortcuts = Cell::new(false); | ||
| 5347 | - | ||
| 5348 | - // The key_code we pick is arbitrary, the only thing | ||
| 5349 | - // that matters is that they are different between cases. | ||
| 5350 | - | ||
| 5351 | - let close_key_code = Keycode::from(close_keysym.raw() + 8u32); | ||
| 5352 | - let close_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| { | ||
| 5353 | - should_intercept_key( | ||
| 5354 | - suppr, | ||
| 5355 | - &bindings.0, | ||
| 5356 | - comp_mod, | ||
| 5357 | - close_key_code, | ||
| 5358 | - close_keysym, | ||
| 5359 | - Some(close_keysym), | ||
| 5360 | - pressed, | ||
| 5361 | - mods, | ||
| 5362 | - &screenshot_ui, | ||
| 5363 | - disable_power_key_handling, | ||
| 5364 | - is_inhibiting_shortcuts.get(), | ||
| 5365 | - ) | ||
| 5366 | - }; | ||
| 5367 | - | ||
| 5368 | - // Key event with the code which can't trigger any action. | ||
| 5369 | - let none_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| { | ||
| 5370 | - should_intercept_key( | ||
| 5371 | - suppr, | ||
| 5372 | - &bindings.0, | ||
| 5373 | - comp_mod, | ||
| 5374 | - Keycode::from(Keysym::l.raw() + 8), | ||
| 5375 | - Keysym::l, | ||
| 5376 | - Some(Keysym::l), | ||
| 5377 | - pressed, | ||
| 5378 | - mods, | ||
| 5379 | - &screenshot_ui, | ||
| 5380 | - disable_power_key_handling, | ||
| 5381 | - is_inhibiting_shortcuts.get(), | ||
| 5382 | - ) | ||
| 5383 | - }; | ||
| 5384 | - | ||
| 5385 | - let mut mods = ModifiersState { | ||
| 5386 | - logo: true, | ||
| 5387 | - ctrl: true, | ||
| 5388 | - ..Default::default() | ||
| 5389 | - }; | ||
| 5390 | - | ||
| 5391 | - // Action press/release. | ||
| 5392 | - | ||
| 5393 | - let filter = close_key_event(&mut suppressed_keys, mods, true); | ||
| 5394 | - assert!(matches!( | ||
| 5395 | - filter, | ||
| 5396 | - FilterResult::Intercept(Some(Bind { | ||
| 5397 | - action: Action::CloseWindow, | ||
| 5398 | - .. | ||
| 5399 | - })) | ||
| 5400 | - )); | ||
| 5401 | - assert!(suppressed_keys.contains(&close_key_code)); | ||
| 5402 | - | ||
| 5403 | - let filter = close_key_event(&mut suppressed_keys, mods, false); | ||
| 5404 | - assert!(matches!(filter, FilterResult::Intercept(None))); | ||
| 5405 | - assert!(suppressed_keys.is_empty()); | ||
| 5406 | - | ||
| 5407 | - // Remove mod to make it for a binding. | ||
| 5408 | - | ||
| 5409 | - mods.shift = true; | ||
| 5410 | - let filter = close_key_event(&mut suppressed_keys, mods, true); | ||
| 5411 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5412 | - | ||
| 5413 | - mods.shift = false; | ||
| 5414 | - let filter = close_key_event(&mut suppressed_keys, mods, false); | ||
| 5415 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5416 | - | ||
| 5417 | - // Just none press/release. | ||
| 5418 | - | ||
| 5419 | - let filter = none_key_event(&mut suppressed_keys, mods, true); | ||
| 5420 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5421 | - | ||
| 5422 | - let filter = none_key_event(&mut suppressed_keys, mods, false); | ||
| 5423 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5424 | - | ||
| 5425 | - // Press action, press arbitrary, release action, release arbitrary. | ||
| 5426 | - | ||
| 5427 | - let filter = close_key_event(&mut suppressed_keys, mods, true); | ||
| 5428 | - assert!(matches!( | ||
| 5429 | - filter, | ||
| 5430 | - FilterResult::Intercept(Some(Bind { | ||
| 5431 | - action: Action::CloseWindow, | ||
| 5432 | - .. | ||
| 5433 | - })) | ||
| 5434 | - )); | ||
| 5435 | - | ||
| 5436 | - let filter = none_key_event(&mut suppressed_keys, mods, true); | ||
| 5437 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5438 | - | ||
| 5439 | - let filter = close_key_event(&mut suppressed_keys, mods, false); | ||
| 5440 | - assert!(matches!(filter, FilterResult::Intercept(None))); | ||
| 5441 | - | ||
| 5442 | - let filter = none_key_event(&mut suppressed_keys, mods, false); | ||
| 5443 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5444 | - | ||
| 5445 | - // Trigger and remove all mods. | ||
| 5446 | - | ||
| 5447 | - let filter = close_key_event(&mut suppressed_keys, mods, true); | ||
| 5448 | - assert!(matches!( | ||
| 5449 | - filter, | ||
| 5450 | - FilterResult::Intercept(Some(Bind { | ||
| 5451 | - action: Action::CloseWindow, | ||
| 5452 | - .. | ||
| 5453 | - })) | ||
| 5454 | - )); | ||
| 5455 | - | ||
| 5456 | - mods = Default::default(); | ||
| 5457 | - let filter = close_key_event(&mut suppressed_keys, mods, false); | ||
| 5458 | - assert!(matches!(filter, FilterResult::Intercept(None))); | ||
| 5459 | - | ||
| 5460 | - // Ensure that no keys are being suppressed. | ||
| 5461 | - assert!(suppressed_keys.is_empty()); | ||
| 5462 | - | ||
| 5463 | - // Now test shortcut inhibiting. | ||
| 5464 | - | ||
| 5465 | - // With inhibited shortcuts, we don't intercept our shortcut. | ||
| 5466 | - is_inhibiting_shortcuts.set(true); | ||
| 5467 | - | ||
| 5468 | - mods = ModifiersState { | ||
| 5469 | - logo: true, | ||
| 5470 | - ctrl: true, | ||
| 5471 | - ..Default::default() | ||
| 5472 | - }; | ||
| 5473 | - | ||
| 5474 | - let filter = close_key_event(&mut suppressed_keys, mods, true); | ||
| 5475 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5476 | - assert!(suppressed_keys.is_empty()); | ||
| 5477 | - | ||
| 5478 | - let filter = close_key_event(&mut suppressed_keys, mods, false); | ||
| 5479 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5480 | - assert!(suppressed_keys.is_empty()); | ||
| 5481 | - | ||
| 5482 | - // Toggle it off after pressing the shortcut. | ||
| 5483 | - let filter = close_key_event(&mut suppressed_keys, mods, true); | ||
| 5484 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5485 | - assert!(suppressed_keys.is_empty()); | ||
| 5486 | - | ||
| 5487 | - is_inhibiting_shortcuts.set(false); | ||
| 5488 | - | ||
| 5489 | - let filter = close_key_event(&mut suppressed_keys, mods, false); | ||
| 5490 | - assert!(matches!(filter, FilterResult::Forward)); | ||
| 5491 | - assert!(suppressed_keys.is_empty()); | ||
| 5492 | - | ||
| 5493 | - // Toggle it on after pressing the shortcut. | ||
| 5494 | - let filter = close_key_event(&mut suppressed_keys, mods, true); | ||
| 5495 | - assert!(matches!( | ||
| 5496 | - filter, | ||
| 5497 | - FilterResult::Intercept(Some(Bind { | ||
| 5498 | - action: Action::CloseWindow, | ||
| 5499 | - .. | ||
| 5500 | - })) | ||
| 5501 | - )); | ||
| 5502 | - assert!(suppressed_keys.contains(&close_key_code)); | ||
| 5503 | - | ||
| 5504 | - is_inhibiting_shortcuts.set(true); | ||
| 5505 | - | ||
| 5506 | - let filter = close_key_event(&mut suppressed_keys, mods, false); | ||
| 5507 | - assert!(matches!(filter, FilterResult::Intercept(None))); | ||
| 5508 | - assert!(suppressed_keys.is_empty()); | ||
| 5509 | - } | ||
| 5510 | 5321 | ||
| 5511 | #[test] | 5322 | #[test] |
| 5512 | fn comp_mod_handling() { | 5323 | fn comp_mod_handling() { |