diff --git a/niri-config/src/binds.rs b/niri-config/src/binds.rs index 0be7596f..e1a6a546 100644 --- a/niri-config/src/binds.rs +++ b/niri-config/src/binds.rs @@ -52,6 +52,9 @@ pub enum Trigger { TouchpadScrollUp, TouchpadScrollLeft, TouchpadScrollRight, + TabletStylusButton1, + TabletStylusButton2, + TabletStylusButton3, } bitflags! { @@ -1000,6 +1003,12 @@ impl FromStr for Key { Trigger::TouchpadScrollLeft } else if key.eq_ignore_ascii_case("TouchpadScrollRight") { Trigger::TouchpadScrollRight + } else if key.eq_ignore_ascii_case("TabletStylusButton1") { + Trigger::TabletStylusButton1 + } else if key.eq_ignore_ascii_case("TabletStylusButton2") { + Trigger::TabletStylusButton2 + } else if key.eq_ignore_ascii_case("TabletStylusButton3") { + Trigger::TabletStylusButton3 } else { let mut keysym = keysym_from_name(key, KEYSYM_CASE_INSENSITIVE); // The keyboard event handling code can receive either diff --git a/src/input/mod.rs b/src/input/mod.rs index 3e673bdb..50567530 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -3778,11 +3778,53 @@ impl State { } fn on_tablet_tool_button(&mut self, event: I::TabletToolButtonEvent) { + const BTN_STYLUS3: u32 = 0x149; + const BTN_STYLUS: u32 = 0x14b; + const BTN_STYLUS2: u32 = 0x14c; + let tool = self.niri.seat.tablet_seat().get_tool(&event.tool()); if let Some(tool) = tool { + let button = event.button(); + + if self.niri.suppressed_buttons.remove(&button) { + return; + } + + let trigger = match button { + BTN_STYLUS => Some(Trigger::TabletStylusButton1), + BTN_STYLUS2 => Some(Trigger::TabletStylusButton2), + BTN_STYLUS3 => Some(Trigger::TabletStylusButton3), + _ => None, + }; + + if let Some(trigger) = trigger { + if event.button_state() == ButtonState::Pressed { + let mod_key = self.backend.mod_key(&self.niri.config.borrow()); + let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); + let modifiers = modifiers_from_state(mods); + + if self.niri.mods_with_tablet_stylus_binds.contains(&modifiers) { + let bind = { + let config = self.niri.config.borrow(); + let bindings = config.binds.0.iter(); + find_configured_bind(bindings, mod_key, trigger, mods) + } + .filter(|bind| { + !self.niri.screenshot_ui.is_open() + || allowed_during_screenshot(&bind.action) + }); + if let Some(bind) = bind { + self.niri.suppressed_buttons.insert(button); + self.handle_bind(bind.clone()); + return; + } + } + } + } + tool.button( - event.button(), + button, event.button_state(), SERIAL_COUNTER.next_serial(), event.time_msec(), @@ -5069,6 +5111,18 @@ pub fn mods_with_finger_scroll_binds(mod_key: ModKey, binds: &Binds) -> HashSet< ) } +pub fn mods_with_tablet_stylus_binds(mod_key: ModKey, binds: &Binds) -> HashSet { + mods_with_binds( + mod_key, + binds, + &[ + Trigger::TabletStylusButton1, + Trigger::TabletStylusButton2, + Trigger::TabletStylusButton3, + ], + ) +} + fn grab_allows_hot_corner(grab: &(dyn PointerGrab + 'static)) -> bool { let grab = grab.as_any(); diff --git a/src/niri.rs b/src/niri.rs index a4150893..0eb68e05 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -134,7 +134,7 @@ use crate::input::scroll_swipe_gesture::ScrollSwipeGesture; use crate::input::scroll_tracker::ScrollTracker; use crate::input::{ apply_libinput_settings, mods_with_finger_scroll_binds, mods_with_mouse_binds, - mods_with_wheel_binds, TabletData, + mods_with_tablet_stylus_binds, mods_with_wheel_binds, TabletData, }; use crate::ipc::server::IpcServer; use crate::layer::mapped::LayerSurfaceRenderElement; @@ -376,6 +376,7 @@ pub struct Niri { pub horizontal_wheel_tracker: ScrollTracker, pub mods_with_mouse_binds: HashSet, pub mods_with_wheel_binds: HashSet, + pub mods_with_tablet_stylus_binds: HashSet, pub vertical_finger_scroll_tracker: ScrollTracker, pub horizontal_finger_scroll_tracker: ScrollTracker, pub mods_with_finger_scroll_binds: HashSet, @@ -1534,6 +1535,8 @@ impl State { .on_hotkey_config_updated(new_mod_key); self.niri.mods_with_mouse_binds = mods_with_mouse_binds(new_mod_key, &config.binds); self.niri.mods_with_wheel_binds = mods_with_wheel_binds(new_mod_key, &config.binds); + self.niri.mods_with_tablet_stylus_binds = + mods_with_tablet_stylus_binds(new_mod_key, &config.binds); self.niri.mods_with_finger_scroll_binds = mods_with_finger_scroll_binds(new_mod_key, &config.binds); } @@ -2407,6 +2410,7 @@ impl Niri { let mods_with_mouse_binds = mods_with_mouse_binds(mod_key, &config_.binds); let mods_with_wheel_binds = mods_with_wheel_binds(mod_key, &config_.binds); let mods_with_finger_scroll_binds = mods_with_finger_scroll_binds(mod_key, &config_.binds); + let mods_with_tablet_stylus_binds = mods_with_tablet_stylus_binds(mod_key, &config_.binds); let screenshot_ui = ScreenshotUi::new(animation_clock.clone(), config.clone()); let window_mru_ui = WindowMruUi::new(config.clone()); @@ -2588,6 +2592,7 @@ impl Niri { horizontal_wheel_tracker: ScrollTracker::new(120), mods_with_mouse_binds, mods_with_wheel_binds, + mods_with_tablet_stylus_binds, // 10 is copied from Clutter: DISCRETE_SCROLL_STEP. vertical_finger_scroll_tracker: ScrollTracker::new(10), diff --git a/src/ui/hotkey_overlay.rs b/src/ui/hotkey_overlay.rs index b8fdca13..34bc3955 100644 --- a/src/ui/hotkey_overlay.rs +++ b/src/ui/hotkey_overlay.rs @@ -560,6 +560,9 @@ fn key_name(screen_reader: bool, mod_key: ModKey, key: &Key) -> String { Trigger::TouchpadScrollUp => String::from("Touchpad Scroll Up"), Trigger::TouchpadScrollLeft => String::from("Touchpad Scroll Left"), Trigger::TouchpadScrollRight => String::from("Touchpad Scroll Right"), + Trigger::TabletStylusButton1 => String::from("Tablet Stylus Button 1"), + Trigger::TabletStylusButton2 => String::from("Tablet Stylus Button 2"), + Trigger::TabletStylusButton3 => String::from("Tablet Stylus Button 3"), }; name.push_str(&pretty);