mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
input: Pass bindings list as iterator
Allows generating it dynamically.
This commit is contained in:
+25
-25
@@ -419,7 +419,7 @@ impl State {
|
|||||||
let bindings = &this.niri.config.borrow().binds;
|
let bindings = &this.niri.config.borrow().binds;
|
||||||
let res = should_intercept_key(
|
let res = should_intercept_key(
|
||||||
&mut this.niri.suppressed_keys,
|
&mut this.niri.suppressed_keys,
|
||||||
bindings,
|
&bindings.0,
|
||||||
mod_key,
|
mod_key,
|
||||||
key_code,
|
key_code,
|
||||||
modified,
|
modified,
|
||||||
@@ -2520,7 +2520,7 @@ impl State {
|
|||||||
}
|
}
|
||||||
.and_then(|trigger| {
|
.and_then(|trigger| {
|
||||||
let config = self.niri.config.borrow();
|
let config = self.niri.config.borrow();
|
||||||
let bindings = &config.binds;
|
let bindings = &config.binds.0;
|
||||||
find_configured_bind(bindings, mod_key, trigger, mods)
|
find_configured_bind(bindings, mod_key, trigger, mods)
|
||||||
}) {
|
}) {
|
||||||
self.niri.suppressed_buttons.insert(button_code);
|
self.niri.suppressed_buttons.insert(button_code);
|
||||||
@@ -2866,7 +2866,7 @@ impl State {
|
|||||||
(bind_left, bind_right)
|
(bind_left, bind_right)
|
||||||
} else {
|
} else {
|
||||||
let config = self.niri.config.borrow();
|
let config = self.niri.config.borrow();
|
||||||
let bindings = &config.binds;
|
let bindings = &config.binds.0;
|
||||||
let bind_left =
|
let bind_left =
|
||||||
find_configured_bind(bindings, mod_key, Trigger::WheelScrollLeft, mods);
|
find_configured_bind(bindings, mod_key, Trigger::WheelScrollLeft, mods);
|
||||||
let bind_right = find_configured_bind(
|
let bind_right = find_configured_bind(
|
||||||
@@ -2948,7 +2948,7 @@ impl State {
|
|||||||
(bind_up, bind_down)
|
(bind_up, bind_down)
|
||||||
} else {
|
} else {
|
||||||
let config = self.niri.config.borrow();
|
let config = self.niri.config.borrow();
|
||||||
let bindings = &config.binds;
|
let bindings = &config.binds.0;
|
||||||
let bind_up =
|
let bind_up =
|
||||||
find_configured_bind(bindings, mod_key, Trigger::WheelScrollUp, mods);
|
find_configured_bind(bindings, mod_key, Trigger::WheelScrollUp, mods);
|
||||||
let bind_down =
|
let bind_down =
|
||||||
@@ -3088,7 +3088,7 @@ impl State {
|
|||||||
.accumulate(horizontal);
|
.accumulate(horizontal);
|
||||||
if ticks != 0 {
|
if ticks != 0 {
|
||||||
let config = self.niri.config.borrow();
|
let config = self.niri.config.borrow();
|
||||||
let bindings = &config.binds;
|
let bindings = &config.binds.0;
|
||||||
let bind_left =
|
let bind_left =
|
||||||
find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollLeft, mods);
|
find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollLeft, mods);
|
||||||
let bind_right =
|
let bind_right =
|
||||||
@@ -3113,7 +3113,7 @@ impl State {
|
|||||||
.accumulate(vertical);
|
.accumulate(vertical);
|
||||||
if ticks != 0 {
|
if ticks != 0 {
|
||||||
let config = self.niri.config.borrow();
|
let config = self.niri.config.borrow();
|
||||||
let bindings = &config.binds;
|
let bindings = &config.binds.0;
|
||||||
let bind_up =
|
let bind_up =
|
||||||
find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollUp, mods);
|
find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollUp, mods);
|
||||||
let bind_down =
|
let bind_down =
|
||||||
@@ -3971,9 +3971,9 @@ impl State {
|
|||||||
/// pressed keys as `suppressed`, thus preventing `releases` corresponding
|
/// pressed keys as `suppressed`, thus preventing `releases` corresponding
|
||||||
/// to them from being delivered.
|
/// to them from being delivered.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn should_intercept_key(
|
fn should_intercept_key<'a>(
|
||||||
suppressed_keys: &mut HashSet<Keycode>,
|
suppressed_keys: &mut HashSet<Keycode>,
|
||||||
bindings: &Binds,
|
bindings: impl IntoIterator<Item = &'a Bind>,
|
||||||
mod_key: ModKey,
|
mod_key: ModKey,
|
||||||
key_code: Keycode,
|
key_code: Keycode,
|
||||||
modified: Keysym,
|
modified: Keysym,
|
||||||
@@ -4055,8 +4055,8 @@ fn should_intercept_key(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_bind(
|
fn find_bind<'a>(
|
||||||
bindings: &Binds,
|
bindings: impl IntoIterator<Item = &'a Bind>,
|
||||||
mod_key: ModKey,
|
mod_key: ModKey,
|
||||||
modified: Keysym,
|
modified: Keysym,
|
||||||
raw: Option<Keysym>,
|
raw: Option<Keysym>,
|
||||||
@@ -4101,8 +4101,8 @@ fn find_bind(
|
|||||||
find_configured_bind(bindings, mod_key, trigger, mods)
|
find_configured_bind(bindings, mod_key, trigger, mods)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_configured_bind(
|
fn find_configured_bind<'a>(
|
||||||
bindings: &Binds,
|
bindings: impl IntoIterator<Item = &'a Bind>,
|
||||||
mod_key: ModKey,
|
mod_key: ModKey,
|
||||||
trigger: Trigger,
|
trigger: Trigger,
|
||||||
mods: ModifiersState,
|
mods: ModifiersState,
|
||||||
@@ -4115,7 +4115,7 @@ fn find_configured_bind(
|
|||||||
modifiers |= Modifiers::COMPOSITOR;
|
modifiers |= Modifiers::COMPOSITOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for bind in &bindings.0 {
|
for bind in bindings {
|
||||||
if bind.key.trigger != trigger {
|
if bind.key.trigger != trigger {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -4733,7 +4733,7 @@ mod tests {
|
|||||||
let close_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| {
|
let close_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| {
|
||||||
should_intercept_key(
|
should_intercept_key(
|
||||||
suppr,
|
suppr,
|
||||||
&bindings,
|
&bindings.0,
|
||||||
comp_mod,
|
comp_mod,
|
||||||
close_key_code,
|
close_key_code,
|
||||||
close_keysym,
|
close_keysym,
|
||||||
@@ -4750,7 +4750,7 @@ mod tests {
|
|||||||
let none_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| {
|
let none_key_event = |suppr: &mut HashSet<Keycode>, mods: ModifiersState, pressed| {
|
||||||
should_intercept_key(
|
should_intercept_key(
|
||||||
suppr,
|
suppr,
|
||||||
&bindings,
|
&bindings.0,
|
||||||
comp_mod,
|
comp_mod,
|
||||||
Keycode::from(Keysym::l.raw() + 8),
|
Keycode::from(Keysym::l.raw() + 8),
|
||||||
Keysym::l,
|
Keysym::l,
|
||||||
@@ -4956,7 +4956,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::q),
|
Trigger::Keysym(Keysym::q),
|
||||||
ModifiersState {
|
ModifiersState {
|
||||||
@@ -4969,7 +4969,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::q),
|
Trigger::Keysym(Keysym::q),
|
||||||
ModifiersState::default(),
|
ModifiersState::default(),
|
||||||
@@ -4979,7 +4979,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::h),
|
Trigger::Keysym(Keysym::h),
|
||||||
ModifiersState {
|
ModifiersState {
|
||||||
@@ -4992,7 +4992,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::h),
|
Trigger::Keysym(Keysym::h),
|
||||||
ModifiersState::default(),
|
ModifiersState::default(),
|
||||||
@@ -5002,7 +5002,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::j),
|
Trigger::Keysym(Keysym::j),
|
||||||
ModifiersState {
|
ModifiersState {
|
||||||
@@ -5014,7 +5014,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::j),
|
Trigger::Keysym(Keysym::j),
|
||||||
ModifiersState::default(),
|
ModifiersState::default(),
|
||||||
@@ -5025,7 +5025,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::k),
|
Trigger::Keysym(Keysym::k),
|
||||||
ModifiersState {
|
ModifiersState {
|
||||||
@@ -5038,7 +5038,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::k),
|
Trigger::Keysym(Keysym::k),
|
||||||
ModifiersState::default(),
|
ModifiersState::default(),
|
||||||
@@ -5048,7 +5048,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::l),
|
Trigger::Keysym(Keysym::l),
|
||||||
ModifiersState {
|
ModifiersState {
|
||||||
@@ -5062,7 +5062,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
find_configured_bind(
|
find_configured_bind(
|
||||||
&bindings,
|
&bindings.0,
|
||||||
ModKey::Super,
|
ModKey::Super,
|
||||||
Trigger::Keysym(Keysym::l),
|
Trigger::Keysym(Keysym::l),
|
||||||
ModifiersState {
|
ModifiersState {
|
||||||
|
|||||||
Reference in New Issue
Block a user