From ec9710983c8fe684fc3bb0aead6490fd68647e4e Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sat, 7 May 2022 18:06:55 +0200 Subject: [PATCH] tree: use trunc instead of round when scrolling containers --- src/ifs/wl_seat/wl_pointer.rs | 2 +- src/ifs/wl_surface/xdg_surface/xdg_popup.rs | 1 + .../wl_surface/xdg_surface/xdg_toplevel.rs | 1 + src/ifs/wl_surface/xwindow.rs | 1 + src/it/test_backend.rs | 7 +++ src/it/tests.rs | 2 + src/it/tests/t0014_container_scroll_focus.rs | 3 -- src/it/tests/t0015_scroll_partial.rs | 48 +++++++++++++++++++ src/tree.rs | 1 + src/tree/container.rs | 4 +- src/tree/display.rs | 1 + src/tree/float.rs | 1 + src/tree/output.rs | 3 +- src/tree/workspace.rs | 1 + 14 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 src/it/tests/t0015_scroll_partial.rs diff --git a/src/ifs/wl_seat/wl_pointer.rs b/src/ifs/wl_seat/wl_pointer.rs index 2d849dd4..2ff0bd91 100644 --- a/src/ifs/wl_seat/wl_pointer.rs +++ b/src/ifs/wl_seat/wl_pointer.rs @@ -34,7 +34,7 @@ pub const AXIS_DISCRETE_SINCE_VERSION: u32 = 5; pub const AXIS_STOP_SINCE_VERSION: u32 = 5; pub const WHEEL_TILT_SINCE_VERSION: u32 = 6; -#[derive(Default)] +#[derive(Default, Debug)] pub struct PendingScroll { pub discrete: [Cell>; 2], pub axis: [Cell>; 2], diff --git a/src/ifs/wl_surface/xdg_surface/xdg_popup.rs b/src/ifs/wl_surface/xdg_surface/xdg_popup.rs index 381a6fd7..29380b4a 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_popup.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_popup.rs @@ -321,6 +321,7 @@ impl Node for XdgPopup { } fn node_on_pointer_focus(&self, seat: &Rc) { + // log::info!("xdg-popup focus"); seat.set_known_cursor(KnownCursor::Default); } } diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs index 0ce99f04..d8aab2bf 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs @@ -426,6 +426,7 @@ impl Node for XdgToplevel { } fn node_on_pointer_focus(&self, seat: &Rc) { + // log::info!("xdg-toplevel focus"); seat.set_known_cursor(KnownCursor::Default); } } diff --git a/src/ifs/wl_surface/xwindow.rs b/src/ifs/wl_surface/xwindow.rs index 3be3d619..dcbab7a5 100644 --- a/src/ifs/wl_surface/xwindow.rs +++ b/src/ifs/wl_surface/xwindow.rs @@ -374,6 +374,7 @@ impl Node for Xwindow { } fn node_on_pointer_focus(&self, seat: &Rc) { + // log::info!("wl-surface focus"); seat.set_known_cursor(KnownCursor::Default); } } diff --git a/src/it/test_backend.rs b/src/it/test_backend.rs index 8cd4f227..9fdbe9c0 100644 --- a/src/it/test_backend.rs +++ b/src/it/test_backend.rs @@ -302,6 +302,13 @@ impl TestBackendMouse { )); self.common.event(InputEvent::Frame); } + + pub fn scroll_px(&self, dy: i32) { + self.common.event(InputEvent::AxisSource(AxisSource::Wheel)); + self.common + .event(InputEvent::Axis(Fixed::from_int(dy), ScrollAxis::Vertical)); + self.common.event(InputEvent::Frame); + } } pub struct TestBackendKb { diff --git a/src/it/tests.rs b/src/it/tests.rs index 30895f79..30420f83 100644 --- a/src/it/tests.rs +++ b/src/it/tests.rs @@ -40,6 +40,7 @@ mod t0011_set_keymap; mod t0012_subsurface_focus; mod t0013_graphics_initialized; mod t0014_container_scroll_focus; +mod t0015_scroll_partial; pub trait TestCase: Sync { fn name(&self) -> &'static str; @@ -72,5 +73,6 @@ pub fn tests() -> Vec<&'static dyn TestCase> { t0012_subsurface_focus, t0013_graphics_initialized, t0014_container_scroll_focus, + t0015_scroll_partial, } } diff --git a/src/it/tests/t0014_container_scroll_focus.rs b/src/it/tests/t0014_container_scroll_focus.rs index e0c6a354..f01d63a3 100644 --- a/src/it/tests/t0014_container_scroll_focus.rs +++ b/src/it/tests/t0014_container_scroll_focus.rs @@ -48,7 +48,6 @@ async fn test(run: Rc) -> TestResult { let mono_container = w_mono2.tl.container_parent()?; let container_pos = mono_container.tl_data().pos.get(); - log::info!("cp {:?}", container_pos); let w_mono1_title = mono_container.render_data.borrow_mut().title_rects[0] .move_(container_pos.x1(), container_pos.y1()); ds.mouse.abs( @@ -63,8 +62,6 @@ async fn test(run: Rc) -> TestResult { ds.mouse.scroll(-1); client.sync().await; - client.save_screenshot("s2").await?; - let enter = enters.next().with_context(|| "no enter event 2")?; tassert_eq!(enter.surface, w_mono1.surface.id); diff --git a/src/it/tests/t0015_scroll_partial.rs b/src/it/tests/t0015_scroll_partial.rs new file mode 100644 index 00000000..82400489 --- /dev/null +++ b/src/it/tests/t0015_scroll_partial.rs @@ -0,0 +1,48 @@ +use { + crate::{ + it::{test_error::TestResult, testrun::TestRun}, + tree::ToplevelNode, + }, + std::rc::Rc, +}; + +testcase!(); + +async fn test(run: Rc) -> TestResult { + let ds = run.create_default_setup().await?; + ds.mouse.rel(1.0, 1.0); + + let client = run.create_client().await?; + let dss = client.get_default_seat().await?; + + let w_mono1 = client.create_window().await?; + w_mono1.map2().await?; + let w_mono2 = client.create_window().await?; + w_mono2.map2().await?; + + run.cfg.set_mono(ds.seat.id(), true)?; + + client.sync().await; + + let container = w_mono2.tl.container_parent()?; + let pos = container.tl_data().pos.get(); + let w_mono1_title = container.render_data.borrow_mut().title_rects[0].move_(pos.x1(), pos.y1()); + ds.mouse.abs( + &ds.connector, + w_mono1_title.x1() as f64, + w_mono1_title.y1() as f64, + ); + client.sync().await; + + let enters = dss.kb.enter.expect()?; + + ds.mouse.scroll_px(-14); + client.sync().await; + tassert!(enters.next().is_err()); + + ds.mouse.scroll_px(-1); + client.sync().await; + tassert!(enters.next().is_ok()); + + Ok(()) +} diff --git a/src/tree.rs b/src/tree.rs index 7b472cf0..709a648d 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -189,6 +189,7 @@ pub trait Node: 'static { } fn node_on_pointer_focus(&self, seat: &Rc) { + // log::info!("{} focus", std::any::type_name::()); let _ = seat; } diff --git a/src/tree/container.rs b/src/tree/container.rs index 9f171efc..5267b08c 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -1159,7 +1159,7 @@ impl Node for ContainerNode { d } else if let Some(scroll) = event.axis[VERTICAL_SCROLL as usize].get() { let mut scroll = self.scroll.get() + scroll.to_f64(); - let discrete = (scroll / PX_PER_SCROLL).round(); + let discrete = (scroll / PX_PER_SCROLL).trunc(); scroll -= discrete * PX_PER_SCROLL; self.scroll.set(scroll); discrete as i32 @@ -1191,6 +1191,7 @@ impl Node for ContainerNode { } fn node_on_pointer_unfocus(&self, seat: &Rc) { + // log::info!("unfocus"); let mut seats = self.seats.borrow_mut(); if let Some(seat_state) = seats.get_mut(&seat.id()) { seat_state.target = false; @@ -1198,6 +1199,7 @@ impl Node for ContainerNode { } fn node_on_pointer_focus(&self, seat: &Rc) { + // log::info!("container focus"); let mut seats = self.seats.borrow_mut(); if let Some(seat_state) = seats.get_mut(&seat.id()) { seat_state.target = true; diff --git a/src/tree/display.rs b/src/tree/display.rs index 6248bb24..878001f5 100644 --- a/src/tree/display.rs +++ b/src/tree/display.rs @@ -115,6 +115,7 @@ impl Node for DisplayNode { } fn node_on_pointer_focus(&self, seat: &Rc) { + // log::info!("display focus"); seat.set_known_cursor(KnownCursor::Default); } } diff --git a/src/tree/float.rs b/src/tree/float.rs index b007aa28..d28ebbd0 100644 --- a/src/tree/float.rs +++ b/src/tree/float.rs @@ -467,6 +467,7 @@ impl Node for FloatNode { } fn node_on_pointer_focus(&self, seat: &Rc) { + // log::info!("float focus"); let mut seats = self.seats.borrow_mut(); if let Some(seat_state) = seats.get_mut(&seat.id()) { seat_state.target = true; diff --git a/src/tree/output.rs b/src/tree/output.rs index 7a0f5cc6..e8d2e0c8 100644 --- a/src/tree/output.rs +++ b/src/tree/output.rs @@ -382,7 +382,7 @@ impl Node for OutputNode { } } let bar_height = self.state.theme.title_height.get() + 1; - if y > bar_height { + if y >= bar_height { y -= bar_height; let len = tree.len(); if let Some(ws) = self.workspace.get() { @@ -405,6 +405,7 @@ impl Node for OutputNode { } fn node_on_pointer_focus(&self, seat: &Rc) { + // log::info!("output focus"); seat.set_known_cursor(KnownCursor::Default); } diff --git a/src/tree/workspace.rs b/src/tree/workspace.rs index d2951295..10dbb7ab 100644 --- a/src/tree/workspace.rs +++ b/src/tree/workspace.rs @@ -130,6 +130,7 @@ impl Node for WorkspaceNode { } fn node_on_pointer_focus(&self, seat: &Rc) { + // log::info!("workspace focus"); seat.set_known_cursor(KnownCursor::Default); }