input: Pass bindings list as iterator
Browse files at this commit661fcd42ad284bf4cf68581ae0979fe04b0f2838Parent: 9a234261 changed file +25 -25
- src/input/mod.rs +25 -25
src/input/mod.rsmodified+25 -25
| @@ -419,7 +419,7 @@ impl State { | |||
| 419 | let bindings = &this.niri.config.borrow().binds; | 419 | let bindings = &this.niri.config.borrow().binds; |
| 420 | let res = should_intercept_key( | 420 | let res = should_intercept_key( |
| 421 | &mut this.niri.suppressed_keys, | 421 | &mut this.niri.suppressed_keys, |
| 422 | - bindings, | 422 | + &bindings.0, |
| 423 | mod_key, | 423 | mod_key, |
| 424 | key_code, | 424 | key_code, |
| 425 | modified, | 425 | modified, |
| @@ -2520,7 +2520,7 @@ impl State { | |||
| 2520 | } | 2520 | } |
| 2521 | .and_then(|trigger| { | 2521 | .and_then(|trigger| { |
| 2522 | let config = self.niri.config.borrow(); | 2522 | let config = self.niri.config.borrow(); |
| 2523 | - let bindings = &config.binds; | 2523 | + let bindings = &config.binds.0; |
| 2524 | find_configured_bind(bindings, mod_key, trigger, mods) | 2524 | find_configured_bind(bindings, mod_key, trigger, mods) |
| 2525 | }) { | 2525 | }) { |
| 2526 | self.niri.suppressed_buttons.insert(button_code); | 2526 | self.niri.suppressed_buttons.insert(button_code); |
| @@ -2866,7 +2866,7 @@ impl State { | |||
| 2866 | (bind_left, bind_right) | 2866 | (bind_left, bind_right) |
| 2867 | } else { | 2867 | } else { |
| 2868 | let config = self.niri.config.borrow(); | 2868 | let config = self.niri.config.borrow(); |
| 2869 | - let bindings = &config.binds; | 2869 | + let bindings = &config.binds.0; |
| 2870 | let bind_left = | 2870 | let bind_left = |
| 2871 | find_configured_bind(bindings, mod_key, Trigger::WheelScrollLeft, mods); | 2871 | find_configured_bind(bindings, mod_key, Trigger::WheelScrollLeft, mods); |
| 2872 | let bind_right = find_configured_bind( | 2872 | let bind_right = find_configured_bind( |
| @@ -2948,7 +2948,7 @@ impl State { | |||
| 2948 | (bind_up, bind_down) | 2948 | (bind_up, bind_down) |
| 2949 | } else { | 2949 | } else { |
| 2950 | let config = self.niri.config.borrow(); | 2950 | let config = self.niri.config.borrow(); |
| 2951 | - let bindings = &config.binds; | 2951 | + let bindings = &config.binds.0; |
| 2952 | let bind_up = | 2952 | let bind_up = |
| 2953 | find_configured_bind(bindings, mod_key, Trigger::WheelScrollUp, mods); | 2953 | find_configured_bind(bindings, mod_key, Trigger::WheelScrollUp, mods); |
| 2954 | let bind_down = | 2954 | let bind_down = |
| @@ -3088,7 +3088,7 @@ impl State { | |||
| 3088 | .accumulate(horizontal); | 3088 | .accumulate(horizontal); |
| 3089 | if ticks != 0 { | 3089 | if ticks != 0 { |
| 3090 | let config = self.niri.config.borrow(); | 3090 | let config = self.niri.config.borrow(); |
| 3091 | - let bindings = &config.binds; | 3091 | + let bindings = &config.binds.0; |
| 3092 | let bind_left = | 3092 | let bind_left = |
| 3093 | find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollLeft, mods); | 3093 | find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollLeft, mods); |
| 3094 | let bind_right = | 3094 | let bind_right = |
| @@ -3113,7 +3113,7 @@ impl State { | |||
| 3113 | .accumulate(vertical); | 3113 | .accumulate(vertical); |
| 3114 | if ticks != 0 { | 3114 | if ticks != 0 { |
| 3115 | let config = self.niri.config.borrow(); | 3115 | let config = self.niri.config.borrow(); |
| 3116 | - let bindings = &config.binds; | 3116 | + let bindings = &config.binds.0; |
| 3117 | let bind_up = | 3117 | let bind_up = |
| 3118 | find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollUp, mods); | 3118 | find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollUp, mods); |
| 3119 | let bind_down = | 3119 | let bind_down = |
| @@ -3971,9 +3971,9 @@ impl State { | |||
| 3971 | /// pressed keys as `suppressed`, thus preventing `releases` corresponding | 3971 | /// pressed keys as `suppressed`, thus preventing `releases` corresponding |
| 3972 | /// to them from being delivered. | 3972 | /// to them from being delivered. |
| 3973 | #[allow(clippy::too_many_arguments)] | 3973 | #[allow(clippy::too_many_arguments)] |
| 3974 | -fn should_intercept_key( | 3974 | +fn should_intercept_key<'a>( |
| 3975 | suppressed_keys: &mut HashSet<Keycode>, | 3975 | suppressed_keys: &mut HashSet<Keycode>, |
| 3976 | - bindings: &Binds, | 3976 | + bindings: impl IntoIterator<Item = &'a Bind>, |
| 3977 | mod_key: ModKey, | 3977 | mod_key: ModKey, |
| 3978 | key_code: Keycode, | 3978 | key_code: Keycode, |
| 3979 | modified: Keysym, | 3979 | modified: Keysym, |
| @@ -4055,8 +4055,8 @@ fn should_intercept_key( | |||
| 4055 | } | 4055 | } |
| 4056 | } | 4056 | } |
| 4057 | 4057 | ||
| 4058 | -fn find_bind( | 4058 | +fn find_bind<'a>( |
| 4059 | - bindings: &Binds, | 4059 | + bindings: impl IntoIterator<Item = &'a Bind>, |
| 4060 | mod_key: ModKey, | 4060 | mod_key: ModKey, |
| 4061 | modified: Keysym, | 4061 | modified: Keysym, |
| 4062 | raw: Option<Keysym>, | 4062 | raw: Option<Keysym>, |
| @@ -4101,8 +4101,8 @@ fn find_bind( | |||
| 4101 | find_configured_bind(bindings, mod_key, trigger, mods) | 4101 | find_configured_bind(bindings, mod_key, trigger, mods) |
| 4102 | } | 4102 | } |
| 4103 | 4103 | ||
| 4104 | -fn find_configured_bind( | 4104 | +fn find_configured_bind<'a>( |
| 4105 | - bindings: &Binds, | 4105 | + bindings: impl IntoIterator<Item = &'a Bind>, |
| 4106 | mod_key: ModKey, | 4106 | mod_key: ModKey, |
| 4107 | trigger: Trigger, | 4107 | trigger: Trigger, |
| 4108 | mods: ModifiersState, | 4108 | mods: ModifiersState, |
| @@ -4115,7 +4115,7 @@ fn find_configured_bind( | |||
| 4115 | modifiers |= Modifiers::COMPOSITOR; | 4115 | modifiers |= Modifiers::COMPOSITOR; |
| 4116 | } | 4116 | } |
| 4117 | 4117 | ||
| 4118 | - for bind in &bindings.0 { | 4118 | + for bind in bindings { |
| 4119 | if bind.key.trigger != trigger { | 4119 | if bind.key.trigger != trigger { |
| 4120 | continue; | 4120 | continue; |
| 4121 | } | 4121 | } |
| @@ -4733,7 +4733,7 @@ mod tests { | |||
| 4733 | let close_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| { | 4733 | let close_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| { |
| 4734 | should_intercept_key( | 4734 | should_intercept_key( |
| 4735 | suppr, | 4735 | suppr, |
| 4736 | - &bindings, | 4736 | + &bindings.0, |
| 4737 | comp_mod, | 4737 | comp_mod, |
| 4738 | close_key_code, | 4738 | close_key_code, |
| 4739 | close_keysym, | 4739 | close_keysym, |
| @@ -4750,7 +4750,7 @@ mod tests { | |||
| 4750 | let none_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| { | 4750 | let none_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| { |
| 4751 | should_intercept_key( | 4751 | should_intercept_key( |
| 4752 | suppr, | 4752 | suppr, |
| 4753 | - &bindings, | 4753 | + &bindings.0, |
| 4754 | comp_mod, | 4754 | comp_mod, |
| 4755 | Keycode::from(Keysym::l.raw() + 8), | 4755 | Keycode::from(Keysym::l.raw() + 8), |
| 4756 | Keysym::l, | 4756 | Keysym::l, |
| @@ -4956,7 +4956,7 @@ mod tests { | |||
| 4956 | 4956 | ||
| 4957 | assert_eq!( | 4957 | assert_eq!( |
| 4958 | find_configured_bind( | 4958 | find_configured_bind( |
| 4959 | - &bindings, | 4959 | + &bindings.0, |
| 4960 | ModKey::Super, | 4960 | ModKey::Super, |
| 4961 | Trigger::Keysym(Keysym::q), | 4961 | Trigger::Keysym(Keysym::q), |
| 4962 | ModifiersState { | 4962 | ModifiersState { |
| @@ -4969,7 +4969,7 @@ mod tests { | |||
| 4969 | ); | 4969 | ); |
| 4970 | assert_eq!( | 4970 | assert_eq!( |
| 4971 | find_configured_bind( | 4971 | find_configured_bind( |
| 4972 | - &bindings, | 4972 | + &bindings.0, |
| 4973 | ModKey::Super, | 4973 | ModKey::Super, |
| 4974 | Trigger::Keysym(Keysym::q), | 4974 | Trigger::Keysym(Keysym::q), |
| 4975 | ModifiersState::default(), | 4975 | ModifiersState::default(), |
| @@ -4979,7 +4979,7 @@ mod tests { | |||
| 4979 | 4979 | ||
| 4980 | assert_eq!( | 4980 | assert_eq!( |
| 4981 | find_configured_bind( | 4981 | find_configured_bind( |
| 4982 | - &bindings, | 4982 | + &bindings.0, |
| 4983 | ModKey::Super, | 4983 | ModKey::Super, |
| 4984 | Trigger::Keysym(Keysym::h), | 4984 | Trigger::Keysym(Keysym::h), |
| 4985 | ModifiersState { | 4985 | ModifiersState { |
| @@ -4992,7 +4992,7 @@ mod tests { | |||
| 4992 | ); | 4992 | ); |
| 4993 | assert_eq!( | 4993 | assert_eq!( |
| 4994 | find_configured_bind( | 4994 | find_configured_bind( |
| 4995 | - &bindings, | 4995 | + &bindings.0, |
| 4996 | ModKey::Super, | 4996 | ModKey::Super, |
| 4997 | Trigger::Keysym(Keysym::h), | 4997 | Trigger::Keysym(Keysym::h), |
| 4998 | ModifiersState::default(), | 4998 | ModifiersState::default(), |
| @@ -5002,7 +5002,7 @@ mod tests { | |||
| 5002 | 5002 | ||
| 5003 | assert_eq!( | 5003 | assert_eq!( |
| 5004 | find_configured_bind( | 5004 | find_configured_bind( |
| 5005 | - &bindings, | 5005 | + &bindings.0, |
| 5006 | ModKey::Super, | 5006 | ModKey::Super, |
| 5007 | Trigger::Keysym(Keysym::j), | 5007 | Trigger::Keysym(Keysym::j), |
| 5008 | ModifiersState { | 5008 | ModifiersState { |
| @@ -5014,7 +5014,7 @@ mod tests { | |||
| 5014 | ); | 5014 | ); |
| 5015 | assert_eq!( | 5015 | assert_eq!( |
| 5016 | find_configured_bind( | 5016 | find_configured_bind( |
| 5017 | - &bindings, | 5017 | + &bindings.0, |
| 5018 | ModKey::Super, | 5018 | ModKey::Super, |
| 5019 | Trigger::Keysym(Keysym::j), | 5019 | Trigger::Keysym(Keysym::j), |
| 5020 | ModifiersState::default(), | 5020 | ModifiersState::default(), |
| @@ -5025,7 +5025,7 @@ mod tests { | |||
| 5025 | 5025 | ||
| 5026 | assert_eq!( | 5026 | assert_eq!( |
| 5027 | find_configured_bind( | 5027 | find_configured_bind( |
| 5028 | - &bindings, | 5028 | + &bindings.0, |
| 5029 | ModKey::Super, | 5029 | ModKey::Super, |
| 5030 | Trigger::Keysym(Keysym::k), | 5030 | Trigger::Keysym(Keysym::k), |
| 5031 | ModifiersState { | 5031 | ModifiersState { |
| @@ -5038,7 +5038,7 @@ mod tests { | |||
| 5038 | ); | 5038 | ); |
| 5039 | assert_eq!( | 5039 | assert_eq!( |
| 5040 | find_configured_bind( | 5040 | find_configured_bind( |
| 5041 | - &bindings, | 5041 | + &bindings.0, |
| 5042 | ModKey::Super, | 5042 | ModKey::Super, |
| 5043 | Trigger::Keysym(Keysym::k), | 5043 | Trigger::Keysym(Keysym::k), |
| 5044 | ModifiersState::default(), | 5044 | ModifiersState::default(), |
| @@ -5048,7 +5048,7 @@ mod tests { | |||
| 5048 | 5048 | ||
| 5049 | assert_eq!( | 5049 | assert_eq!( |
| 5050 | find_configured_bind( | 5050 | find_configured_bind( |
| 5051 | - &bindings, | 5051 | + &bindings.0, |
| 5052 | ModKey::Super, | 5052 | ModKey::Super, |
| 5053 | Trigger::Keysym(Keysym::l), | 5053 | Trigger::Keysym(Keysym::l), |
| 5054 | ModifiersState { | 5054 | ModifiersState { |
| @@ -5062,7 +5062,7 @@ mod tests { | |||
| 5062 | ); | 5062 | ); |
| 5063 | assert_eq!( | 5063 | assert_eq!( |
| 5064 | find_configured_bind( | 5064 | find_configured_bind( |
| 5065 | - &bindings, | 5065 | + &bindings.0, |
| 5066 | ModKey::Super, | 5066 | ModKey::Super, |
| 5067 | Trigger::Keysym(Keysym::l), | 5067 | Trigger::Keysym(Keysym::l), |
| 5068 | ModifiersState { | 5068 | ModifiersState { |