Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions niri-config/src/binds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub enum Trigger {
TouchpadScrollUp,
TouchpadScrollLeft,
TouchpadScrollRight,
TabletStylusButton1,
TabletStylusButton2,
TabletStylusButton3,
}

bitflags! {
Expand Down Expand Up @@ -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
Expand Down
52 changes: 51 additions & 1 deletion src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3726,11 +3726,49 @@ impl State {
}

fn on_tablet_tool_button<I: InputBackend>(&mut self, event: I::TabletToolButtonEvent) {
const BTN_STYLUS3: u32 = 0x149;
const BTN_STYLUS: u32 = 0x14b;
const BTN_STYLUS2: u32 = 0x14c;
Comment thread
youssefadly237 marked this conversation as resolved.

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());
Comment thread
youssefadly237 marked this conversation as resolved.
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)
};
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(),
Expand Down Expand Up @@ -5020,6 +5058,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<Modifiers> {
mods_with_binds(
mod_key,
binds,
&[
Trigger::TabletStylusButton1,
Trigger::TabletStylusButton2,
Trigger::TabletStylusButton3,
],
)
}

fn grab_allows_hot_corner(grab: &(dyn PointerGrab<State> + 'static)) -> bool {
let grab = grab.as_any();

Expand Down
7 changes: 6 additions & 1 deletion src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,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;
Expand Down Expand Up @@ -375,6 +375,7 @@ pub struct Niri {
pub horizontal_wheel_tracker: ScrollTracker,
pub mods_with_mouse_binds: HashSet<Modifiers>,
pub mods_with_wheel_binds: HashSet<Modifiers>,
pub mods_with_tablet_stylus_binds: HashSet<Modifiers>,
pub vertical_finger_scroll_tracker: ScrollTracker,
pub horizontal_finger_scroll_tracker: ScrollTracker,
pub mods_with_finger_scroll_binds: HashSet<Modifiers>,
Expand Down Expand Up @@ -1523,6 +1524,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);
}
Expand Down Expand Up @@ -2395,6 +2398,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);
Comment thread
youssefadly237 marked this conversation as resolved.

let screenshot_ui = ScreenshotUi::new(animation_clock.clone(), config.clone());
let window_mru_ui = WindowMruUi::new(config.clone());
Expand Down Expand Up @@ -2576,6 +2580,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),
Expand Down
3 changes: 3 additions & 0 deletions src/ui/hotkey_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down