input: avoid unnecessary Bind and Action clones
Browse files at this commitcbd94d10cd1f7f824c843399006e9f9e6aa1697fParent: b345b122 changed files +18 -12
- niri-config/src/binds.rs +11 -0
- src/input/mod.rs +7 -12
niri-config/src/binds.rsmodified+11 -0
| @@ -67,6 +67,17 @@ impl Bind { | |||
| 67 | BoundAction::Press(_) => None, | 67 | BoundAction::Press(_) => None, |
| 68 | } | 68 | } |
| 69 | } | 69 | } |
| 70 | + | ||
| 71 | + pub fn into_action(self, pressed: bool) -> Option<Action> { | ||
| 72 | + match (self.action, pressed) { | ||
| 73 | + (BoundAction::Press(action), true) | (BoundAction::Release(action), false) => { | ||
| 74 | + Some(action) | ||
| 75 | + } | ||
| 76 | + (BoundAction::Both { press, .. }, true) => Some(press), | ||
| 77 | + (BoundAction::Both { release, .. }, false) => Some(release), | ||
| 78 | + _ => None, | ||
| 79 | + } | ||
| 80 | + } | ||
| 70 | } | 81 | } |
| 71 | 82 | ||
| 72 | #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] | 83 | #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] |
src/input/mod.rsmodified+7 -12
| @@ -681,10 +681,10 @@ impl State { | |||
| 681 | match result { | 681 | match result { |
| 682 | ShouldInterceptResult::ForwardAndHandle(bind) | 682 | ShouldInterceptResult::ForwardAndHandle(bind) |
| 683 | | ShouldInterceptResult::InterceptAndHandle(bind) => { | 683 | | ShouldInterceptResult::InterceptAndHandle(bind) => { |
| 684 | - self.handle_bind(bind.clone(), pressed); | 684 | + if pressed && bind.repeat { |
| 685 | - if pressed { | 685 | + self.start_key_repeat(bind.clone()); |
| 686 | - self.start_key_repeat(bind); | ||
| 687 | } | 686 | } |
| 687 | + self.handle_bind(bind, pressed); | ||
| 688 | } | 688 | } |
| 689 | ShouldInterceptResult::Forward | ShouldInterceptResult::InterceptOnly => {} | 689 | ShouldInterceptResult::Forward | ShouldInterceptResult::InterceptOnly => {} |
| 690 | } | 690 | } |
| @@ -747,15 +747,6 @@ impl State { | |||
| 747 | } | 747 | } |
| 748 | 748 | ||
| 749 | pub fn handle_bind(&mut self, bind: Bind, pressed: bool) { | 749 | pub fn handle_bind(&mut self, bind: Bind, pressed: bool) { |
| 750 | - let action = if pressed { | ||
| 751 | - bind.press_action() | ||
| 752 | - } else { | ||
| 753 | - bind.release_action() | ||
| 754 | - }; | ||
| 755 | - let Some(action) = action.cloned() else { | ||
| 756 | - return; | ||
| 757 | - }; | ||
| 758 | - | ||
| 759 | let allowed_when_locked = bind_allowed_when_locked(&bind, pressed); | 750 | let allowed_when_locked = bind_allowed_when_locked(&bind, pressed); |
| 760 | let allowed_during_screenshot = bind_allowed_during_screenshot(&bind, pressed); | 751 | let allowed_during_screenshot = bind_allowed_during_screenshot(&bind, pressed); |
| 761 | 752 | ||
| @@ -796,6 +787,10 @@ impl State { | |||
| 796 | } | 787 | } |
| 797 | } | 788 | } |
| 798 | 789 | ||
| 790 | + let Some(action) = bind.into_action(pressed) else { | ||
| 791 | + return; | ||
| 792 | + }; | ||
| 793 | + | ||
| 799 | self.do_action(action, allowed_when_locked); | 794 | self.do_action(action, allowed_when_locked); |
| 800 | } | 795 | } |
| 801 | 796 | ||