Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect mouse side buttons #72

Merged
merged 2 commits into from
Oct 22, 2023
Merged
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
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 @@
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,

Check failure on line 281 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / all

no variant or associated item named `Back` found for enum `winit::event::MouseButton` in the current scope

Check failure on line 281 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / web

no variant or associated item named `Back` found for enum `MouseButton` in the current scope

Check failure on line 281 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / native (macOS-latest, beta)

no variant or associated item named `Back` found for enum `MouseButton` in the current scope
winit::event::MouseButton::Forward => mouse::Button::Forward,

Check failure on line 282 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / all

no variant or associated item named `Forward` found for enum `winit::event::MouseButton` in the current scope

Check failure on line 282 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / web

no variant or associated item named `Forward` found for enum `MouseButton` in the current scope

Check failure on line 282 in winit/src/conversion.rs

View workflow job for this annotation

GitHub Actions / native (macOS-latest, beta)

no variant or associated item named `Forward` found for enum `MouseButton` in the current scope
winit::event::MouseButton::Other(other) => mouse::Button::Other(other),
}
}
Expand Down
Loading