From c5620efc9c5f44f9755a64359bb9fee9f92a4ded Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Wed, 9 Dec 2020 23:11:25 +0300 Subject: [PATCH] On Wayland, don't drop extra mouse buttons This commit forwards "unknown" Wayland mouse buttons downstream via 'MouseButton::Other'. Possible values for those could be found in . Also, since Wayland just forwards buttons from the kernel, which are 'u16', we must adjust 'MouseButton::Other' to take 'u16' instead of 'u8'. --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- src/event.rs | 2 +- .../linux/wayland/seat/pointer/handlers.rs | 14 +++++++++----- src/platform_impl/linux/x11/event_processor.rs | 2 +- src/platform_impl/windows/event_loop.rs | 4 ++-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9946438c..d6372d4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ - On Wayland, default font size in CSD increased from 11 to 17. - On Windows, fix bug causing message boxes to appear delayed. - On Android, support multi-touch. +- On Wayland, extra mouse buttons are not dropped anymore. +- **Breaking**: `MouseButton::Other` now uses `u16`. # 0.23.0 (2020-10-02) diff --git a/Cargo.toml b/Cargo.toml index 6a316d0c..f501f8c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ raw-window-handle = "0.3" bitflags = "1" [dev-dependencies] -image = "0.23" +image = "0.23.12" simple_logger = "1.9" [target.'cfg(target_os = "android")'.dependencies] diff --git a/src/event.rs b/src/event.rs index 5d89c7db..f39ddaac 100644 --- a/src/event.rs +++ b/src/event.rs @@ -745,7 +745,7 @@ pub enum MouseButton { Left, Right, Middle, - Other(u8), + Other(u16), } /// Describes a difference in the mouse scroll wheel state. diff --git a/src/platform_impl/linux/wayland/seat/pointer/handlers.rs b/src/platform_impl/linux/wayland/seat/pointer/handlers.rs index 06165a49..7d291713 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/handlers.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/handlers.rs @@ -17,6 +17,11 @@ use crate::platform_impl::wayland::{self, DeviceId}; use super::{PointerData, WinitPointer}; +// These values are comming from . +const BTN_LEFT: u32 = 0x110; +const BTN_RIGHT: u32 = 0x111; +const BTN_MIDDLE: u32 = 0x112; + #[inline] pub(super) fn handle_pointer( pointer: ThemedPointer, @@ -153,11 +158,10 @@ pub(super) fn handle_pointer( }; let button = match button { - 0x110 => MouseButton::Left, - 0x111 => MouseButton::Right, - 0x112 => MouseButton::Middle, - // TODO - figure out the translation. - _ => return, + BTN_LEFT => MouseButton::Left, + BTN_RIGHT => MouseButton::Right, + BTN_MIDDLE => MouseButton::Middle, + button => MouseButton::Other(button as u16), }; event_sink.push_window_event( diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index ab87d76d..65ed4d9f 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -709,7 +709,7 @@ impl EventProcessor { event: MouseInput { device_id, state, - button: Other(x as u8), + button: Other(x as u16), modifiers, }, }), diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index a6794e4e..6b3d287a 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -1307,7 +1307,7 @@ unsafe extern "system" fn public_window_callback( event: MouseInput { device_id: DEVICE_ID, state: Pressed, - button: Other(xbutton as u8), + button: Other(xbutton), modifiers: event::get_key_mods(), }, }); @@ -1329,7 +1329,7 @@ unsafe extern "system" fn public_window_callback( event: MouseInput { device_id: DEVICE_ID, state: Released, - button: Other(xbutton as u8), + button: Other(xbutton), modifiers: event::get_key_mods(), }, });