From cbd94d10cd1f7f824c843399006e9f9e6aa1697f Mon Sep 17 00:00:00 2001 From: Justin Spedding Date: Sun, 18 Oct 2026 10:25:24 -0400 Subject: [PATCH] input: avoid unnecessary Bind and Action clones --- niri-config/src/binds.rs | 11 +++++++++++ src/input/mod.rs | 19 +++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/niri-config/src/binds.rs b/niri-config/src/binds.rs index 4a715f68..bed03739 100644 --- a/niri-config/src/binds.rs +++ b/niri-config/src/binds.rs @@ -67,6 +67,17 @@ impl Bind { BoundAction::Press(_) => None, } } + + pub fn into_action(self, pressed: bool) -> Option { + match (self.action, pressed) { + (BoundAction::Press(action), true) | (BoundAction::Release(action), false) => { + Some(action) + } + (BoundAction::Both { press, .. }, true) => Some(press), + (BoundAction::Both { release, .. }, false) => Some(release), + _ => None, + } + } } #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] diff --git a/src/input/mod.rs b/src/input/mod.rs index 03d9fbd9..e2225b69 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -681,10 +681,10 @@ impl State { match result { ShouldInterceptResult::ForwardAndHandle(bind) | ShouldInterceptResult::InterceptAndHandle(bind) => { - self.handle_bind(bind.clone(), pressed); - if pressed { - self.start_key_repeat(bind); + if pressed && bind.repeat { + self.start_key_repeat(bind.clone()); } + self.handle_bind(bind, pressed); } ShouldInterceptResult::Forward | ShouldInterceptResult::InterceptOnly => {} } @@ -747,15 +747,6 @@ impl State { } pub fn handle_bind(&mut self, bind: Bind, pressed: bool) { - let action = if pressed { - bind.press_action() - } else { - bind.release_action() - }; - let Some(action) = action.cloned() else { - return; - }; - let allowed_when_locked = bind_allowed_when_locked(&bind, pressed); let allowed_during_screenshot = bind_allowed_during_screenshot(&bind, pressed); @@ -796,6 +787,10 @@ impl State { } } + let Some(action) = bind.into_action(pressed) else { + return; + }; + self.do_action(action, allowed_when_locked); }