input: support release actions on tablet stylus buttons
Browse files at this commiteb9e029708f4b27f96248f334e40f1ee69703c6eParent: ab05d6d2 changed files +29 -0
- src/input/mod.rs +25 -0
- src/niri.rs +4 -0
src/input/mod.rsmodified+25 -0
| @@ -814,6 +814,12 @@ impl State { | ||
| 814 | 814 | .drain() |
| 815 | 815 | .map(|(_, bind)| bind), |
| 816 | 816 | ); |
| 817 | + binds.extend( | |
| 818 | + self.niri | |
| 819 | + .pending_tablet_release_binds | |
| 820 | + .drain() | |
| 821 | + .map(|(_, bind)| bind), | |
| 822 | + ); | |
| 817 | 823 | |
| 818 | 824 | // Forget the rest of the input state: the releases will never arrive. |
| 819 | 825 | self.niri.clear_input_state(); |
| @@ -4034,6 +4040,15 @@ impl State { | ||
| 4034 | 4040 | _ => None, |
| 4035 | 4041 | }; |
| 4036 | 4042 | |
| 4043 | + // Handle release binds. | |
| 4044 | + if button_state == ButtonState::Released { | |
| 4045 | + if let Some(bind) = self.niri.pending_tablet_release_binds.remove(&button) { | |
| 4046 | + self.niri.suppressed_buttons.remove(&button); | |
| 4047 | + self.handle_bind(bind, false); | |
| 4048 | + return; | |
| 4049 | + } | |
| 4050 | + } | |
| 4051 | + | |
| 4037 | 4052 | if self.niri.suppressed_buttons.remove(&button) { |
| 4038 | 4053 | return; |
| 4039 | 4054 | } |
| @@ -4051,6 +4066,15 @@ impl State { | ||
| 4051 | 4066 | if self.niri.mods_with_tablet_stylus_binds.contains(&modifiers) { |
| 4052 | 4067 | if let Some(bind) = self.find_pointer_bind(mod_key, trigger, mods) { |
| 4053 | 4068 | self.niri.suppressed_buttons.insert(button); |
| 4069 | + if should_record_release_bind( | |
| 4070 | + &bind, | |
| 4071 | + self.niri.is_locked(), | |
| 4072 | + &self.niri.bind_cooldown_timers, | |
| 4073 | + ) { | |
| 4074 | + self.niri | |
| 4075 | + .pending_tablet_release_binds | |
| 4076 | + .insert(button, bind.clone()); | |
| 4077 | + } | |
| 4054 | 4078 | if bind.has_press() { |
| 4055 | 4079 | self.handle_bind(bind.clone(), true); |
| 4056 | 4080 | } |
| @@ -4666,6 +4690,7 @@ impl Niri { | ||
| 4666 | 4690 | fn cancel_interrupted_release_binds(&mut self) { |
| 4667 | 4691 | retain_press_binds(&mut self.pending_release_binds); |
| 4668 | 4692 | retain_press_binds(&mut self.pending_mouse_release_binds); |
| 4693 | + retain_press_binds(&mut self.pending_tablet_release_binds); | |
| 4669 | 4694 | } |
| 4670 | 4695 | } |
| 4671 | 4696 |
src/niri.rsmodified+4 -0
| @@ -363,6 +363,8 @@ pub struct Niri { | ||
| 363 | 363 | pub pending_release_binds: HashMap<Keycode, Bind>, |
| 364 | 364 | /// Same as `pending_release_binds`, but for mouse buttons, keyed by the button code. |
| 365 | 365 | pub pending_mouse_release_binds: HashMap<u32, Bind>, |
| 366 | + /// Same as `pending_release_binds`, but for tablet tool buttons, keyed by the button code. | |
| 367 | + pub pending_tablet_release_binds: HashMap<u32, Bind>, | |
| 366 | 368 | pub bind_cooldown_timers: HashMap<Key, RegistrationToken>, |
| 367 | 369 | pub bind_repeat_timer: Option<RegistrationToken>, |
| 368 | 370 | pub keyboard_focus: KeyboardFocus, |
| @@ -2843,6 +2845,7 @@ impl Niri { | ||
| 2843 | 2845 | suppressed_buttons: HashSet::new(), |
| 2844 | 2846 | pending_release_binds: HashMap::new(), |
| 2845 | 2847 | pending_mouse_release_binds: HashMap::new(), |
| 2848 | + pending_tablet_release_binds: HashMap::new(), | |
| 2846 | 2849 | bind_cooldown_timers: HashMap::new(), |
| 2847 | 2850 | bind_repeat_timer: Option::default(), |
| 2848 | 2851 | presentation_state, |
| @@ -6601,6 +6604,7 @@ impl Niri { | ||
| 6601 | 6604 | self.suppressed_buttons.clear(); |
| 6602 | 6605 | self.pending_release_binds.clear(); |
| 6603 | 6606 | self.pending_mouse_release_binds.clear(); |
| 6607 | + self.pending_tablet_release_binds.clear(); | |
| 6604 | 6608 | |
| 6605 | 6609 | // Stop ongoing key repeat if any. |
| 6606 | 6610 | if let Some(token) = self.bind_repeat_timer.take() { |