Skip to content

Commit

Permalink
feat: Add side mouse button events
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz authored Oct 22, 2023
1 parent c716df2 commit a9bddc5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Detect mouse side buttons.

Many thanks to...
- @edfloreshz
- @jackpot51
- @wash2

Expand Down
6 changes: 6 additions & 0 deletions core/src/mouse/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub enum Button {
/// The middle (wheel) button.
Middle,

/// The side button often used as "back" in web browsers.
Back,

/// The side button often used as "forward" in web browsers.
Forward,

/// Some other button.
Other(u16),
}
9 changes: 8 additions & 1 deletion sctk/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use sctk::{
reexports::client::protocol::wl_pointer::AxisSource,
seat::{
keyboard::Modifiers,
pointer::{AxisScroll, CursorIcon, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT},
pointer::{
AxisScroll, CursorIcon, BTN_EXTRA, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT,
BTN_SIDE,
},
},
};
use xkeysym::{key, RawKeysym};
Expand Down Expand Up @@ -83,6 +86,10 @@ pub fn pointer_button_to_native(button: u32) -> Option<mouse::Button> {
Some(mouse::Button::Right)
} else if button == BTN_MIDDLE {
Some(mouse::Button::Middle)
} else if button == BTN_SIDE {
Some(mouse::Button::Back)
} else if button == BTN_EXTRA {
Some(mouse::Button::Forward)
} else {
button.try_into().ok().map(mouse::Button::Other)
}
Expand Down
2 changes: 2 additions & 0 deletions winit/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
winit::event::MouseButton::Left => mouse::Button::Left,
winit::event::MouseButton::Right => mouse::Button::Right,
winit::event::MouseButton::Middle => mouse::Button::Middle,
winit::event::MouseButton::Back => mouse::Button::Back,
winit::event::MouseButton::Forward => mouse::Button::Forward,
winit::event::MouseButton::Other(other) => mouse::Button::Other(other),
}
}
Expand Down

0 comments on commit a9bddc5

Please sign in to comment.