From e3577fc5283709ea9f3d891f97b82e1bf50994a0 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Wed, 17 Jun 2026 11:01:29 -0600 Subject: [PATCH] =?UTF-8?q?feat(slint):=20winit=20input=20hook=20=E2=80=94?= =?UTF-8?q?=20mouse=20back/forward=20nav=20+=20global=20pointer=20mirror?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop to the winit backend (on_winit_window_event) to (1) route the browser Back/Forward mouse buttons to navigation before Slint hands them to the topmost TouchArea, so cards/sidebar rows no longer swallow them, and (2) mirror the cursor position into ShellState (pointer-x/y/in-window) so passive hover chrome can react without installing a TouchArea over interactive content. This is the seam that unblocks the auto-hide scrollbars. cx --- crates/qbz-slint/src/main.rs | 60 +++++++++++++++++++++++++++++++++ crates/qbz-slint/ui/state.slint | 6 ++++ 2 files changed, 66 insertions(+) diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 034bf524d..d9d73f092 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -104,6 +104,10 @@ mod ui_prefs; use std::sync::Arc; +use i_slint_backend_winit::{ + winit::event::{ElementState, MouseButton, WindowEvent}, + EventResult, WinitWindowAccessor, +}; use slint::Model; use adapter::SlintAdapter; @@ -577,6 +581,61 @@ fn update_nav_flags(window: &AppWindow) { state.set_can_forward(nav::can_forward()); } +/// Capture browser mouse buttons before Slint routes them to the topmost +/// TouchArea, and mirror the cursor position into `ShellState` for passive +/// hover chrome that must not install a TouchArea over interactive content. +/// Otherwise cards/sidebar rows can swallow Back/Forward while empty chrome +/// still works, and hover-only scrollbars cannot reliably see card hover. +fn install_browser_mouse_nav(window: &AppWindow) { + let weak = window.as_weak(); + window.window().on_winit_window_event(move |slint_window, event| { + match event { + WindowEvent::CursorMoved { position, .. } => { + let Some(window) = weak.upgrade() else { + return EventResult::Propagate; + }; + let position = position.to_logical::(slint_window.scale_factor() as f64); + let state = window.global::(); + state.set_pointer_x(position.x as f32); + state.set_pointer_y(position.y as f32); + state.set_pointer_in_window(true); + return EventResult::Propagate; + } + WindowEvent::CursorLeft { .. } => { + if let Some(window) = weak.upgrade() { + let state = window.global::(); + state.set_pointer_in_window(false); + state.set_pointer_x(-1.0); + state.set_pointer_y(-1.0); + } + return EventResult::Propagate; + } + WindowEvent::MouseInput { + state: ElementState::Pressed, + button, + .. + } => { + let Some(window) = weak.upgrade() else { + return EventResult::Propagate; + }; + + match button { + MouseButton::Back => { + window.global::().invoke_request_back(); + EventResult::PreventDefault + } + MouseButton::Forward => { + window.global::().invoke_request_forward(); + EventResult::PreventDefault + } + _ => EventResult::Propagate, + } + } + _ => EventResult::Propagate, + } + }); +} + /// Whether the CURRENT content view is one the AppShell swaps for the /// OfflinePlaceholder while offline. KEEP IN SYNC with `qobuz-view-blocked` /// in `AppShell.slint`. The playlist view blocks only when it is neither a @@ -3996,6 +4055,7 @@ fn main() -> Result<(), Box> { .select()?; let window = AppWindow::new()?; + install_browser_mouse_nav(&window); // FONT TEST (slint-mvp): render with bundled Inter 18pt. Inter is a // clean, screen-tuned UI face; combined with the femtovg #5177/#11335 // text fixes this is the candidate for the final look. Flip diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index 4d07fc84f..ee2c2fc01 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -3088,6 +3088,12 @@ export global ShellState { // NPB responsive breakpoint AND a right panel (Queue/Lyrics) is open. out property content-constrained: root.window-width < 1366px && (root.queue-open || root.lyrics-open); + // Global pointer position in window coords, fed from winit. Used by + // hover-only chrome that must not install a TouchArea over interactive + // content (for example auto-hide scrollbars over album cards). + in-out property pointer-in-window: false; + in-out property pointer-x: -1px; + in-out property pointer-y: -1px; // Section navigation placement: the sections (Discover/Library/Local // Library/My QBZ) now live in the sidebar and open right-flyout menus. in-out property nav-in-sidebar: true;