From af152f7f3ead8625a0bcef2299a239273a88aa46 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 10 Apr 2022 01:54:16 +0200 Subject: [PATCH] autocommit 2022-04-10 01:54:16 CEST --- src/backends/metal/input.rs | 2 +- src/backends/x.rs | 3 ++- src/ifs/wl_seat.rs | 2 ++ src/ifs/wl_surface.rs | 4 ++-- src/tree.rs | 2 +- src/tree/container.rs | 41 +++++++++++++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/backends/metal/input.rs b/src/backends/metal/input.rs index e31bd625..a822b1eb 100644 --- a/src/backends/metal/input.rs +++ b/src/backends/metal/input.rs @@ -14,6 +14,7 @@ use { }, std::rc::Rc, }; +use crate::ifs::wl_seat::PX_PER_SCROLL; macro_rules! unpack { ($slf:expr, $ev:expr) => {{ @@ -121,7 +122,6 @@ impl MetalBackend { } fn handle_pointer_axis(self: &Rc, event: LibInputEvent, source: AxisSource) { - const PX_PER_SCROLL: f64 = 15.0; const ONE_TWENTRY: f64 = 120.0; let (event, dev) = unpack!(self, event, pointer_event); let axes = [ diff --git a/src/backends/x.rs b/src/backends/x.rs index 8016864e..3318882d 100644 --- a/src/backends/x.rs +++ b/src/backends/x.rs @@ -54,6 +54,7 @@ use { }, thiserror::Error, }; +use crate::ifs::wl_seat::PX_PER_SCROLL; #[derive(Debug, Error)] pub enum XBackendError { @@ -729,7 +730,7 @@ impl XBackendData { }; seat.mouse_event(InputEvent::AxisSource(AxisSource::Wheel)); seat.mouse_event(InputEvent::AxisDiscrete(val, axis)); - seat.mouse_event(InputEvent::Axis(Fixed::from_int(val * 15), axis)); + seat.mouse_event(InputEvent::Axis((val as f64 * PX_PER_SCROLL).into(), axis)); seat.mouse_event(InputEvent::Frame); } } else { diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index f09dfdff..6edda577 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -74,6 +74,8 @@ pub const BTN_LEFT: u32 = 0x110; pub const SEAT_NAME_SINCE: u32 = 2; +pub const PX_PER_SCROLL: f64 = 15.0; + #[derive(Clone)] pub struct Dnd { pub seat: Rc, diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index 074f7bd7..d82548af 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -799,8 +799,8 @@ impl Node for WlSurface { seat.button_surface(&self, button, state); } - fn axis_event(&self, seat: &WlSeatGlobal, event: &PendingScroll) { - seat.scroll_surface(self, event); + fn axis_event(self: Rc, seat: &WlSeatGlobal, event: &PendingScroll) { + seat.scroll_surface(&*self, event); } fn focus(self: Rc, seat: &Rc) { diff --git a/src/tree.rs b/src/tree.rs index 76da4973..72f169d6 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -197,7 +197,7 @@ pub trait Node { let _ = state; } - fn axis_event(&self, seat: &WlSeatGlobal, event: &PendingScroll) { + fn axis_event(self: Rc, seat: &WlSeatGlobal, event: &PendingScroll) { let _ = seat; let _ = event; } diff --git a/src/tree/container.rs b/src/tree/container.rs index 5d39be37..a6cc463c 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -32,6 +32,8 @@ use { rc::Rc, }, }; +use crate::ifs::wl_seat::PX_PER_SCROLL; +use crate::ifs::wl_seat::wl_pointer::{PendingScroll, VERTICAL_SCROLL}; #[allow(dead_code)] #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -111,6 +113,7 @@ pub struct ContainerNode { state: Rc, pub render_data: RefCell, visible: Cell, + scroll: Cell, } impl Debug for ContainerNode { @@ -209,6 +212,7 @@ impl ContainerNode { state: state.clone(), render_data: Default::default(), visible: Cell::new(false), + scroll: Cell::new(0.0), }); child.set_parent(slf.clone()); slf @@ -1044,6 +1048,43 @@ impl Node for ContainerNode { } } + fn axis_event(self: Rc, seat: &WlSeatGlobal, event: &PendingScroll) { + let mut seat_datas = self.seats.borrow_mut(); + let seat_data = match seat_datas.get_mut(&seat.id()) { + Some(s) => s, + _ => return, + }; + if seat_data.y > self.state.theme.title_height.get() { + return; + } + let cur_mc = match self.mono_child.get() { + Some(mc) => mc, + _ => return, + }; + let scroll = match event.axis[VERTICAL_SCROLL as usize].get() { + Some(s) => s, + _ => return, + }; + let mut scroll = self.scroll.get() + f64::from(scroll); + let discrete = (scroll / PX_PER_SCROLL).round(); + scroll -= discrete * PX_PER_SCROLL; + self.scroll.set(scroll); + let discrete = discrete as i32; + let mut new_mc = cur_mc.clone(); + for _ in 0..discrete.abs() { + let new = if discrete < 0 { + new_mc.prev() + } else { + new_mc.next() + }; + new_mc = match new { + Some(n) => n, + None => break, + }; + } + self.activate_child(&new_mc); + } + fn focus_parent(&self, seat: &Rc) { self.parent.get().focus_self(seat); }