From 4fb3ba214beb5112966752bcf44f9e6e6727b4f9 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 9 Mar 2026 18:20:52 -0700 Subject: [PATCH] winit: Fix `cursor_position` for touch events Some widgets check the cursor position when handling the touch down event, so we need to make sure `cursor_position` is set then, and not only when there is a touch move event. Simply always setting it for `WindowEvent::PointerButton` (for touch or mouse input) seems reasonable. We also need to avoid clearing `cursor_position` for `PointerLeft` with a touch device. Do that only for mouse input. Ideally Iced would handle touch input without tying to `cursor_position`, but this should match the behavior of upstream Iced. This seems to fix regressions since the Iced rebase in the `tour` example, and in `cosmic-files`. `cosmic-files` seems to have some issue using the menus with a touch device, but that doesn't seem to be a regression. --- winit/src/window/state.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/winit/src/window/state.rs b/winit/src/window/state.rs index 33179a68..aedbc705 100644 --- a/winit/src/window/state.rs +++ b/winit/src/window/state.rs @@ -5,7 +5,7 @@ use crate::graphics::Viewport; use crate::program::{self, Program}; use winit::dpi::LogicalPosition; -use winit::event::WindowEvent; +use winit::event::{PointerKind, WindowEvent}; use winit::window::Window; use std::fmt::{Debug, Formatter}; @@ -184,10 +184,10 @@ where } => { self.update_scale_factor(*new_scale_factor); } - WindowEvent::PointerMoved { position, .. } => { + WindowEvent::PointerMoved { position, .. } | WindowEvent::PointerButton { position, .. } => { self.cursor_position = Some(*position); } - WindowEvent::PointerLeft { .. } => { + WindowEvent::PointerLeft { kind: PointerKind::Mouse, .. } => { self.cursor_position = None; } WindowEvent::ModifiersChanged(new_modifiers) => {