From ab05d6d88abf18b61bb76c3f824e239b6ab6ade2 Mon Sep 17 00:00:00 2001 From: Justin Spedding Date: Tue, 22 Sep 2026 16:08:52 -0400 Subject: [PATCH] input: support release actions on mouse buttons --- src/input/mod.rs | 24 ++++++++++++++++++++++++ src/niri.rs | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/src/input/mod.rs b/src/input/mod.rs index c8c546d3..68def8a2 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -808,6 +808,12 @@ impl State { .drain() .map(|(_, bind)| bind), ); + binds.extend( + self.niri + .pending_mouse_release_binds + .drain() + .map(|(_, bind)| bind), + ); // Forget the rest of the input state: the releases will never arrive. self.niri.clear_input_state(); @@ -2955,6 +2961,14 @@ impl State { let modifiers = modifiers_from_state(mods); let mod_down = modifiers.contains(mod_key.to_modifiers()); + if ButtonState::Released == button_state { + if let Some(bind) = self.niri.pending_mouse_release_binds.remove(&button_code) { + self.niri.suppressed_buttons.remove(&button_code); + self.handle_bind(bind, false); + return; + } + } + if self.niri.suppressed_buttons.remove(&button_code) { return; } @@ -2996,6 +3010,15 @@ impl State { .and_then(|trigger| self.find_pointer_bind(mod_key, trigger, mods)) { self.niri.suppressed_buttons.insert(button_code); + if should_record_release_bind( + &bind, + self.niri.is_locked(), + &self.niri.bind_cooldown_timers, + ) { + self.niri + .pending_mouse_release_binds + .insert(button_code, bind.clone()); + } if bind.has_press() { self.handle_bind(bind.clone(), true); } @@ -4642,6 +4665,7 @@ impl State { impl Niri { fn cancel_interrupted_release_binds(&mut self) { retain_press_binds(&mut self.pending_release_binds); + retain_press_binds(&mut self.pending_mouse_release_binds); } } diff --git a/src/niri.rs b/src/niri.rs index 578e0f03..b36bd499 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -361,6 +361,8 @@ pub struct Niri { pub suppressed_buttons: HashSet, /// Binds whose release action is pending, keyed by the key code. pub pending_release_binds: HashMap, + /// Same as `pending_release_binds`, but for mouse buttons, keyed by the button code. + pub pending_mouse_release_binds: HashMap, pub bind_cooldown_timers: HashMap, pub bind_repeat_timer: Option, pub keyboard_focus: KeyboardFocus, @@ -2840,6 +2842,7 @@ impl Niri { suppressed_keys: HashSet::new(), suppressed_buttons: HashSet::new(), pending_release_binds: HashMap::new(), + pending_mouse_release_binds: HashMap::new(), bind_cooldown_timers: HashMap::new(), bind_repeat_timer: Option::default(), presentation_state, @@ -6597,6 +6600,7 @@ impl Niri { self.suppressed_keys.clear(); self.suppressed_buttons.clear(); self.pending_release_binds.clear(); + self.pending_mouse_release_binds.clear(); // Stop ongoing key repeat if any. if let Some(token) = self.bind_repeat_timer.take() {