input: add find_pointer_bind()
Browse files at this commit73e96877be16b95f362e0b886d40a0b6e0f82429Parent: 53318801 changed file +34 -102
- src/input/mod.rs +34 -102
src/input/mod.rsmodified+34 -102
| @@ -2922,6 +2922,22 @@ impl State { | ||
| 2922 | 2922 | self.niri.queue_redraw_all(); |
| 2923 | 2923 | } |
| 2924 | 2924 | |
| 2925 | + fn find_pointer_bind( | |
| 2926 | + &mut self, | |
| 2927 | + mod_key: ModKey, | |
| 2928 | + trigger: Trigger, | |
| 2929 | + mods: ModifiersState, | |
| 2930 | + ) -> Option<Bind> { | |
| 2931 | + let modifiers = modifiers_from_state(mods); | |
| 2932 | + | |
| 2933 | + let config = self.niri.config.borrow(); | |
| 2934 | + let bindings = make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers); | |
| 2935 | + | |
| 2936 | + find_configured_bind(bindings, mod_key, trigger, mods).filter(|bind| { | |
| 2937 | + !self.niri.screenshot_ui.is_open() || bind_allowed_during_screenshot(bind, true) | |
| 2938 | + }) | |
| 2939 | + } | |
| 2940 | + | |
| 2925 | 2941 | fn on_pointer_button<I: InputBackend>(&mut self, event: I::PointerButtonEvent) { |
| 2926 | 2942 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 2927 | 2943 | |
| @@ -2977,15 +2993,8 @@ impl State { | ||
| 2977 | 2993 | Some(MouseButton::Forward) => Some(Trigger::MouseForward), |
| 2978 | 2994 | _ => None, |
| 2979 | 2995 | } |
| 2980 | - .and_then(|trigger| { | |
| 2981 | - let config = self.niri.config.borrow(); | |
| 2982 | - let bindings = | |
| 2983 | - make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers); | |
| 2984 | - find_configured_bind(bindings, mod_key, trigger, mods) | |
| 2985 | - }) | |
| 2986 | - .filter(|bind| { | |
| 2987 | - !self.niri.screenshot_ui.is_open() || bind_allowed_during_screenshot(bind, true) | |
| 2988 | - }) { | |
| 2996 | + .and_then(|trigger| self.find_pointer_bind(mod_key, trigger, mods)) | |
| 2997 | + { | |
| 2989 | 2998 | self.niri.suppressed_buttons.insert(button_code); |
| 2990 | 2999 | if bind.has_press() { |
| 2991 | 3000 | self.handle_bind(bind.clone(), true); |
| @@ -3341,30 +3350,10 @@ impl State { | ||
| 3341 | 3350 | }); |
| 3342 | 3351 | (bind_left, bind_right) |
| 3343 | 3352 | } else { |
| 3344 | - let config = self.niri.config.borrow(); | |
| 3345 | - let bindings = | |
| 3346 | - make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers); | |
| 3347 | - let bind_left = find_configured_bind( | |
| 3348 | - bindings.clone(), | |
| 3349 | - mod_key, | |
| 3350 | - Trigger::WheelScrollLeft, | |
| 3351 | - mods, | |
| 3352 | - ) | |
| 3353 | - .filter(|bind| { | |
| 3354 | - !self.niri.screenshot_ui.is_open() | |
| 3355 | - || bind_allowed_during_screenshot(bind, true) | |
| 3356 | - }); | |
| 3357 | - let bind_right = find_configured_bind( | |
| 3358 | - bindings, | |
| 3359 | - mod_key, | |
| 3360 | - Trigger::WheelScrollRight, | |
| 3361 | - mods, | |
| 3353 | + ( | |
| 3354 | + self.find_pointer_bind(mod_key, Trigger::WheelScrollLeft, mods), | |
| 3355 | + self.find_pointer_bind(mod_key, Trigger::WheelScrollRight, mods), | |
| 3362 | 3356 | ) |
| 3363 | - .filter(|bind| { | |
| 3364 | - !self.niri.screenshot_ui.is_open() | |
| 3365 | - || bind_allowed_during_screenshot(bind, true) | |
| 3366 | - }); | |
| 3367 | - (bind_left, bind_right) | |
| 3368 | 3357 | }; |
| 3369 | 3358 | |
| 3370 | 3359 | if let Some(right) = bind_right { |
| @@ -3447,26 +3436,10 @@ impl State { | ||
| 3447 | 3436 | }); |
| 3448 | 3437 | (bind_up, bind_down) |
| 3449 | 3438 | } else { |
| 3450 | - let config = self.niri.config.borrow(); | |
| 3451 | - let bindings = | |
| 3452 | - make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers); | |
| 3453 | - let bind_up = find_configured_bind( | |
| 3454 | - bindings.clone(), | |
| 3455 | - mod_key, | |
| 3456 | - Trigger::WheelScrollUp, | |
| 3457 | - mods, | |
| 3439 | + ( | |
| 3440 | + self.find_pointer_bind(mod_key, Trigger::WheelScrollUp, mods), | |
| 3441 | + self.find_pointer_bind(mod_key, Trigger::WheelScrollDown, mods), | |
| 3458 | 3442 | ) |
| 3459 | - .filter(|bind| { | |
| 3460 | - !self.niri.screenshot_ui.is_open() | |
| 3461 | - || bind_allowed_during_screenshot(bind, true) | |
| 3462 | - }); | |
| 3463 | - let bind_down = | |
| 3464 | - find_configured_bind(bindings, mod_key, Trigger::WheelScrollDown, mods) | |
| 3465 | - .filter(|bind| { | |
| 3466 | - !self.niri.screenshot_ui.is_open() | |
| 3467 | - || bind_allowed_during_screenshot(bind, true) | |
| 3468 | - }); | |
| 3469 | - (bind_up, bind_down) | |
| 3470 | 3443 | }; |
| 3471 | 3444 | |
| 3472 | 3445 | if let Some(down) = bind_down { |
| @@ -3599,26 +3572,10 @@ impl State { | ||
| 3599 | 3572 | .horizontal_finger_scroll_tracker |
| 3600 | 3573 | .accumulate(horizontal); |
| 3601 | 3574 | if ticks != 0 { |
| 3602 | - let config = self.niri.config.borrow(); | |
| 3603 | - let bindings = | |
| 3604 | - make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers); | |
| 3605 | - let bind_left = find_configured_bind( | |
| 3606 | - bindings.clone(), | |
| 3607 | - mod_key, | |
| 3608 | - Trigger::TouchpadScrollLeft, | |
| 3609 | - mods, | |
| 3610 | - ) | |
| 3611 | - .filter(|bind| { | |
| 3612 | - !self.niri.screenshot_ui.is_open() | |
| 3613 | - || bind_allowed_during_screenshot(bind, true) | |
| 3614 | - }); | |
| 3615 | - let bind_right = | |
| 3616 | - find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollRight, mods) | |
| 3617 | - .filter(|bind| { | |
| 3618 | - !self.niri.screenshot_ui.is_open() | |
| 3619 | - || bind_allowed_during_screenshot(bind, true) | |
| 3620 | - }); | |
| 3621 | - drop(config); | |
| 3575 | + let (bind_left, bind_right) = ( | |
| 3576 | + self.find_pointer_bind(mod_key, Trigger::TouchpadScrollLeft, mods), | |
| 3577 | + self.find_pointer_bind(mod_key, Trigger::TouchpadScrollRight, mods), | |
| 3578 | + ); | |
| 3622 | 3579 | |
| 3623 | 3580 | if let Some(right) = bind_right { |
| 3624 | 3581 | for _ in 0..ticks { |
| @@ -3637,26 +3594,10 @@ impl State { | ||
| 3637 | 3594 | .vertical_finger_scroll_tracker |
| 3638 | 3595 | .accumulate(vertical); |
| 3639 | 3596 | if ticks != 0 { |
| 3640 | - let config = self.niri.config.borrow(); | |
| 3641 | - let bindings = | |
| 3642 | - make_binds_iter(&config, &mut self.niri.window_mru_ui, modifiers); | |
| 3643 | - let bind_up = find_configured_bind( | |
| 3644 | - bindings.clone(), | |
| 3645 | - mod_key, | |
| 3646 | - Trigger::TouchpadScrollUp, | |
| 3647 | - mods, | |
| 3648 | - ) | |
| 3649 | - .filter(|bind| { | |
| 3650 | - !self.niri.screenshot_ui.is_open() | |
| 3651 | - || bind_allowed_during_screenshot(bind, true) | |
| 3652 | - }); | |
| 3653 | - let bind_down = | |
| 3654 | - find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollDown, mods) | |
| 3655 | - .filter(|bind| { | |
| 3656 | - !self.niri.screenshot_ui.is_open() | |
| 3657 | - || bind_allowed_during_screenshot(bind, true) | |
| 3658 | - }); | |
| 3659 | - drop(config); | |
| 3597 | + let (bind_up, bind_down) = ( | |
| 3598 | + self.find_pointer_bind(mod_key, Trigger::TouchpadScrollUp, mods), | |
| 3599 | + self.find_pointer_bind(mod_key, Trigger::TouchpadScrollDown, mods), | |
| 3600 | + ); | |
| 3660 | 3601 | |
| 3661 | 3602 | if let Some(down) = bind_down { |
| 3662 | 3603 | for _ in 0..ticks { |
| @@ -4085,16 +4026,7 @@ impl State { | ||
| 4085 | 4026 | let modifiers = modifiers_from_state(mods); |
| 4086 | 4027 | |
| 4087 | 4028 | if self.niri.mods_with_tablet_stylus_binds.contains(&modifiers) { |
| 4088 | - let bind = { | |
| 4089 | - let config = self.niri.config.borrow(); | |
| 4090 | - let bindings = config.binds.0.iter(); | |
| 4091 | - find_configured_bind(bindings, mod_key, trigger, mods) | |
| 4092 | - } | |
| 4093 | - .filter(|bind| { | |
| 4094 | - !self.niri.screenshot_ui.is_open() | |
| 4095 | - || bind_allowed_during_screenshot(bind, true) | |
| 4096 | - }); | |
| 4097 | - if let Some(bind) = bind { | |
| 4029 | + if let Some(bind) = self.find_pointer_bind(mod_key, trigger, mods) { | |
| 4098 | 4030 | self.niri.suppressed_buttons.insert(button); |
| 4099 | 4031 | if bind.has_press() { |
| 4100 | 4032 | self.handle_bind(bind.clone(), true); |
| @@ -5640,7 +5572,7 @@ fn make_binds_iter<'a>( | ||
| 5640 | 5572 | config: &'a Config, |
| 5641 | 5573 | mru: &'a mut WindowMruUi, |
| 5642 | 5574 | mods: Modifiers, |
| 5643 | -) -> impl Iterator<Item = &'a Bind> + Clone { | |
| 5575 | +) -> impl Iterator<Item = &'a Bind> { | |
| 5644 | 5576 | // Figure out the binds to use depending on whether the MRU is enabled and/or open. |
| 5645 | 5577 | let general_binds = (!mru.is_open()).then_some(config.binds.0.iter()); |
| 5646 | 5578 | let general_binds = general_binds.into_iter().flatten(); |