Skip to content

Commit

Permalink
Supress mouse binds release events
Browse files Browse the repository at this point in the history
  • Loading branch information
bbb651 committed Dec 15, 2024
1 parent b7c0929 commit 36a6698
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ impl State {
let bindings = &config.binds;
find_configured_bind(bindings, comp_mod, trigger, mods)
}) {
self.niri.suppressed_buttons.insert(button_code);
self.handle_bind(bind.clone());
return;
};
Expand All @@ -1586,7 +1587,7 @@ impl State {
let window = mapped.window.clone();

// Check if we need to start an interactive move.
if event.button() == Some(MouseButton::Left) && !pointer.is_grabbed() {
if button == Some(MouseButton::Left) && !pointer.is_grabbed() {
let mod_down = match self.backend.mod_key() {
CompositorMod::Super => mods.logo,
CompositorMod::Alt => mods.alt,
Expand All @@ -1605,7 +1606,7 @@ impl State {
) {
let start_data = PointerGrabStartData {
focus: None,
button: event.button_code(),
button: button_code,
location,
};
let grab = MoveGrab::new(start_data, window.clone());
Expand All @@ -1617,7 +1618,7 @@ impl State {
}
}
// Check if we need to start an interactive resize.
else if event.button() == Some(MouseButton::Right) && !pointer.is_grabbed() {
else if button == Some(MouseButton::Right) && !pointer.is_grabbed() {
let mod_down = match self.backend.mod_key() {
CompositorMod::Super => mods.logo,
CompositorMod::Alt => mods.alt,
Expand Down Expand Up @@ -1669,7 +1670,7 @@ impl State {
{
let start_data = PointerGrabStartData {
focus: None,
button: event.button_code(),
button: button_code,
location,
};
let grab = ResizeGrab::new(start_data, window.clone());
Expand All @@ -1693,7 +1694,7 @@ impl State {
self.niri.queue_redraw_all();
}

if event.button() == Some(MouseButton::Middle) && !pointer.is_grabbed() {
if button == Some(MouseButton::Middle) && !pointer.is_grabbed() {
let mod_down = match self.backend.mod_key() {
CompositorMod::Super => mods.logo,
CompositorMod::Alt => mods.alt,
Expand All @@ -1703,7 +1704,7 @@ impl State {
let location = pointer.current_location();
let start_data = PointerGrabStartData {
focus: None,
button: event.button_code(),
button: button_code,
location,
};
let grab = SpatialMovementGrab::new(start_data, output);
Expand All @@ -1723,7 +1724,7 @@ impl State {
self.niri.focus_layer_surface_if_on_demand(layer_under);
}

if let Some(button) = event.button() {
if let Some(button) = button {
let pos = pointer.current_location();
if let Some((output, _)) = self.niri.output_under(pos) {
let output = output.clone();
Expand All @@ -1748,6 +1749,10 @@ impl State {
}
}

if self.niri.suppressed_buttons.remove(&button_code) {
return;
}

pointer.button(
self,
&ButtonEvent {
Expand Down
3 changes: 3 additions & 0 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ pub struct Niri {
pub seat: Seat<State>,
/// Scancodes of the keys to suppress.
pub suppressed_keys: HashSet<Keycode>,
/// Button codes of the mouse buttons to suppress.
pub suppressed_buttons: HashSet<u32>,
pub bind_cooldown_timers: HashMap<Key, RegistrationToken>,
pub bind_repeat_timer: Option<RegistrationToken>,
pub keyboard_focus: KeyboardFocus,
Expand Down Expand Up @@ -1969,6 +1971,7 @@ impl Niri {
popups: PopupManager::default(),
popup_grab: None,
suppressed_keys: HashSet::new(),
suppressed_buttons: HashSet::new(),
bind_cooldown_timers: HashMap::new(),
bind_repeat_timer: Option::default(),
presentation_state,
Expand Down

0 comments on commit 36a6698

Please sign in to comment.