From 577fba82e540d549ac2f2441a638e1d23d1f100d Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 9 Feb 2024 16:16:18 +0400 Subject: input: Split bound_action() and add tests --- src/input.rs | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/src/input.rs b/src/input.rs index 30d8e100..77424d35 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1421,6 +1421,15 @@ fn action( _ => (), } + bound_action(bindings, comp_mod, raw, mods) +} + +fn bound_action( + bindings: &Binds, + comp_mod: CompositorMod, + raw: Option, + mods: ModifiersState, +) -> Option { // Handle configured binds. let mut modifiers = Modifiers::empty(); if mods.ctrl { @@ -1720,4 +1729,159 @@ mod tests { // Ensure that no keys are being suppressed. assert!(suppressed_keys.is_empty()); } + + #[test] + fn comp_mod_handling() { + let bindings = Binds(vec![ + Bind { + key: Key { + keysym: Keysym::q, + modifiers: Modifiers::COMPOSITOR, + }, + actions: vec![Action::CloseWindow], + }, + Bind { + key: Key { + keysym: Keysym::h, + modifiers: Modifiers::SUPER, + }, + actions: vec![Action::FocusColumnLeft], + }, + Bind { + key: Key { + keysym: Keysym::j, + modifiers: Modifiers::empty(), + }, + actions: vec![Action::FocusWindowDown], + }, + Bind { + key: Key { + keysym: Keysym::k, + modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER, + }, + actions: vec![Action::FocusWindowUp], + }, + Bind { + key: Key { + keysym: Keysym::l, + modifiers: Modifiers::SUPER | Modifiers::ALT, + }, + actions: vec![Action::FocusColumnRight], + }, + ]); + + assert_eq!( + bound_action( + &bindings, + CompositorMod::Super, + Some(Keysym::q), + ModifiersState { + logo: true, + ..Default::default() + } + ), + Some(Action::CloseWindow) + ); + assert_eq!( + bound_action( + &bindings, + CompositorMod::Super, + Some(Keysym::q), + ModifiersState::default(), + ), + None, + ); + + // assert_eq!( + // bound_action( + // &bindings, + // CompositorMod::Super, + // Some(Keysym::h), + // ModifiersState { + // logo: true, + // ..Default::default() + // } + // ), + // Some(Action::FocusColumnLeft) + // ); + assert_eq!( + bound_action( + &bindings, + CompositorMod::Super, + Some(Keysym::h), + ModifiersState::default(), + ), + None, + ); + + assert_eq!( + bound_action( + &bindings, + CompositorMod::Super, + Some(Keysym::j), + ModifiersState { + logo: true, + ..Default::default() + } + ), + None, + ); + assert_eq!( + bound_action( + &bindings, + CompositorMod::Super, + Some(Keysym::j), + ModifiersState::default(), + ), + Some(Action::FocusWindowDown) + ); + + assert_eq!( + bound_action( + &bindings, + CompositorMod::Super, + Some(Keysym::k), + ModifiersState { + logo: true, + ..Default::default() + } + ), + Some(Action::FocusWindowUp) + ); + assert_eq!( + bound_action( + &bindings, + CompositorMod::Super, + Some(Keysym::k), + ModifiersState::default(), + ), + None, + ); + + // assert_eq!( + // bound_action( + // &bindings, + // CompositorMod::Super, + // Some(Keysym::l), + // ModifiersState { + // logo: true, + // alt: true, + // ..Default::default() + // } + // ), + // Some(Action::FocusColumnRight) + // ); + assert_eq!( + bound_action( + &bindings, + CompositorMod::Super, + Some(Keysym::l), + ModifiersState { + logo: true, + ..Default::default() + }, + ), + None, + ); + } } -- cgit