From 9798d3ca8627962e38015ba993bfa52202524d2a Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 22 Nov 2022 15:39:49 +0100 Subject: [PATCH] Support horizontal scrolling on X11 This was previously bound to the mouse forwards/back buttons (canonically mouse 4 and 5). --- src/x11/window.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/x11/window.rs b/src/x11/window.rs index 5678fbd..2ad0cad 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -596,20 +596,17 @@ impl Window { let detail = event.detail(); match detail { - 4 => { + 4..=7 => { handler.on_event( &mut crate::Window::new(self), Event::Mouse(MouseEvent::WheelScrolled { - delta: ScrollDelta::Lines { x: 0.0, y: 1.0 }, - modifiers: key_mods(event.state()), - }), - ); - } - 5 => { - handler.on_event( - &mut crate::Window::new(self), - Event::Mouse(MouseEvent::WheelScrolled { - delta: ScrollDelta::Lines { x: 0.0, y: -1.0 }, + delta: match detail { + 4 => ScrollDelta::Lines { x: 0.0, y: 1.0 }, + 5 => ScrollDelta::Lines { x: 0.0, y: -1.0 }, + 6 => ScrollDelta::Lines { x: -1.0, y: 0.0 }, + 7 => ScrollDelta::Lines { x: 1.0, y: 0.0 }, + _ => unreachable!(), + }, modifiers: key_mods(event.state()), }), ); @@ -631,7 +628,7 @@ impl Window { let event = unsafe { xcb::cast_event::(&event) }; let detail = event.detail(); - if detail != 4 && detail != 5 { + if !(4..=7).contains(&detail) { let button_id = mouse_id(detail); handler.on_event( &mut crate::Window::new(self),