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.
This commit is contained in:
Ian Douglas Scott 2026-03-09 18:20:52 -07:00 committed by Ashley Wulber
parent 99bc455118
commit 4fb3ba214b

View file

@ -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) => {