input: add tablet stylus button triggers and binds (#3745)
Browse files at this commit4 changed files +73 -2
- niri-config/src/binds.rs +9 -0
- src/input/mod.rs +55 -1
- src/niri.rs +6 -1
- src/ui/hotkey_overlay.rs +3 -0
niri-config/src/binds.rsmodified+9 -0
| @@ -52,6 +52,9 @@ pub enum Trigger { | |||
| 52 | TouchpadScrollUp, | 52 | TouchpadScrollUp, |
| 53 | TouchpadScrollLeft, | 53 | TouchpadScrollLeft, |
| 54 | TouchpadScrollRight, | 54 | TouchpadScrollRight, |
| 55 | + TabletStylusButton1, | ||
| 56 | + TabletStylusButton2, | ||
| 57 | + TabletStylusButton3, | ||
| 55 | } | 58 | } |
| 56 | 59 | ||
| 57 | bitflags! { | 60 | bitflags! { |
| @@ -1000,6 +1003,12 @@ impl FromStr for Key { | |||
| 1000 | Trigger::TouchpadScrollLeft | 1003 | Trigger::TouchpadScrollLeft |
| 1001 | } else if key.eq_ignore_ascii_case("TouchpadScrollRight") { | 1004 | } else if key.eq_ignore_ascii_case("TouchpadScrollRight") { |
| 1002 | Trigger::TouchpadScrollRight | 1005 | Trigger::TouchpadScrollRight |
| 1006 | + } else if key.eq_ignore_ascii_case("TabletStylusButton1") { | ||
| 1007 | + Trigger::TabletStylusButton1 | ||
| 1008 | + } else if key.eq_ignore_ascii_case("TabletStylusButton2") { | ||
| 1009 | + Trigger::TabletStylusButton2 | ||
| 1010 | + } else if key.eq_ignore_ascii_case("TabletStylusButton3") { | ||
| 1011 | + Trigger::TabletStylusButton3 | ||
| 1003 | } else { | 1012 | } else { |
| 1004 | let mut keysym = keysym_from_name(key, KEYSYM_CASE_INSENSITIVE); | 1013 | let mut keysym = keysym_from_name(key, KEYSYM_CASE_INSENSITIVE); |
| 1005 | // The keyboard event handling code can receive either | 1014 | // The keyboard event handling code can receive either |
src/input/mod.rsmodified+55 -1
| @@ -3778,11 +3778,53 @@ impl State { | |||
| 3778 | } | 3778 | } |
| 3779 | 3779 | ||
| 3780 | fn on_tablet_tool_button<I: InputBackend>(&mut self, event: I::TabletToolButtonEvent) { | 3780 | fn on_tablet_tool_button<I: InputBackend>(&mut self, event: I::TabletToolButtonEvent) { |
| 3781 | + const BTN_STYLUS3: u32 = 0x149; | ||
| 3782 | + const BTN_STYLUS: u32 = 0x14b; | ||
| 3783 | + const BTN_STYLUS2: u32 = 0x14c; | ||
| 3784 | + | ||
| 3781 | let tool = self.niri.seat.tablet_seat().get_tool(&event.tool()); | 3785 | let tool = self.niri.seat.tablet_seat().get_tool(&event.tool()); |
| 3782 | 3786 | ||
| 3783 | if let Some(tool) = tool { | 3787 | if let Some(tool) = tool { |
| 3788 | + let button = event.button(); | ||
| 3789 | + | ||
| 3790 | + if self.niri.suppressed_buttons.remove(&button) { | ||
| 3791 | + return; | ||
| 3792 | + } | ||
| 3793 | + | ||
| 3794 | + let trigger = match button { | ||
| 3795 | + BTN_STYLUS => Some(Trigger::TabletStylusButton1), | ||
| 3796 | + BTN_STYLUS2 => Some(Trigger::TabletStylusButton2), | ||
| 3797 | + BTN_STYLUS3 => Some(Trigger::TabletStylusButton3), | ||
| 3798 | + _ => None, | ||
| 3799 | + }; | ||
| 3800 | + | ||
| 3801 | + if let Some(trigger) = trigger { | ||
| 3802 | + if event.button_state() == ButtonState::Pressed { | ||
| 3803 | + let mod_key = self.backend.mod_key(&self.niri.config.borrow()); | ||
| 3804 | + let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | ||
| 3805 | + let modifiers = modifiers_from_state(mods); | ||
| 3806 | + | ||
| 3807 | + if self.niri.mods_with_tablet_stylus_binds.contains(&modifiers) { | ||
| 3808 | + let bind = { | ||
| 3809 | + let config = self.niri.config.borrow(); | ||
| 3810 | + let bindings = config.binds.0.iter(); | ||
| 3811 | + find_configured_bind(bindings, mod_key, trigger, mods) | ||
| 3812 | + } | ||
| 3813 | + .filter(|bind| { | ||
| 3814 | + !self.niri.screenshot_ui.is_open() | ||
| 3815 | + || allowed_during_screenshot(&bind.action) | ||
| 3816 | + }); | ||
| 3817 | + if let Some(bind) = bind { | ||
| 3818 | + self.niri.suppressed_buttons.insert(button); | ||
| 3819 | + self.handle_bind(bind.clone()); | ||
| 3820 | + return; | ||
| 3821 | + } | ||
| 3822 | + } | ||
| 3823 | + } | ||
| 3824 | + } | ||
| 3825 | + | ||
| 3784 | tool.button( | 3826 | tool.button( |
| 3785 | - event.button(), | 3827 | + button, |
| 3786 | event.button_state(), | 3828 | event.button_state(), |
| 3787 | SERIAL_COUNTER.next_serial(), | 3829 | SERIAL_COUNTER.next_serial(), |
| 3788 | event.time_msec(), | 3830 | event.time_msec(), |
| @@ -5069,6 +5111,18 @@ pub fn mods_with_finger_scroll_binds(mod_key: ModKey, binds: &Binds) -> HashSet< | |||
| 5069 | ) | 5111 | ) |
| 5070 | } | 5112 | } |
| 5071 | 5113 | ||
| 5114 | +pub fn mods_with_tablet_stylus_binds(mod_key: ModKey, binds: &Binds) -> HashSet<Modifiers> { | ||
| 5115 | + mods_with_binds( | ||
| 5116 | + mod_key, | ||
| 5117 | + binds, | ||
| 5118 | + &[ | ||
| 5119 | + Trigger::TabletStylusButton1, | ||
| 5120 | + Trigger::TabletStylusButton2, | ||
| 5121 | + Trigger::TabletStylusButton3, | ||
| 5122 | + ], | ||
| 5123 | + ) | ||
| 5124 | +} | ||
| 5125 | + | ||
| 5072 | fn grab_allows_hot_corner(grab: &(dyn PointerGrab<State> + 'static)) -> bool { | 5126 | fn grab_allows_hot_corner(grab: &(dyn PointerGrab<State> + 'static)) -> bool { |
| 5073 | let grab = grab.as_any(); | 5127 | let grab = grab.as_any(); |
| 5074 | 5128 | ||
src/niri.rsmodified+6 -1
| @@ -134,7 +134,7 @@ use crate::input::scroll_swipe_gesture::ScrollSwipeGesture; | |||
| 134 | use crate::input::scroll_tracker::ScrollTracker; | 134 | use crate::input::scroll_tracker::ScrollTracker; |
| 135 | use crate::input::{ | 135 | use crate::input::{ |
| 136 | apply_libinput_settings, mods_with_finger_scroll_binds, mods_with_mouse_binds, | 136 | apply_libinput_settings, mods_with_finger_scroll_binds, mods_with_mouse_binds, |
| 137 | - mods_with_wheel_binds, TabletData, | 137 | + mods_with_tablet_stylus_binds, mods_with_wheel_binds, TabletData, |
| 138 | }; | 138 | }; |
| 139 | use crate::ipc::server::IpcServer; | 139 | use crate::ipc::server::IpcServer; |
| 140 | use crate::layer::mapped::LayerSurfaceRenderElement; | 140 | use crate::layer::mapped::LayerSurfaceRenderElement; |
| @@ -376,6 +376,7 @@ pub struct Niri { | |||
| 376 | pub horizontal_wheel_tracker: ScrollTracker, | 376 | pub horizontal_wheel_tracker: ScrollTracker, |
| 377 | pub mods_with_mouse_binds: HashSet<Modifiers>, | 377 | pub mods_with_mouse_binds: HashSet<Modifiers>, |
| 378 | pub mods_with_wheel_binds: HashSet<Modifiers>, | 378 | pub mods_with_wheel_binds: HashSet<Modifiers>, |
| 379 | + pub mods_with_tablet_stylus_binds: HashSet<Modifiers>, | ||
| 379 | pub vertical_finger_scroll_tracker: ScrollTracker, | 380 | pub vertical_finger_scroll_tracker: ScrollTracker, |
| 380 | pub horizontal_finger_scroll_tracker: ScrollTracker, | 381 | pub horizontal_finger_scroll_tracker: ScrollTracker, |
| 381 | pub mods_with_finger_scroll_binds: HashSet<Modifiers>, | 382 | pub mods_with_finger_scroll_binds: HashSet<Modifiers>, |
| @@ -1534,6 +1535,8 @@ impl State { | |||
| 1534 | .on_hotkey_config_updated(new_mod_key); | 1535 | .on_hotkey_config_updated(new_mod_key); |
| 1535 | self.niri.mods_with_mouse_binds = mods_with_mouse_binds(new_mod_key, &config.binds); | 1536 | self.niri.mods_with_mouse_binds = mods_with_mouse_binds(new_mod_key, &config.binds); |
| 1536 | self.niri.mods_with_wheel_binds = mods_with_wheel_binds(new_mod_key, &config.binds); | 1537 | self.niri.mods_with_wheel_binds = mods_with_wheel_binds(new_mod_key, &config.binds); |
| 1538 | + self.niri.mods_with_tablet_stylus_binds = | ||
| 1539 | + mods_with_tablet_stylus_binds(new_mod_key, &config.binds); | ||
| 1537 | self.niri.mods_with_finger_scroll_binds = | 1540 | self.niri.mods_with_finger_scroll_binds = |
| 1538 | mods_with_finger_scroll_binds(new_mod_key, &config.binds); | 1541 | mods_with_finger_scroll_binds(new_mod_key, &config.binds); |
| 1539 | } | 1542 | } |
| @@ -2407,6 +2410,7 @@ impl Niri { | |||
| 2407 | let mods_with_mouse_binds = mods_with_mouse_binds(mod_key, &config_.binds); | 2410 | let mods_with_mouse_binds = mods_with_mouse_binds(mod_key, &config_.binds); |
| 2408 | let mods_with_wheel_binds = mods_with_wheel_binds(mod_key, &config_.binds); | 2411 | let mods_with_wheel_binds = mods_with_wheel_binds(mod_key, &config_.binds); |
| 2409 | let mods_with_finger_scroll_binds = mods_with_finger_scroll_binds(mod_key, &config_.binds); | 2412 | let mods_with_finger_scroll_binds = mods_with_finger_scroll_binds(mod_key, &config_.binds); |
| 2413 | + let mods_with_tablet_stylus_binds = mods_with_tablet_stylus_binds(mod_key, &config_.binds); | ||
| 2410 | 2414 | ||
| 2411 | let screenshot_ui = ScreenshotUi::new(animation_clock.clone(), config.clone()); | 2415 | let screenshot_ui = ScreenshotUi::new(animation_clock.clone(), config.clone()); |
| 2412 | let window_mru_ui = WindowMruUi::new(config.clone()); | 2416 | let window_mru_ui = WindowMruUi::new(config.clone()); |
| @@ -2588,6 +2592,7 @@ impl Niri { | |||
| 2588 | horizontal_wheel_tracker: ScrollTracker::new(120), | 2592 | horizontal_wheel_tracker: ScrollTracker::new(120), |
| 2589 | mods_with_mouse_binds, | 2593 | mods_with_mouse_binds, |
| 2590 | mods_with_wheel_binds, | 2594 | mods_with_wheel_binds, |
| 2595 | + mods_with_tablet_stylus_binds, | ||
| 2591 | 2596 | ||
| 2592 | // 10 is copied from Clutter: DISCRETE_SCROLL_STEP. | 2597 | // 10 is copied from Clutter: DISCRETE_SCROLL_STEP. |
| 2593 | vertical_finger_scroll_tracker: ScrollTracker::new(10), | 2598 | vertical_finger_scroll_tracker: ScrollTracker::new(10), |
src/ui/hotkey_overlay.rsmodified+3 -0
| @@ -560,6 +560,9 @@ fn key_name(screen_reader: bool, mod_key: ModKey, key: &Key) -> String { | |||
| 560 | Trigger::TouchpadScrollUp => String::from("Touchpad Scroll Up"), | 560 | Trigger::TouchpadScrollUp => String::from("Touchpad Scroll Up"), |
| 561 | Trigger::TouchpadScrollLeft => String::from("Touchpad Scroll Left"), | 561 | Trigger::TouchpadScrollLeft => String::from("Touchpad Scroll Left"), |
| 562 | Trigger::TouchpadScrollRight => String::from("Touchpad Scroll Right"), | 562 | Trigger::TouchpadScrollRight => String::from("Touchpad Scroll Right"), |
| 563 | + Trigger::TabletStylusButton1 => String::from("Tablet Stylus Button 1"), | ||
| 564 | + Trigger::TabletStylusButton2 => String::from("Tablet Stylus Button 2"), | ||
| 565 | + Trigger::TabletStylusButton3 => String::from("Tablet Stylus Button 3"), | ||
| 563 | }; | 566 | }; |
| 564 | name.push_str(&pretty); | 567 | name.push_str(&pretty); |
| 565 | 568 | ||