chore: remove platform FingerId

The same as for `WindowId`.
This commit is contained in:
Kirill Chibisov 2024-10-15 17:26:43 +03:00
parent c8c1eca3c7
commit edfb4b03f4
20 changed files with 71 additions and 172 deletions

View file

@ -17,16 +17,6 @@ mod state;
mod types;
mod window;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FingerId(i32);
impl FingerId {
#[cfg(test)]
pub const fn dummy() -> Self {
FingerId(0)
}
}
/// Get the WindowId out of the surface.
#[inline]
fn make_wid(surface: &WlSurface) -> WindowId {

View file

@ -8,9 +8,9 @@ use sctk::seat::touch::{TouchData, TouchHandler};
use tracing::warn;
use crate::dpi::LogicalPosition;
use crate::event::{ButtonSource, ElementState, PointerKind, PointerSource, WindowEvent};
use crate::event::{ButtonSource, ElementState, FingerId, PointerKind, PointerSource, WindowEvent};
use crate::platform_impl::wayland;
use crate::platform_impl::wayland::state::WinitState;
use crate::platform_impl::wayland::{self, FingerId};
impl TouchHandler for WinitState {
fn down(
@ -40,12 +40,15 @@ impl TouchHandler for WinitState {
// Update the state of the point.
let location = LogicalPosition::<f64>::from(position);
// Only update primary finger once we don't have any touch.
if seat_state.touch_map.is_empty() {
seat_state.first_touch_id = Some(id);
}
let primary = seat_state.first_touch_id == Some(id);
seat_state.touch_map.insert(id, TouchPoint { surface, location });
let primary = seat_state.first_touch_id.get_or_insert(id) == &id;
let position = location.to_physical(scale_factor);
let finger_id =
crate::event::FingerId(crate::platform_impl::FingerId::Wayland(FingerId(id)));
let finger_id = FingerId::from_raw(id as usize);
self.events_sink.push_window_event(
WindowEvent::PointerEntered {
@ -93,7 +96,10 @@ impl TouchHandler for WinitState {
// Update the primary touch point.
let primary = seat_state.first_touch_id == Some(id);
if primary {
// Reset primary finger once all the other fingers are lifted to not transfer primary
// finger to some other finger and still accept it when it's briefly moved between the
// windows.
if seat_state.touch_map.is_empty() {
seat_state.first_touch_id = None;
}
@ -104,8 +110,7 @@ impl TouchHandler for WinitState {
};
let position = touch_point.location.to_physical(scale_factor);
let finger_id =
crate::event::FingerId(crate::platform_impl::FingerId::Wayland(FingerId(id)));
let finger_id = FingerId::from_raw(id as usize);
self.events_sink.push_window_event(
WindowEvent::PointerButton {
@ -167,9 +172,7 @@ impl TouchHandler for WinitState {
primary,
position: touch_point.location.to_physical(scale_factor),
source: PointerSource::Touch {
finger_id: crate::event::FingerId(crate::platform_impl::FingerId::Wayland(
FingerId(id),
)),
finger_id: FingerId::from_raw(id as usize),
force: None,
},
},
@ -201,9 +204,7 @@ impl TouchHandler for WinitState {
device_id: None,
primary,
position: Some(position),
kind: PointerKind::Touch(crate::event::FingerId(
crate::platform_impl::FingerId::Wayland(FingerId(id)),
)),
kind: PointerKind::Touch(FingerId::from_raw(id as usize)),
},
window_id,
);