input: support release actions on mouse buttons
Browse files at this commitab05d6d88abf18b61bb76c3f824e239b6ab6ade2Parent: 73e96872 changed files +28 -0
- src/input/mod.rs +24 -0
- src/niri.rs +4 -0
src/input/mod.rsmodified+24 -0
| @@ -808,6 +808,12 @@ impl State { | |||
| 808 | .drain() | 808 | .drain() |
| 809 | .map(|(_, bind)| bind), | 809 | .map(|(_, bind)| bind), |
| 810 | ); | 810 | ); |
| 811 | + binds.extend( | ||
| 812 | + self.niri | ||
| 813 | + .pending_mouse_release_binds | ||
| 814 | + .drain() | ||
| 815 | + .map(|(_, bind)| bind), | ||
| 816 | + ); | ||
| 811 | 817 | ||
| 812 | // Forget the rest of the input state: the releases will never arrive. | 818 | // Forget the rest of the input state: the releases will never arrive. |
| 813 | self.niri.clear_input_state(); | 819 | self.niri.clear_input_state(); |
| @@ -2955,6 +2961,14 @@ impl State { | |||
| 2955 | let modifiers = modifiers_from_state(mods); | 2961 | let modifiers = modifiers_from_state(mods); |
| 2956 | let mod_down = modifiers.contains(mod_key.to_modifiers()); | 2962 | let mod_down = modifiers.contains(mod_key.to_modifiers()); |
| 2957 | 2963 | ||
| 2964 | + if ButtonState::Released == button_state { | ||
| 2965 | + if let Some(bind) = self.niri.pending_mouse_release_binds.remove(&button_code) { | ||
| 2966 | + self.niri.suppressed_buttons.remove(&button_code); | ||
| 2967 | + self.handle_bind(bind, false); | ||
| 2968 | + return; | ||
| 2969 | + } | ||
| 2970 | + } | ||
| 2971 | + | ||
| 2958 | if self.niri.suppressed_buttons.remove(&button_code) { | 2972 | if self.niri.suppressed_buttons.remove(&button_code) { |
| 2959 | return; | 2973 | return; |
| 2960 | } | 2974 | } |
| @@ -2996,6 +3010,15 @@ impl State { | |||
| 2996 | .and_then(|trigger| self.find_pointer_bind(mod_key, trigger, mods)) | 3010 | .and_then(|trigger| self.find_pointer_bind(mod_key, trigger, mods)) |
| 2997 | { | 3011 | { |
| 2998 | self.niri.suppressed_buttons.insert(button_code); | 3012 | self.niri.suppressed_buttons.insert(button_code); |
| 3013 | + if should_record_release_bind( | ||
| 3014 | + &bind, | ||
| 3015 | + self.niri.is_locked(), | ||
| 3016 | + &self.niri.bind_cooldown_timers, | ||
| 3017 | + ) { | ||
| 3018 | + self.niri | ||
| 3019 | + .pending_mouse_release_binds | ||
| 3020 | + .insert(button_code, bind.clone()); | ||
| 3021 | + } | ||
| 2999 | if bind.has_press() { | 3022 | if bind.has_press() { |
| 3000 | self.handle_bind(bind.clone(), true); | 3023 | self.handle_bind(bind.clone(), true); |
| 3001 | } | 3024 | } |
| @@ -4642,6 +4665,7 @@ impl State { | |||
| 4642 | impl Niri { | 4665 | impl Niri { |
| 4643 | fn cancel_interrupted_release_binds(&mut self) { | 4666 | fn cancel_interrupted_release_binds(&mut self) { |
| 4644 | retain_press_binds(&mut self.pending_release_binds); | 4667 | retain_press_binds(&mut self.pending_release_binds); |
| 4668 | + retain_press_binds(&mut self.pending_mouse_release_binds); | ||
| 4645 | } | 4669 | } |
| 4646 | } | 4670 | } |
| 4647 | 4671 | ||
src/niri.rsmodified+4 -0
| @@ -361,6 +361,8 @@ pub struct Niri { | |||
| 361 | pub suppressed_buttons: HashSet<u32>, | 361 | pub suppressed_buttons: HashSet<u32>, |
| 362 | /// Binds whose release action is pending, keyed by the key code. | 362 | /// Binds whose release action is pending, keyed by the key code. |
| 363 | pub pending_release_binds: HashMap<Keycode, Bind>, | 363 | pub pending_release_binds: HashMap<Keycode, Bind>, |
| 364 | + /// Same as `pending_release_binds`, but for mouse buttons, keyed by the button code. | ||
| 365 | + pub pending_mouse_release_binds: HashMap<u32, Bind>, | ||
| 364 | pub bind_cooldown_timers: HashMap<Key, RegistrationToken>, | 366 | pub bind_cooldown_timers: HashMap<Key, RegistrationToken>, |
| 365 | pub bind_repeat_timer: Option<RegistrationToken>, | 367 | pub bind_repeat_timer: Option<RegistrationToken>, |
| 366 | pub keyboard_focus: KeyboardFocus, | 368 | pub keyboard_focus: KeyboardFocus, |
| @@ -2840,6 +2842,7 @@ impl Niri { | |||
| 2840 | suppressed_keys: HashSet::new(), | 2842 | suppressed_keys: HashSet::new(), |
| 2841 | suppressed_buttons: HashSet::new(), | 2843 | suppressed_buttons: HashSet::new(), |
| 2842 | pending_release_binds: HashMap::new(), | 2844 | pending_release_binds: HashMap::new(), |
| 2845 | + pending_mouse_release_binds: HashMap::new(), | ||
| 2843 | bind_cooldown_timers: HashMap::new(), | 2846 | bind_cooldown_timers: HashMap::new(), |
| 2844 | bind_repeat_timer: Option::default(), | 2847 | bind_repeat_timer: Option::default(), |
| 2845 | presentation_state, | 2848 | presentation_state, |
| @@ -6597,6 +6600,7 @@ impl Niri { | |||
| 6597 | self.suppressed_keys.clear(); | 6600 | self.suppressed_keys.clear(); |
| 6598 | self.suppressed_buttons.clear(); | 6601 | self.suppressed_buttons.clear(); |
| 6599 | self.pending_release_binds.clear(); | 6602 | self.pending_release_binds.clear(); |
| 6603 | + self.pending_mouse_release_binds.clear(); | ||
| 6600 | 6604 | ||
| 6601 | // Stop ongoing key repeat if any. | 6605 | // Stop ongoing key repeat if any. |
| 6602 | if let Some(token) = self.bind_repeat_timer.take() { | 6606 | if let Some(token) = self.bind_repeat_timer.take() { |