From 41070d7c67d0e37dedf4b1bfb93a34c2c2e3e381 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 15 Jan 2024 21:51:01 +0100 Subject: [PATCH] Make DeviceId simpler on iOS (#3402) This previously contained a UIScreen for some weird reason; perhaps because `DeviceId` was confused for `UIDevice`? --- src/platform_impl/ios/mod.rs | 19 +++++++++---------- src/platform_impl/ios/view.rs | 9 +++------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index f5898bbf..7f8c23fc 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -68,6 +68,8 @@ mod window; use std::fmt; +use crate::event::DeviceId as RootDeviceId; + pub(crate) use self::{ event_loop::{ EventLoop, EventLoopProxy, EventLoopWindowTarget, OwnedDisplayHandle, @@ -76,28 +78,25 @@ pub(crate) use self::{ monitor::{MonitorHandle, VideoModeHandle}, window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId}, }; - -use self::uikit::UIScreen; pub(crate) use crate::cursor::NoCustomCursor as PlatformCustomCursor; pub(crate) use crate::cursor::NoCustomCursor as PlatformCustomCursorBuilder; pub(crate) use crate::icon::NoIcon as PlatformIcon; pub(crate) use crate::platform_impl::Fullscreen; +/// There is no way to detect which device that performed a certain event in +/// UIKit (i.e. you can't differentiate between different external keyboards, +/// or wether it was the main touchscreen, assistive technologies, or some +/// other pointer device that caused a touch event). #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct DeviceId { - uiscreen: *const UIScreen, -} +pub struct DeviceId; impl DeviceId { pub const unsafe fn dummy() -> Self { - DeviceId { - uiscreen: std::ptr::null(), - } + DeviceId } } -unsafe impl Send for DeviceId {} -unsafe impl Sync for DeviceId {} +pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct KeyEventExtra {} diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 5a93ad78..d7573f3a 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -17,12 +17,12 @@ use super::uikit::{ use super::window::WindowId; use crate::{ dpi::PhysicalPosition, - event::{DeviceId as RootDeviceId, Event, Force, Touch, TouchPhase, WindowEvent}, + event::{Event, Force, Touch, TouchPhase, WindowEvent}, platform::ios::ValidOrientations, platform_impl::platform::{ ffi::{UIRectEdge, UIUserInterfaceIdiom}, window::PlatformSpecificWindowBuilderAttributes, - DeviceId, Fullscreen, + Fullscreen, DEVICE_ID, }, window::{WindowAttributes, WindowId as RootWindowId}, }; @@ -199,7 +199,6 @@ impl WinitView { fn handle_touches(&self, touches: &NSSet) { let window = self.window().unwrap(); - let uiscreen = window.screen(); let mut touch_events = Vec::new(); let os_supports_force = app_state::os_capabilities().force_touch; for touch in touches { @@ -252,9 +251,7 @@ impl WinitView { touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { window_id: RootWindowId(window.id()), event: WindowEvent::Touch(Touch { - device_id: RootDeviceId(DeviceId { - uiscreen: Id::as_ptr(&uiscreen), - }), + device_id: DEVICE_ID, id: touch_id, location: physical_location, force,