From ece7569885d7cbdb69a594d37a0cca4b541cf567 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 9 Oct 2024 18:13:54 -0400 Subject: [PATCH 01/29] split surface from window, linux impl --- src/platform_impl/linux/wayland/window/mod.rs | 146 +++++---- src/platform_impl/linux/x11/window.rs | 70 ++-- src/window.rs | 309 ++++++++++-------- 3 files changed, 276 insertions(+), 249 deletions(-) diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index d555987918..c84e383ce6 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -25,7 +25,7 @@ use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::platform_impl::{Fullscreen, MonitorHandle as PlatformMonitorHandle}; use crate::window::{ Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme, - UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, WindowId, + UserAttentionType, Window as CoreWindow, Surface as CoreSurface, WindowAttributes, WindowButtons, WindowId, WindowLevel, }; @@ -272,11 +272,16 @@ impl rwh_06::HasDisplayHandle for Window { } } -impl CoreWindow for Window { +impl CoreSurface for Window { fn id(&self) -> WindowId { self.window_id } + #[inline] + fn scale_factor(&self) -> f64 { + self.window_state.lock().unwrap().scale_factor() + } + fn request_redraw(&self) { // NOTE: try to not wake up the loop when the event was already scheduled and not yet // processed by the loop, because if at this point the value was `true` it could only @@ -292,13 +297,77 @@ impl CoreWindow for Window { } } + fn pre_present_notify(&self) { + self.window_state.lock().unwrap().request_frame_callback(); + } + + fn surface_size(&self) -> PhysicalSize { + let window_state = self.window_state.lock().unwrap(); + let scale_factor = window_state.scale_factor(); + super::logical_to_physical_rounded(window_state.surface_size(), scale_factor) + } + + fn request_surface_size(&self, size: Size) -> Option> { + let mut window_state = self.window_state.lock().unwrap(); + let new_size = window_state.request_surface_size(size); + self.request_redraw(); + Some(new_size) + } + #[inline] - fn title(&self) -> String { - self.window_state.lock().unwrap().title().to_owned() + fn set_transparent(&self, transparent: bool) { + self.window_state.lock().unwrap().set_transparent(transparent); } + - fn pre_present_notify(&self) { - self.window_state.lock().unwrap().request_frame_callback(); + fn set_cursor(&self, cursor: Cursor) { + let window_state = &mut self.window_state.lock().unwrap(); + + match cursor { + Cursor::Icon(icon) => window_state.set_cursor(icon), + Cursor::Custom(cursor) => window_state.set_custom_cursor(cursor), + } + } + + fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { + let scale_factor = self.scale_factor(); + let position = position.to_logical(scale_factor); + self.window_state + .lock() + .unwrap() + .set_cursor_position(position) + // Request redraw on success, since the state is double buffered. + .map(|_| self.request_redraw()) + } + + fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> { + self.window_state.lock().unwrap().set_cursor_grab(mode) + } + + fn set_cursor_visible(&self, visible: bool) { + self.window_state.lock().unwrap().set_cursor_visible(visible); + } + + fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { + let surface = self.window.wl_surface(); + + if hittest { + surface.set_input_region(None); + Ok(()) + } else { + let region = Region::new(&*self.compositor).map_err(|err| os_error!(err))?; + region.add(0, 0, 0, 0); + surface.set_input_region(Some(region.wl_region())); + Ok(()) + } + } +} + +impl CoreWindow for Window { + + #[inline] + fn title(&self) -> String { + self.window_state.lock().unwrap().title().to_owned() } fn reset_dead_keys(&self) { @@ -319,19 +388,6 @@ impl CoreWindow for Window { // Not possible. } - fn surface_size(&self) -> PhysicalSize { - let window_state = self.window_state.lock().unwrap(); - let scale_factor = window_state.scale_factor(); - super::logical_to_physical_rounded(window_state.surface_size(), scale_factor) - } - - fn request_surface_size(&self, size: Size) -> Option> { - let mut window_state = self.window_state.lock().unwrap(); - let new_size = window_state.request_surface_size(size); - self.request_redraw(); - Some(new_size) - } - fn outer_size(&self) -> PhysicalSize { let window_state = self.window_state.lock().unwrap(); let scale_factor = window_state.scale_factor(); @@ -369,11 +425,6 @@ impl CoreWindow for Window { self.window_state.lock().unwrap().set_title(new_title); } - #[inline] - fn set_transparent(&self, transparent: bool) { - self.window_state.lock().unwrap().set_transparent(transparent); - } - fn set_visible(&self, _visible: bool) { // Not possible on Wayland. } @@ -472,11 +523,6 @@ impl CoreWindow for Window { } } - #[inline] - fn scale_factor(&self) -> f64 { - self.window_state.lock().unwrap().scale_factor() - } - #[inline] fn set_blur(&self, blur: bool) { self.window_state.lock().unwrap().set_blur(blur); @@ -565,34 +611,6 @@ impl CoreWindow for Window { fn set_content_protected(&self, _protected: bool) {} - fn set_cursor(&self, cursor: Cursor) { - let window_state = &mut self.window_state.lock().unwrap(); - - match cursor { - Cursor::Icon(icon) => window_state.set_cursor(icon), - Cursor::Custom(cursor) => window_state.set_custom_cursor(cursor), - } - } - - fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { - let scale_factor = self.scale_factor(); - let position = position.to_logical(scale_factor); - self.window_state - .lock() - .unwrap() - .set_cursor_position(position) - // Request redraw on success, since the state is double buffered. - .map(|_| self.request_redraw()) - } - - fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> { - self.window_state.lock().unwrap().set_cursor_grab(mode) - } - - fn set_cursor_visible(&self, visible: bool) { - self.window_state.lock().unwrap().set_cursor_visible(visible); - } - fn drag_window(&self) -> Result<(), RequestError> { self.window_state.lock().unwrap().drag_window() } @@ -607,20 +625,6 @@ impl CoreWindow for Window { self.window_state.lock().unwrap().show_window_menu(position); } - fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { - let surface = self.window.wl_surface(); - - if hittest { - surface.set_input_region(None); - Ok(()) - } else { - let region = Region::new(&*self.compositor).map_err(|err| os_error!(err))?; - region.add(0, 0, 0, 0); - surface.set_input_region(Some(region.wl_region())); - Ok(()) - } - } - fn current_monitor(&self) -> Option { let data = self.window.wl_surface().data::()?; data.outputs() diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 016d059622..6977b3ea77 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -35,7 +35,7 @@ use crate::platform_impl::{ VideoModeHandle as PlatformVideoModeHandle, }; use crate::window::{ - CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow, + CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow, Surface as CoreSurface, WindowAttributes, WindowButtons, WindowId, WindowLevel, }; @@ -61,7 +61,7 @@ impl Window { } } -impl CoreWindow for Window { +impl CoreSurface for Window { fn id(&self) -> WindowId { self.0.id() } @@ -78,6 +78,40 @@ impl CoreWindow for Window { self.0.pre_present_notify() } + fn surface_size(&self) -> PhysicalSize { + self.0.surface_size() + } + + fn request_surface_size(&self, size: Size) -> Option> { + self.0.request_surface_size(size) + } + + fn set_transparent(&self, transparent: bool) { + self.0.set_transparent(transparent); + } + + fn set_cursor(&self, cursor: Cursor) { + self.0.set_cursor(cursor); + } + + fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { + self.0.set_cursor_position(position) + } + + fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> { + self.0.set_cursor_grab(mode) + } + + fn set_cursor_visible(&self, visible: bool) { + self.0.set_cursor_visible(visible); + } + + fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { + self.0.set_cursor_hittest(hittest) + } +} + +impl CoreWindow for Window { fn reset_dead_keys(&self) { common::xkb::reset_dead_keys(); } @@ -94,14 +128,6 @@ impl CoreWindow for Window { self.0.set_outer_position(position) } - fn surface_size(&self) -> PhysicalSize { - self.0.surface_size() - } - - fn request_surface_size(&self, size: Size) -> Option> { - self.0.request_surface_size(size) - } - fn outer_size(&self) -> PhysicalSize { self.0.outer_size() } @@ -126,10 +152,6 @@ impl CoreWindow for Window { self.0.set_title(title); } - fn set_transparent(&self, transparent: bool) { - self.0.set_transparent(transparent); - } - fn set_blur(&self, blur: bool) { self.0.set_blur(blur); } @@ -238,22 +260,6 @@ impl CoreWindow for Window { self.0.title() } - fn set_cursor(&self, cursor: Cursor) { - self.0.set_cursor(cursor); - } - - fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { - self.0.set_cursor_position(position) - } - - fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> { - self.0.set_cursor_grab(mode) - } - - fn set_cursor_visible(&self, visible: bool) { - self.0.set_cursor_visible(visible); - } - fn drag_window(&self) -> Result<(), RequestError> { self.0.drag_window() } @@ -266,10 +272,6 @@ impl CoreWindow for Window { self.0.show_window_menu(position); } - fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { - self.0.set_cursor_hittest(hittest) - } - fn current_monitor(&self) -> Option { self.0 .current_monitor() diff --git a/src/window.rs b/src/window.rs index 071cdf2bab..5296ddbffb 100644 --- a/src/window.rs +++ b/src/window.rs @@ -420,9 +420,9 @@ impl WindowAttributes { } } -/// Represents a window. +/// Represents a surface. /// -/// The window is closed when dropped. +/// The surface is closed when dropped. /// /// ## Threading /// @@ -436,9 +436,9 @@ impl WindowAttributes { /// /// ## Platform-specific /// -/// **Web:** The [`Window`], which is represented by a `HTMLElementCanvas`, can -/// not be closed by dropping the [`Window`]. -pub trait Window: AsAny + Send + Sync { +/// **Web:** The [`Surface`], which is represented by a `HTMLElementCanvas`, can +/// not be closed by dropping the [`Surface`]. +pub trait Surface: AsAny + Send + Sync { /// Returns an identifier unique to the window. fn id(&self) -> WindowId; @@ -567,6 +567,166 @@ pub trait Window: AsAny + Send + Sync { /// [`WindowEvent::RedrawRequested`]: crate::event::WindowEvent::RedrawRequested fn pre_present_notify(&self); + /// Returns the size of the window's render-able surface. + /// + /// This is the dimensions you should pass to things like Wgpu or Glutin when configuring. + /// + /// ## Platform-specific + /// + /// - **iOS:** Returns the `PhysicalSize` of the window's [safe area] in screen space + /// coordinates. + /// - **Web:** Returns the size of the canvas element. Doesn't account for CSS [`transform`]. + /// + /// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc + /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform + fn surface_size(&self) -> PhysicalSize; + + /// Request the new size for the surface. + /// + /// On platforms where the size is entirely controlled by the user the + /// applied size will be returned immediately, resize event in such case + /// may not be generated. + /// + /// On platforms where resizing is disallowed by the windowing system, the current surface size + /// is returned immediately, and the user one is ignored. + /// + /// When `None` is returned, it means that the request went to the display system, + /// and the actual size will be delivered later with the [`WindowEvent::SurfaceResized`]. + /// + /// See [`Window::surface_size`] for more information about the values. + /// + /// The request could automatically un-maximize the window if it's maximized. + /// + /// ```no_run + /// # use winit::dpi::{LogicalSize, PhysicalSize}; + /// # use winit::window::Window; + /// # fn scope(window: &dyn Window) { + /// // Specify the size in logical dimensions like this: + /// let _ = window.request_surface_size(LogicalSize::new(400.0, 200.0).into()); + /// + /// // Or specify the size in physical dimensions like this: + /// let _ = window.request_surface_size(PhysicalSize::new(400, 200).into()); + /// # } + /// ``` + /// + /// ## Platform-specific + /// + /// - **Web:** Sets the size of the canvas element. Doesn't account for CSS [`transform`]. + /// + /// [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized + /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform + #[must_use] + fn request_surface_size(&self, size: Size) -> Option>; + + /// Change the window transparency state. + /// + /// This is just a hint that may not change anything about + /// the window transparency, however doing a mismatch between + /// the content of your window and this hint may result in + /// visual artifacts. + /// + /// The default value follows the [`WindowAttributes::with_transparent`]. + /// + /// ## Platform-specific + /// + /// - **macOS:** This will reset the window's background color. + /// - **Web / iOS / Android:** Unsupported. + /// - **X11:** Can only be set while building the window, with + /// [`WindowAttributes::with_transparent`]. + fn set_transparent(&self, transparent: bool); + + /// Modifies whether the window catches cursor events. + /// + /// If `true`, the window will catch the cursor events. If `false`, events are passed through + /// the window such that any other window behind it receives them. By default hittest is + /// enabled. + /// + /// ## Platform-specific + /// + /// - **iOS / Android / Web / Orbital:** Always returns an [`RequestError::NotSupported`]. + fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError>; + + /// Changes the position of the cursor in window coordinates. + /// + /// ```no_run + /// # use winit::dpi::{LogicalPosition, PhysicalPosition}; + /// # use winit::window::Window; + /// # fn scope(window: &dyn Window) { + /// // Specify the position in logical dimensions like this: + /// window.set_cursor_position(LogicalPosition::new(400.0, 200.0).into()); + /// + /// // Or specify the position in physical dimensions like this: + /// window.set_cursor_position(PhysicalPosition::new(400, 200).into()); + /// # } + /// ``` + /// + /// ## Platform-specific + /// + /// - **Wayland**: Cursor must be in [`CursorGrabMode::Locked`]. + /// - **iOS / Android / Web / Orbital:** Always returns an [`RequestError::NotSupported`]. + fn set_cursor_position(&self, position: Position) -> Result<(), RequestError>; + + /// Set grabbing [mode][CursorGrabMode] on the cursor preventing it from leaving the window. + /// + /// # Example + /// + /// First try confining the cursor, and if that fails, try locking it instead. + /// + /// ```no_run + /// # use winit::window::{CursorGrabMode, Window}; + /// # fn scope(window: &dyn Window) { + /// window + /// .set_cursor_grab(CursorGrabMode::Confined) + /// .or_else(|_e| window.set_cursor_grab(CursorGrabMode::Locked)) + /// .unwrap(); + /// # } + /// ``` + fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError>; + + /// Modifies the cursor icon of the window. + /// + /// ## Platform-specific + /// + /// - **iOS / Android / Orbital:** Unsupported. + /// - **Web:** Custom cursors have to be loaded and decoded first, until then the previous + /// cursor is shown. + fn set_cursor(&self, cursor: Cursor); + + /// Modifies the cursor's visibility. + /// + /// If `false`, this will hide the cursor. If `true`, this will show the cursor. + /// + /// ## Platform-specific + /// + /// - **Windows:** The cursor is only hidden within the confines of the window. + /// - **X11:** The cursor is only hidden within the confines of the window. + /// - **Wayland:** The cursor is only hidden within the confines of the window. + /// - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor + /// is outside of the window. + /// - **iOS / Android:** Unsupported. + fn set_cursor_visible(&self, visible: bool); +} + +/// Represents a toplevel window, which may generally have decorations. +/// +/// The window is closed when dropped. +/// +/// ## Threading +/// +/// This is `Send + Sync`, meaning that it can be freely used from other +/// threads. +/// +/// However, some platforms (macOS, Web and iOS) only allow user interface +/// interactions on the main thread, so on those platforms, if you use the +/// window from a thread other than the main, the code is scheduled to run on +/// the main thread, and your thread may be blocked until that completes. +/// +/// ## Platform-specific +/// +/// **Web:** The [`Window`], which is represented by a `HTMLElementCanvas`, can +/// not be closed by dropping the [`Window`]. +pub trait Window: Surface { + /// Reset the dead key state of the keyboard. /// /// This is useful when a dead key is bound to trigger an action. Then @@ -643,57 +803,6 @@ pub trait Window: AsAny + Send + Sync { /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform fn set_outer_position(&self, position: Position); - /// Returns the size of the window's render-able surface. - /// - /// This is the dimensions you should pass to things like Wgpu or Glutin when configuring. - /// - /// ## Platform-specific - /// - /// - **iOS:** Returns the `PhysicalSize` of the window's [safe area] in screen space - /// coordinates. - /// - **Web:** Returns the size of the canvas element. Doesn't account for CSS [`transform`]. - /// - /// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc - /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform - fn surface_size(&self) -> PhysicalSize; - - /// Request the new size for the surface. - /// - /// On platforms where the size is entirely controlled by the user the - /// applied size will be returned immediately, resize event in such case - /// may not be generated. - /// - /// On platforms where resizing is disallowed by the windowing system, the current surface size - /// is returned immediately, and the user one is ignored. - /// - /// When `None` is returned, it means that the request went to the display system, - /// and the actual size will be delivered later with the [`WindowEvent::SurfaceResized`]. - /// - /// See [`Window::surface_size`] for more information about the values. - /// - /// The request could automatically un-maximize the window if it's maximized. - /// - /// ```no_run - /// # use winit::dpi::{LogicalSize, PhysicalSize}; - /// # use winit::window::Window; - /// # fn scope(window: &dyn Window) { - /// // Specify the size in logical dimensions like this: - /// let _ = window.request_surface_size(LogicalSize::new(400.0, 200.0).into()); - /// - /// // Or specify the size in physical dimensions like this: - /// let _ = window.request_surface_size(PhysicalSize::new(400, 200).into()); - /// # } - /// ``` - /// - /// ## Platform-specific - /// - /// - **Web:** Sets the size of the canvas element. Doesn't account for CSS [`transform`]. - /// - /// [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized - /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform - #[must_use] - fn request_surface_size(&self, size: Size) -> Option>; - /// Returns the size of the entire window. /// /// These dimensions include window decorations like the title bar and borders. If you don't @@ -771,23 +880,6 @@ pub trait Window: AsAny + Send + Sync { /// - **iOS / Android:** Unsupported. fn set_title(&self, title: &str); - /// Change the window transparency state. - /// - /// This is just a hint that may not change anything about - /// the window transparency, however doing a mismatch between - /// the content of your window and this hint may result in - /// visual artifacts. - /// - /// The default value follows the [`WindowAttributes::with_transparent`]. - /// - /// ## Platform-specific - /// - /// - **macOS:** This will reset the window's background color. - /// - **Web / iOS / Android:** Unsupported. - /// - **X11:** Can only be set while building the window, with - /// [`WindowAttributes::with_transparent`]. - fn set_transparent(&self, transparent: bool); - /// Change the window blur state. /// /// If `true`, this will make the transparent window background blurry. @@ -1125,66 +1217,6 @@ pub trait Window: AsAny + Send + Sync { /// - **iOS / Android / x11 / Wayland / Web:** Unsupported. Always returns an empty string. fn title(&self) -> String; - /// Modifies the cursor icon of the window. - /// - /// ## Platform-specific - /// - /// - **iOS / Android / Orbital:** Unsupported. - /// - **Web:** Custom cursors have to be loaded and decoded first, until then the previous - /// cursor is shown. - fn set_cursor(&self, cursor: Cursor); - - /// Changes the position of the cursor in window coordinates. - /// - /// ```no_run - /// # use winit::dpi::{LogicalPosition, PhysicalPosition}; - /// # use winit::window::Window; - /// # fn scope(window: &dyn Window) { - /// // Specify the position in logical dimensions like this: - /// window.set_cursor_position(LogicalPosition::new(400.0, 200.0).into()); - /// - /// // Or specify the position in physical dimensions like this: - /// window.set_cursor_position(PhysicalPosition::new(400, 200).into()); - /// # } - /// ``` - /// - /// ## Platform-specific - /// - /// - **Wayland**: Cursor must be in [`CursorGrabMode::Locked`]. - /// - **iOS / Android / Web / Orbital:** Always returns an [`RequestError::NotSupported`]. - fn set_cursor_position(&self, position: Position) -> Result<(), RequestError>; - - /// Set grabbing [mode][CursorGrabMode] on the cursor preventing it from leaving the window. - /// - /// # Example - /// - /// First try confining the cursor, and if that fails, try locking it instead. - /// - /// ```no_run - /// # use winit::window::{CursorGrabMode, Window}; - /// # fn scope(window: &dyn Window) { - /// window - /// .set_cursor_grab(CursorGrabMode::Confined) - /// .or_else(|_e| window.set_cursor_grab(CursorGrabMode::Locked)) - /// .unwrap(); - /// # } - /// ``` - fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError>; - - /// Modifies the cursor's visibility. - /// - /// If `false`, this will hide the cursor. If `true`, this will show the cursor. - /// - /// ## Platform-specific - /// - /// - **Windows:** The cursor is only hidden within the confines of the window. - /// - **X11:** The cursor is only hidden within the confines of the window. - /// - **Wayland:** The cursor is only hidden within the confines of the window. - /// - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor - /// is outside of the window. - /// - **iOS / Android:** Unsupported. - fn set_cursor_visible(&self, visible: bool); - /// Moves the window with the left mouse button until the button is released. /// /// There's no guarantee that this will work unless the left mouse button was pressed @@ -1220,17 +1252,6 @@ pub trait Window: AsAny + Send + Sync { /// [window menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu fn show_window_menu(&self, position: Position); - /// Modifies whether the window catches cursor events. - /// - /// If `true`, the window will catch the cursor events. If `false`, events are passed through - /// the window such that any other window behind it receives them. By default hittest is - /// enabled. - /// - /// ## Platform-specific - /// - /// - **iOS / Android / Web / Orbital:** Always returns an [`RequestError::NotSupported`]. - fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError>; - /// Returns the monitor on which the window currently resides. /// /// Returns `None` if current monitor can't be detected. From 6148318c42413efbf44f0d45e8eaa994f3d225fc Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 9 Oct 2024 18:16:23 -0400 Subject: [PATCH 02/29] cargo format --- src/platform_impl/apple/appkit/app.rs | 26 ++++++---- .../linux/wayland/seat/pointer/mod.rs | 5 +- src/platform_impl/linux/wayland/window/mod.rs | 8 ++- src/platform_impl/linux/x11/dnd.rs | 28 +++++----- .../linux/x11/event_processor.rs | 47 ++++++++++------- src/platform_impl/linux/x11/mod.rs | 19 ++++--- src/platform_impl/linux/x11/util/input.rs | 8 +-- src/platform_impl/linux/x11/window.rs | 4 +- src/platform_impl/orbital/event_loop.rs | 52 ++++++++++++------- src/platform_impl/windows/window_state.rs | 22 +++++--- src/window.rs | 1 - 11 files changed, 129 insertions(+), 91 deletions(-) diff --git a/src/platform_impl/apple/appkit/app.rs b/src/platform_impl/apple/appkit/app.rs index 747a17b4c5..f214ee191e 100644 --- a/src/platform_impl/apple/appkit/app.rs +++ b/src/platform_impl/apple/appkit/app.rs @@ -60,28 +60,32 @@ fn maybe_dispatch_device_event(app_state: &Rc, event: &NSEvent) { if delta_x != 0.0 || delta_y != 0.0 { app_state.maybe_queue_with_handler(move |app, event_loop| { - app.device_event(event_loop, None, DeviceEvent::PointerMotion { - delta: (delta_x, delta_y), - }); + app.device_event( + event_loop, + None, + DeviceEvent::PointerMotion { delta: (delta_x, delta_y) }, + ); }); } }, NSEventType::LeftMouseDown | NSEventType::RightMouseDown | NSEventType::OtherMouseDown => { let button = unsafe { event.buttonNumber() } as u32; app_state.maybe_queue_with_handler(move |app, event_loop| { - app.device_event(event_loop, None, DeviceEvent::Button { - button, - state: ElementState::Pressed, - }); + app.device_event( + event_loop, + None, + DeviceEvent::Button { button, state: ElementState::Pressed }, + ); }); }, NSEventType::LeftMouseUp | NSEventType::RightMouseUp | NSEventType::OtherMouseUp => { let button = unsafe { event.buttonNumber() } as u32; app_state.maybe_queue_with_handler(move |app, event_loop| { - app.device_event(event_loop, None, DeviceEvent::Button { - button, - state: ElementState::Released, - }); + app.device_event( + event_loop, + None, + DeviceEvent::Button { button, state: ElementState::Released }, + ); }); }, _ => (), diff --git a/src/platform_impl/linux/wayland/seat/pointer/mod.rs b/src/platform_impl/linux/wayland/seat/pointer/mod.rs index d080967b5f..c6d151901f 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/mod.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/mod.rs @@ -27,7 +27,10 @@ use sctk::seat::pointer::{ use sctk::seat::SeatState; use crate::dpi::{LogicalPosition, PhysicalPosition}; -use crate::event::{ElementState, MouseButton, MouseScrollDelta, PointerSource, PointerKind, TouchPhase, WindowEvent}; +use crate::event::{ + ElementState, MouseButton, MouseScrollDelta, PointerKind, PointerSource, TouchPhase, + WindowEvent, +}; use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::wayland::{self, WindowId}; diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index c84e383ce6..564edf72ef 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -24,9 +24,9 @@ use crate::event_loop::AsyncRequestSerial; use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::platform_impl::{Fullscreen, MonitorHandle as PlatformMonitorHandle}; use crate::window::{ - Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme, - UserAttentionType, Window as CoreWindow, Surface as CoreSurface, WindowAttributes, WindowButtons, WindowId, - WindowLevel, + Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, + Surface as CoreSurface, Theme, UserAttentionType, Window as CoreWindow, WindowAttributes, + WindowButtons, WindowId, WindowLevel, }; pub(crate) mod state; @@ -318,7 +318,6 @@ impl CoreSurface for Window { fn set_transparent(&self, transparent: bool) { self.window_state.lock().unwrap().set_transparent(transparent); } - fn set_cursor(&self, cursor: Cursor) { let window_state = &mut self.window_state.lock().unwrap(); @@ -364,7 +363,6 @@ impl CoreSurface for Window { } impl CoreWindow for Window { - #[inline] fn title(&self) -> String { self.window_state.lock().unwrap().title().to_owned() diff --git a/src/platform_impl/linux/x11/dnd.rs b/src/platform_impl/linux/x11/dnd.rs index 691e40af9b..ac79b5be5f 100644 --- a/src/platform_impl/linux/x11/dnd.rs +++ b/src/platform_impl/linux/x11/dnd.rs @@ -73,13 +73,13 @@ impl Dnd { DndState::Rejected => (0, atoms[DndNone]), }; self.xconn - .send_client_msg(target_window, target_window, atoms[XdndStatus] as _, None, [ - this_window, - accepted, - 0, - 0, - action as _, - ])? + .send_client_msg( + target_window, + target_window, + atoms[XdndStatus] as _, + None, + [this_window, accepted, 0, 0, action as _], + )? .ignore_error(); Ok(()) @@ -97,13 +97,13 @@ impl Dnd { DndState::Rejected => (0, atoms[DndNone]), }; self.xconn - .send_client_msg(target_window, target_window, atoms[XdndFinished] as _, None, [ - this_window, - accepted, - action as _, - 0, - 0, - ])? + .send_client_msg( + target_window, + target_window, + atoms[XdndFinished] as _, + None, + [this_window, accepted, action as _, 0, 0], + )? .ignore_error(); Ok(()) diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 1be903fa32..c5b2907067 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -657,10 +657,10 @@ impl EventProcessor { drop(shared_state_lock); if moved { - callback(&self.target, Event::WindowEvent { - window_id, - event: WindowEvent::Moved(outer.into()), - }); + callback( + &self.target, + Event::WindowEvent { window_id, event: WindowEvent::Moved(outer.into()) }, + ); } outer }; @@ -706,13 +706,18 @@ impl EventProcessor { drop(shared_state_lock); let surface_size = Arc::new(Mutex::new(new_surface_size)); - callback(&self.target, Event::WindowEvent { - window_id, - event: WindowEvent::ScaleFactorChanged { - scale_factor: new_scale_factor, - surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&surface_size)), + callback( + &self.target, + Event::WindowEvent { + window_id, + event: WindowEvent::ScaleFactorChanged { + scale_factor: new_scale_factor, + surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade( + &surface_size, + )), + }, }, - }); + ); let new_surface_size = *surface_size.lock().unwrap(); drop(surface_size); @@ -762,10 +767,13 @@ impl EventProcessor { } if resized { - callback(&self.target, Event::WindowEvent { - window_id, - event: WindowEvent::SurfaceResized(new_surface_size.into()), - }); + callback( + &self.target, + Event::WindowEvent { + window_id, + event: WindowEvent::SurfaceResized(new_surface_size.into()), + }, + ); } } @@ -1516,10 +1524,13 @@ impl EventProcessor { } let physical_key = xkb::raw_keycode_to_physicalkey(keycode); - callback(&self.target, Event::DeviceEvent { - device_id, - event: DeviceEvent::Key(RawKeyEvent { physical_key, state }), - }); + callback( + &self.target, + Event::DeviceEvent { + device_id, + event: DeviceEvent::Key(RawKeyEvent { physical_key, state }), + }, + ); } fn xinput2_hierarchy_changed(&mut self, xev: &XIHierarchyEvent) { diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 8e72449025..c3bfaa4420 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -1031,15 +1031,18 @@ impl Device { let ty = unsafe { (*class_ptr)._type }; if ty == ffi::XIScrollClass { let info = unsafe { &*(class_ptr as *const ffi::XIScrollClassInfo) }; - scroll_axes.push((info.number, ScrollAxis { - increment: info.increment, - orientation: match info.scroll_type { - ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal, - ffi::XIScrollTypeVertical => ScrollOrientation::Vertical, - _ => unreachable!(), + scroll_axes.push(( + info.number, + ScrollAxis { + increment: info.increment, + orientation: match info.scroll_type { + ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal, + ffi::XIScrollTypeVertical => ScrollOrientation::Vertical, + _ => unreachable!(), + }, + position: 0.0, }, - position: 0.0, - })); + )); } } } diff --git a/src/platform_impl/linux/x11/util/input.rs b/src/platform_impl/linux/x11/util/input.rs index 12a69bd0c7..b4f441436b 100644 --- a/src/platform_impl/linux/x11/util/input.rs +++ b/src/platform_impl/linux/x11/util/input.rs @@ -20,10 +20,10 @@ impl XConnection { mask: xinput::XIEventMask, ) -> Result, X11Error> { self.xcb_connection() - .xinput_xi_select_events(window, &[xinput::EventMask { - deviceid: device_id, - mask: vec![mask], - }]) + .xinput_xi_select_events( + window, + &[xinput::EventMask { deviceid: device_id, mask: vec![mask] }], + ) .map_err(Into::into) } diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 6977b3ea77..5a36b9da83 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -35,8 +35,8 @@ use crate::platform_impl::{ VideoModeHandle as PlatformVideoModeHandle, }; use crate::window::{ - CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow, Surface as CoreSurface, - WindowAttributes, WindowButtons, WindowId, WindowLevel, + CursorGrabMode, ImePurpose, ResizeDirection, Surface as CoreSurface, Theme, UserAttentionType, + Window as CoreWindow, WindowAttributes, WindowButtons, WindowId, WindowLevel, }; pub(crate) struct Window(Arc); diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 55b52aef50..e69a5e723f 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -402,33 +402,47 @@ impl EventLoop { ); }, EventOption::Mouse(MouseEvent { x, y }) => { - app.window_event(window_target, window_id, event::WindowEvent::PointerMoved { - device_id: None, - position: (x, y).into(), - source: event::PointerSource::Mouse, - }); + app.window_event( + window_target, + window_id, + event::WindowEvent::PointerMoved { + device_id: None, + position: (x, y).into(), + source: event::PointerSource::Mouse, + }, + ); }, EventOption::MouseRelative(MouseRelativeEvent { dx, dy }) => { - app.device_event(window_target, None, event::DeviceEvent::PointerMotion { - delta: (dx as f64, dy as f64), - }); + app.device_event( + window_target, + None, + event::DeviceEvent::PointerMotion { delta: (dx as f64, dy as f64) }, + ); }, EventOption::Button(ButtonEvent { left, middle, right }) => { while let Some((button, state)) = event_state.mouse(left, middle, right) { - app.window_event(window_target, window_id, event::WindowEvent::PointerButton { - device_id: None, - state, - position: dpi::PhysicalPosition::default(), - button: button.into(), - }); + app.window_event( + window_target, + window_id, + event::WindowEvent::PointerButton { + device_id: None, + state, + position: dpi::PhysicalPosition::default(), + button: button.into(), + }, + ); } }, EventOption::Scroll(ScrollEvent { x, y }) => { - app.window_event(window_target, window_id, event::WindowEvent::MouseWheel { - device_id: None, - delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32), - phase: event::TouchPhase::Moved, - }); + app.window_event( + window_target, + window_id, + event::WindowEvent::MouseWheel { + device_id: None, + delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32), + phase: event::TouchPhase::Moved, + }, + ); }, EventOption::Quit(QuitEvent {}) => { app.window_event(window_target, window_id, event::WindowEvent::CloseRequested); diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index f84dd2cfdb..f197a1b239 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -362,20 +362,26 @@ impl WindowFlags { if diff.contains(WindowFlags::MAXIMIZED) || new.contains(WindowFlags::MAXIMIZED) { unsafe { - ShowWindow(window, match new.contains(WindowFlags::MAXIMIZED) { - true => SW_MAXIMIZE, - false => SW_RESTORE, - }); + ShowWindow( + window, + match new.contains(WindowFlags::MAXIMIZED) { + true => SW_MAXIMIZE, + false => SW_RESTORE, + }, + ); } } // Minimize operations should execute after maximize for proper window animations if diff.contains(WindowFlags::MINIMIZED) { unsafe { - ShowWindow(window, match new.contains(WindowFlags::MINIMIZED) { - true => SW_MINIMIZE, - false => SW_RESTORE, - }); + ShowWindow( + window, + match new.contains(WindowFlags::MINIMIZED) { + true => SW_MINIMIZE, + false => SW_RESTORE, + }, + ); } diff.remove(WindowFlags::MINIMIZED); diff --git a/src/window.rs b/src/window.rs index 5296ddbffb..ce33de0165 100644 --- a/src/window.rs +++ b/src/window.rs @@ -726,7 +726,6 @@ pub trait Surface: AsAny + Send + Sync { /// **Web:** The [`Window`], which is represented by a `HTMLElementCanvas`, can /// not be closed by dropping the [`Window`]. pub trait Window: Surface { - /// Reset the dead key state of the keyboard. /// /// This is useful when a dead key is bound to trigger an action. Then From cb8e03d3708210a2287440727dfc81d57dbbe826 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 9 Oct 2024 18:19:30 -0400 Subject: [PATCH 03/29] fix docs --- src/window.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/window.rs b/src/window.rs index ce33de0165..0a9fb0784f 100644 --- a/src/window.rs +++ b/src/window.rs @@ -510,7 +510,7 @@ pub trait Surface: AsAny + Send + Sync { /// /// This is the **strongly encouraged** method of redrawing windows, as it can integrate with /// OS-requested redraws (e.g. when a window gets resized). To improve the event delivery - /// consider using [`Window::pre_present_notify`] as described in docs. + /// consider using [`Surface::pre_present_notify`] as described in docs. /// /// Applications should always aim to redraw whenever they receive a `RedrawRequested` event. /// @@ -526,7 +526,7 @@ pub trait Surface: AsAny + Send + Sync { /// - **Windows** This API uses `RedrawWindow` to request a `WM_PAINT` message and /// `RedrawRequested` is emitted in sync with any `WM_PAINT` messages. /// - **Wayland:** The events are aligned with the frame callbacks when - /// [`Window::pre_present_notify`] is used. + /// [`Surface::pre_present_notify`] is used. /// - **Web:** [`WindowEvent::RedrawRequested`] will be aligned with the /// `requestAnimationFrame`. /// @@ -546,7 +546,7 @@ pub trait Surface: AsAny + Send + Sync { /// APIs and software rendering. /// /// ```no_run - /// # use winit::window::Window; + /// # use winit::Surface::Window; /// # fn swap_buffers() {} /// # fn scope(window: &dyn Window) { /// // Do the actual drawing with OpenGL. @@ -593,13 +593,13 @@ pub trait Surface: AsAny + Send + Sync { /// When `None` is returned, it means that the request went to the display system, /// and the actual size will be delivered later with the [`WindowEvent::SurfaceResized`]. /// - /// See [`Window::surface_size`] for more information about the values. + /// See [`Surface::surface_size`] for more information about the values. /// /// The request could automatically un-maximize the window if it's maximized. /// /// ```no_run /// # use winit::dpi::{LogicalSize, PhysicalSize}; - /// # use winit::window::Window; + /// # use winit::Surface::Window; /// # fn scope(window: &dyn Window) { /// // Specify the size in logical dimensions like this: /// let _ = window.request_surface_size(LogicalSize::new(400.0, 200.0).into()); @@ -650,7 +650,7 @@ pub trait Surface: AsAny + Send + Sync { /// /// ```no_run /// # use winit::dpi::{LogicalPosition, PhysicalPosition}; - /// # use winit::window::Window; + /// # use winit::Surface::Window; /// # fn scope(window: &dyn Window) { /// // Specify the position in logical dimensions like this: /// window.set_cursor_position(LogicalPosition::new(400.0, 200.0).into()); @@ -673,7 +673,7 @@ pub trait Surface: AsAny + Send + Sync { /// First try confining the cursor, and if that fails, try locking it instead. /// /// ```no_run - /// # use winit::window::{CursorGrabMode, Window}; + /// # use winit::Surface::{CursorGrabMode, Window}; /// # fn scope(window: &dyn Window) { /// window /// .set_cursor_grab(CursorGrabMode::Confined) From 9e0955c34eaceaa89360943a7a808b41fac44d64 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 9 Oct 2024 18:27:16 -0400 Subject: [PATCH 04/29] fix docs for real this time --- src/changelog/unreleased.md | 2 +- src/cursor.rs | 2 +- src/event.rs | 6 +++--- src/lib.rs | 6 +++--- src/monitor.rs | 10 +++++----- src/platform/web.rs | 2 +- src/platform_impl/apple/uikit/window.rs | 6 +++--- src/window.rs | 16 ++++++++-------- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 8a22aed48c..3ba37240e3 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -162,7 +162,7 @@ changelog entry. - `EventLoopExtRunOnDemand::run_on_demand`. - `VideoMode` - `WindowAttributes::new()` - - `Window::set_cursor_icon()` + - `Surface::set_cursor_icon()` - On iOS, remove `platform::ios::EventLoopExtIOS` and related `platform::ios::Idiom` type. This feature was incomplete, and the equivalent functionality can be trivially achieved outside diff --git a/src/cursor.rs b/src/cursor.rs index d9130b8268..30f1bf71b0 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -12,7 +12,7 @@ pub const MAX_CURSOR_SIZE: u16 = 2048; const PIXEL_SIZE: usize = 4; -/// See [`Window::set_cursor()`][crate::window::Window::set_cursor] for more details. +/// See [`Surface::set_cursor()`][crate::window::Surface::set_cursor] for more details. #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub enum Cursor { Icon(CursorIcon), diff --git a/src/event.rs b/src/event.rs index edb3ea7161..f10316dd23 100644 --- a/src/event.rs +++ b/src/event.rs @@ -151,9 +151,9 @@ pub enum WindowEvent { /// The size of the window's surface has changed. /// /// Contains the new dimensions of the surface (can also be retrieved with - /// [`Window::surface_size`]). + /// [`Surface::surface_size`]). /// - /// [`Window::surface_size`]: crate::window::Window::surface_size + /// [`Surface::surface_size`]: crate::window::Surface::surface_size SurfaceResized(PhysicalSize), /// The position of the window has changed. Contains the window's new position. @@ -448,7 +448,7 @@ pub enum WindowEvent { /// This gets triggered in two scenarios: /// - The OS has performed an operation that's invalidated the window's contents (such as /// resizing the window). - /// - The application has explicitly requested a redraw via [`Window::request_redraw`]. + /// - The application has explicitly requested a redraw via [`Surface::request_redraw`]. /// /// Winit will aggregate duplicate redraw requests into a single event, to /// help avoid duplicating rendering work. diff --git a/src/lib.rs b/src/lib.rs index f998cd1232..52f73f53f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -99,7 +99,7 @@ //! ``` //! //! [`WindowEvent`] has a [`WindowId`] member. In multi-window environments, it should be -//! compared to the value returned by [`Window::id()`] to determine which [`Window`] +//! compared to the value returned by [`Surface::id()`] to determine which [`Window`] //! dispatched the event. //! //! # Drawing on the window @@ -132,7 +132,7 @@ //! can be found by calling [`window.scale_factor()`]. //! //! [`ScaleFactorChanged`]: event::WindowEvent::ScaleFactorChanged -//! [`window.scale_factor()`]: window::Window::scale_factor +//! [`window.scale_factor()`]: window::Surface::scale_factor //! //! # Cargo Features //! @@ -212,7 +212,7 @@ //! [`WindowAttributes`]: window::WindowAttributes //! [window_new]: window::Window::new //! [`create_window`]: event_loop::ActiveEventLoop::create_window -//! [`Window::id()`]: window::Window::id +//! [`Surface::id()`]: window::Surface::id //! [`WindowEvent`]: event::WindowEvent //! [`DeviceEvent`]: event::DeviceEvent //! [`Event::UserEvent`]: event::Event::UserEvent diff --git a/src/monitor.rs b/src/monitor.rs index 898f9b2003..59131a6c53 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -47,9 +47,9 @@ impl Ord for VideoModeHandle { impl VideoModeHandle { /// Returns the resolution of this video mode. This **must not** be used to create your - /// rendering surface. Use [`Window::surface_size()`] instead. + /// rendering surface. Use [`Surface::surface_size()`] instead. /// - /// [`Window::surface_size()`]: crate::window::Window::surface_size + /// [`Surface::surface_size()`]: crate::window::Surface::surface_size #[inline] pub fn size(&self) -> PhysicalSize { self.video_mode.size() @@ -158,14 +158,14 @@ impl MonitorHandle { } /// Returns the scale factor of the underlying monitor. To map logical pixels to physical - /// pixels and vice versa, use [`Window::scale_factor`]. + /// pixels and vice versa, use [`Surface::scale_factor`]. /// /// See the [`dpi`] module for more information. /// /// ## Platform-specific /// /// - **X11:** Can be overridden using the `WINIT_X11_SCALE_FACTOR` environment variable. - /// - **Wayland:** May differ from [`Window::scale_factor`]. + /// - **Wayland:** May differ from [`Surface::scale_factor`]. /// - **Android:** Always returns 1.0. /// - **Web:** Always returns `0.0` without #[cfg_attr( @@ -175,7 +175,7 @@ impl MonitorHandle { #[cfg_attr(not(any(web_platform, docsrs)), doc = " detailed monitor permissions.")] /// #[rustfmt::skip] - /// [`Window::scale_factor`]: crate::window::Window::scale_factor + /// [`Surface::scale_factor`]: crate::window::Surface::scale_factor #[inline] pub fn scale_factor(&self) -> f64 { self.inner.scale_factor() diff --git a/src/platform/web.rs b/src/platform/web.rs index a64a890442..7002a8682a 100644 --- a/src/platform/web.rs +++ b/src/platform/web.rs @@ -34,7 +34,7 @@ //! - [`Window::set_outer_position()`] //! //! [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized -//! [`Window::(set_)surface_size()`]: crate::window::Window::surface_size +//! [`Window::(set_)surface_size()`]: crate::window::Surface::surface_size //! [`WindowEvent::Occluded`]: crate::event::WindowEvent::Occluded //! [`WindowEvent::PointerMoved`]: crate::event::WindowEvent::PointerMoved //! [`WindowEvent::PointerEntered`]: crate::event::WindowEvent::PointerEntered diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index 1be3a555c1..e5d1f9d2a5 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -122,7 +122,7 @@ impl Inner { } pub fn set_transparent(&self, _transparent: bool) { - debug!("`Window::set_transparent` is ignored on iOS") + debug!("`Surface::set_transparent` is ignored on iOS") } pub fn set_blur(&self, _blur: bool) { @@ -252,7 +252,7 @@ impl Inner { } pub fn set_cursor(&self, _cursor: Cursor) { - debug!("`Window::set_cursor` ignored on iOS") + debug!("`Surface::set_cursor` ignored on iOS") } pub fn set_cursor_position(&self, _position: Position) -> Result<(), NotSupportedError> { @@ -264,7 +264,7 @@ impl Inner { } pub fn set_cursor_visible(&self, _visible: bool) { - debug!("`Window::set_cursor_visible` is ignored on iOS") + debug!("`Surface::set_cursor_visible` is ignored on iOS") } pub fn drag_window(&self) -> Result<(), NotSupportedError> { diff --git a/src/window.rs b/src/window.rs index 0a9fb0784f..3167bc7c73 100644 --- a/src/window.rs +++ b/src/window.rs @@ -16,7 +16,7 @@ use crate::utils::AsAny; /// Identifier of a window. Unique for each window. /// -/// Can be obtained with [`window.id()`][`Window::id`]. +/// Can be obtained with [`window.id()`][`Surface::id`]. /// /// Whenever you receive an event specific to a window, this event contains a `WindowId` which you /// can then compare to the ids of your windows. @@ -132,7 +132,7 @@ impl WindowAttributes { /// /// If this is not set, some platform-specific dimensions will be used. /// - /// See [`Window::request_surface_size`] for details. + /// See [`Surface::request_surface_size`] for details. #[inline] pub fn with_surface_size>(mut self, size: S) -> Self { self.surface_size = Some(size.into()); @@ -271,7 +271,7 @@ impl WindowAttributes { /// If this is `true`, writing colors with alpha values different than /// `1.0` will produce a transparent window. On some platforms this /// is more of a hint for the system and you'd still have the alpha - /// buffer. To control it see [`Window::set_transparent`]. + /// buffer. To control it see [`Surface::set_transparent`]. /// /// The default is `false`. #[inline] @@ -387,7 +387,7 @@ impl WindowAttributes { /// /// The default is [`CursorIcon::Default`]. /// - /// See [`Window::set_cursor()`] for more details. + /// See [`Surface::set_cursor()`] for more details. #[inline] pub fn with_cursor(mut self, cursor: impl Into) -> Self { self.cursor = cursor.into(); @@ -805,13 +805,13 @@ pub trait Window: Surface { /// Returns the size of the entire window. /// /// These dimensions include window decorations like the title bar and borders. If you don't - /// want that (and you usually don't), use [`Window::surface_size`] instead. + /// want that (and you usually don't), use [`Surface::surface_size`] instead. /// /// ## Platform-specific /// /// - **iOS:** Returns the [`PhysicalSize`] of the window in screen space coordinates. /// - **Web:** Returns the size of the canvas element. _Note: this returns the same value as - /// [`Window::surface_size`]._ + /// [`Surface::surface_size`]._ fn outer_size(&self) -> PhysicalSize; /// Sets a minimum dimensions of the window's surface. @@ -914,7 +914,7 @@ pub trait Window: Surface { /// Note that making the window unresizable doesn't exempt you from handling /// [`WindowEvent::SurfaceResized`], as that event can still be triggered by DPI scaling, /// entering fullscreen mode, etc. Also, the window could still be resized by calling - /// [`Window::request_surface_size`]. + /// [`Surface::request_surface_size`]. /// /// ## Platform-specific /// @@ -1342,7 +1342,7 @@ impl rwh_06::HasWindowHandle for dyn Window + '_ { /// The behavior of cursor grabbing. /// -/// Use this enum with [`Window::set_cursor_grab`] to grab the cursor. +/// Use this enum with [`Surface::set_cursor_grab`] to grab the cursor. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum CursorGrabMode { From 9174c7f80a340ea02f00fc2cd78033bd9329d0e6 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 9 Oct 2024 18:32:54 -0400 Subject: [PATCH 05/29] actually fix docs --- src/event.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event.rs b/src/event.rs index f10316dd23..5b611dd137 100644 --- a/src/event.rs +++ b/src/event.rs @@ -51,7 +51,7 @@ use crate::event_loop::AsyncRequestSerial; use crate::keyboard::{self, ModifiersKeyState, ModifiersKeys, ModifiersState}; use crate::platform_impl; #[cfg(doc)] -use crate::window::Window; +use crate::window::{Surface, Window}; use crate::window::{ActivationToken, Theme, WindowId}; // TODO: Remove once the backends can call `ApplicationHandler` methods directly. For now backends From 3f83bbbfe55bdcb5c710c5690c1c2176ca92509e Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 9 Oct 2024 19:48:15 -0400 Subject: [PATCH 06/29] fix some stupid edits --- src/window.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/window.rs b/src/window.rs index 3167bc7c73..2c4e172345 100644 --- a/src/window.rs +++ b/src/window.rs @@ -546,7 +546,7 @@ pub trait Surface: AsAny + Send + Sync { /// APIs and software rendering. /// /// ```no_run - /// # use winit::Surface::Window; + /// # use winit::window::Window; /// # fn swap_buffers() {} /// # fn scope(window: &dyn Window) { /// // Do the actual drawing with OpenGL. @@ -599,7 +599,7 @@ pub trait Surface: AsAny + Send + Sync { /// /// ```no_run /// # use winit::dpi::{LogicalSize, PhysicalSize}; - /// # use winit::Surface::Window; + /// # use winit::window::Window; /// # fn scope(window: &dyn Window) { /// // Specify the size in logical dimensions like this: /// let _ = window.request_surface_size(LogicalSize::new(400.0, 200.0).into()); @@ -650,7 +650,7 @@ pub trait Surface: AsAny + Send + Sync { /// /// ```no_run /// # use winit::dpi::{LogicalPosition, PhysicalPosition}; - /// # use winit::Surface::Window; + /// # use winit::window::Window; /// # fn scope(window: &dyn Window) { /// // Specify the position in logical dimensions like this: /// window.set_cursor_position(LogicalPosition::new(400.0, 200.0).into()); @@ -673,7 +673,7 @@ pub trait Surface: AsAny + Send + Sync { /// First try confining the cursor, and if that fails, try locking it instead. /// /// ```no_run - /// # use winit::Surface::{CursorGrabMode, Window}; + /// # use winit::window::{CursorGrabMode, Window}; /// # fn scope(window: &dyn Window) { /// window /// .set_cursor_grab(CursorGrabMode::Confined) From 240486af321511bf5a83734eb815f8f65763d6b8 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Sat, 12 Oct 2024 12:29:30 -0400 Subject: [PATCH 07/29] move handles and monitor methods to Surface --- src/platform_impl/linux/wayland/window/mod.rs | 76 ++++++------- src/platform_impl/linux/x11/window.rs | 66 +++++------ src/window.rs | 106 +++++++++--------- 3 files changed, 125 insertions(+), 123 deletions(-) diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 564edf72ef..2929c0f11a 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -360,6 +360,44 @@ impl CoreSurface for Window { Ok(()) } } + + fn current_monitor(&self) -> Option { + let data = self.window.wl_surface().data::()?; + data.outputs() + .next() + .map(MonitorHandle::new) + .map(crate::platform_impl::MonitorHandle::Wayland) + .map(|inner| CoreMonitorHandle { inner }) + } + + fn available_monitors(&self) -> Box> { + Box::new( + self.monitors + .lock() + .unwrap() + .clone() + .into_iter() + .map(crate::platform_impl::MonitorHandle::Wayland) + .map(|inner| CoreMonitorHandle { inner }), + ) + } + + fn primary_monitor(&self) -> Option { + // NOTE: There's no such concept on Wayland. + None + } + + /// Get the raw-window-handle v0.6 display handle. + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + self + } + + /// Get the raw-window-handle v0.6 window handle. + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + self + } } impl CoreWindow for Window { @@ -622,44 +660,6 @@ impl CoreWindow for Window { let position = position.to_logical(scale_factor); self.window_state.lock().unwrap().show_window_menu(position); } - - fn current_monitor(&self) -> Option { - let data = self.window.wl_surface().data::()?; - data.outputs() - .next() - .map(MonitorHandle::new) - .map(crate::platform_impl::MonitorHandle::Wayland) - .map(|inner| CoreMonitorHandle { inner }) - } - - fn available_monitors(&self) -> Box> { - Box::new( - self.monitors - .lock() - .unwrap() - .clone() - .into_iter() - .map(crate::platform_impl::MonitorHandle::Wayland) - .map(|inner| CoreMonitorHandle { inner }), - ) - } - - fn primary_monitor(&self) -> Option { - // NOTE: There's no such concept on Wayland. - None - } - - /// Get the raw-window-handle v0.6 display handle. - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { - self - } - - /// Get the raw-window-handle v0.6 window handle. - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { - self - } } /// The request from the window to the event loop. diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 5a36b9da83..6d2f28c8d2 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -109,6 +109,40 @@ impl CoreSurface for Window { fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { self.0.set_cursor_hittest(hittest) } + + fn current_monitor(&self) -> Option { + self.0 + .current_monitor() + .map(crate::platform_impl::MonitorHandle::X) + .map(|inner| crate::monitor::MonitorHandle { inner }) + } + + fn available_monitors(&self) -> Box> { + Box::new( + self.0 + .available_monitors() + .into_iter() + .map(crate::platform_impl::MonitorHandle::X) + .map(|inner| crate::monitor::MonitorHandle { inner }), + ) + } + + fn primary_monitor(&self) -> Option { + self.0 + .primary_monitor() + .map(crate::platform_impl::MonitorHandle::X) + .map(|inner| crate::monitor::MonitorHandle { inner }) + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + self + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + self + } } impl CoreWindow for Window { @@ -272,39 +306,7 @@ impl CoreWindow for Window { self.0.show_window_menu(position); } - fn current_monitor(&self) -> Option { - self.0 - .current_monitor() - .map(crate::platform_impl::MonitorHandle::X) - .map(|inner| crate::monitor::MonitorHandle { inner }) - } - - fn available_monitors(&self) -> Box> { - Box::new( - self.0 - .available_monitors() - .into_iter() - .map(crate::platform_impl::MonitorHandle::X) - .map(|inner| crate::monitor::MonitorHandle { inner }), - ) - } - fn primary_monitor(&self) -> Option { - self.0 - .primary_monitor() - .map(crate::platform_impl::MonitorHandle::X) - .map(|inner| crate::monitor::MonitorHandle { inner }) - } - - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { - self - } - - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { - self - } } #[cfg(feature = "rwh_06")] diff --git a/src/window.rs b/src/window.rs index 2c4e172345..2613a0031e 100644 --- a/src/window.rs +++ b/src/window.rs @@ -420,7 +420,7 @@ impl WindowAttributes { } } -/// Represents a surface. +/// Represents an area that can be drawn to; this includes windows. /// /// The surface is closed when dropped. /// @@ -705,6 +705,58 @@ pub trait Surface: AsAny + Send + Sync { /// is outside of the window. /// - **iOS / Android:** Unsupported. fn set_cursor_visible(&self, visible: bool); + + /// Returns the monitor on which the window currently resides. + /// + /// Returns `None` if current monitor can't be detected. + fn current_monitor(&self) -> Option; + + /// Returns the list of all the monitors available on the system. + /// + /// This is the same as [`ActiveEventLoop::available_monitors`], and is provided for + /// convenience. + /// + /// + /// ## Platform-specific + /// + /// **Web:** Only returns the current monitor without + #[cfg_attr( + any(web_platform, docsrs), + doc = "[detailed monitor permissions][crate::platform::web::ActiveEventLoopExtWeb::request_detailed_monitor_permission]." + )] + #[cfg_attr(not(any(web_platform, docsrs)), doc = "detailed monitor permissions.")] + /// + #[rustfmt::skip] + /// [`ActiveEventLoop::available_monitors`]: crate::event_loop::ActiveEventLoop::available_monitors + fn available_monitors(&self) -> Box>; + + /// Returns the primary monitor of the system. + /// + /// Returns `None` if it can't identify any monitor as a primary one. + /// + /// This is the same as [`ActiveEventLoop::primary_monitor`], and is provided for convenience. + /// + /// ## Platform-specific + /// + /// - **Wayland:** Always returns `None`. + /// - **Web:** Always returns `None` without + #[cfg_attr( + any(web_platform, docsrs), + doc = " [detailed monitor permissions][crate::platform::web::ActiveEventLoopExtWeb::request_detailed_monitor_permission]." + )] + #[cfg_attr(not(any(web_platform, docsrs)), doc = " detailed monitor permissions.")] + /// + #[rustfmt::skip] + /// [`ActiveEventLoop::primary_monitor`]: crate::event_loop::ActiveEventLoop::primary_monitor + fn primary_monitor(&self) -> Option; + + /// Get the raw-window-handle v0.6 display handle. + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle; + + /// Get the raw-window-handle v0.6 window handle. + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle; } /// Represents a toplevel window, which may generally have decorations. @@ -1250,58 +1302,6 @@ pub trait Window: Surface { /// /// [window menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu fn show_window_menu(&self, position: Position); - - /// Returns the monitor on which the window currently resides. - /// - /// Returns `None` if current monitor can't be detected. - fn current_monitor(&self) -> Option; - - /// Returns the list of all the monitors available on the system. - /// - /// This is the same as [`ActiveEventLoop::available_monitors`], and is provided for - /// convenience. - /// - /// - /// ## Platform-specific - /// - /// **Web:** Only returns the current monitor without - #[cfg_attr( - any(web_platform, docsrs), - doc = "[detailed monitor permissions][crate::platform::web::ActiveEventLoopExtWeb::request_detailed_monitor_permission]." - )] - #[cfg_attr(not(any(web_platform, docsrs)), doc = "detailed monitor permissions.")] - /// - #[rustfmt::skip] - /// [`ActiveEventLoop::available_monitors`]: crate::event_loop::ActiveEventLoop::available_monitors - fn available_monitors(&self) -> Box>; - - /// Returns the primary monitor of the system. - /// - /// Returns `None` if it can't identify any monitor as a primary one. - /// - /// This is the same as [`ActiveEventLoop::primary_monitor`], and is provided for convenience. - /// - /// ## Platform-specific - /// - /// - **Wayland:** Always returns `None`. - /// - **Web:** Always returns `None` without - #[cfg_attr( - any(web_platform, docsrs), - doc = " [detailed monitor permissions][crate::platform::web::ActiveEventLoopExtWeb::request_detailed_monitor_permission]." - )] - #[cfg_attr(not(any(web_platform, docsrs)), doc = " detailed monitor permissions.")] - /// - #[rustfmt::skip] - /// [`ActiveEventLoop::primary_monitor`]: crate::event_loop::ActiveEventLoop::primary_monitor - fn primary_monitor(&self) -> Option; - - /// Get the raw-window-handle v0.6 display handle. - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle; - - /// Get the raw-window-handle v0.6 window handle. - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle; } impl dyn Window { From 12fb98a8396d859d98d7704d269693fe603fc6d3 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Sat, 12 Oct 2024 14:26:03 -0400 Subject: [PATCH 08/29] Downcasting (linux impl) --- src/platform_impl/linux/wayland/window/mod.rs | 4 ++++ src/platform_impl/linux/x11/window.rs | 4 ++++ src/window.rs | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 2929c0f11a..be15670fc4 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -398,6 +398,10 @@ impl CoreSurface for Window { fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { self } + + fn as_window(&self) -> Option<&dyn CoreWindow> { + Some(self) + } } impl CoreWindow for Window { diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 6d2f28c8d2..44d999d31f 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -143,6 +143,10 @@ impl CoreSurface for Window { fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { self } + + fn as_window(&self) -> Option<&dyn CoreWindow> { + Some(self) + } } impl CoreWindow for Window { diff --git a/src/window.rs b/src/window.rs index 2613a0031e..197046b98e 100644 --- a/src/window.rs +++ b/src/window.rs @@ -757,6 +757,11 @@ pub trait Surface: AsAny + Send + Sync { /// Get the raw-window-handle v0.6 window handle. #[cfg(feature = "rwh_06")] fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle; + + /// Tries to downcast this surface to a [`Window`]. Returns `None` if the surface is not a window. + fn as_window(&self) -> Option<&dyn Window> { + None + } } /// Represents a toplevel window, which may generally have decorations. From 4f5f6fe885dc8bba223430ecd41ec31241faa5ce Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Sat, 12 Oct 2024 14:27:38 -0400 Subject: [PATCH 09/29] doc fix --- src/monitor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monitor.rs b/src/monitor.rs index 59131a6c53..565a152aee 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -4,7 +4,7 @@ //! [`MonitorHandle`] type. This is retrieved from one of the following //! methods, which return an iterator of [`MonitorHandle`]: //! - [`ActiveEventLoop::available_monitors`][crate::event_loop::ActiveEventLoop::available_monitors]. -//! - [`Window::available_monitors`][crate::window::Window::available_monitors]. +//! - [`Window::available_monitors`][crate::window::Surface::available_monitors]. use std::num::{NonZeroU16, NonZeroU32}; use crate::dpi::{PhysicalPosition, PhysicalSize}; From 4a39a87c50224ecc6c8fad7377799897356c07fa Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Sat, 12 Oct 2024 14:53:11 -0400 Subject: [PATCH 10/29] Rename WindowId and WindowEvent to SurfaceId and SurfaceEvent --- examples/child_window.rs | 20 ++-- examples/control_flow.rs | 14 +-- examples/pump_events.rs | 12 +-- examples/run_on_demand.rs | 16 +-- examples/util/fill.rs | 4 +- examples/window.rs | 70 ++++++------ examples/x11_embed.rs | 12 +-- src/application.rs | 22 ++-- src/changelog/unreleased.md | 14 +-- src/event.rs | 46 ++++---- src/lib.rs | 22 ++-- src/platform/web.rs | 18 ++-- src/platform_impl/android/mod.rs | 22 ++-- .../linux/wayland/event_loop/mod.rs | 16 +-- .../linux/wayland/event_loop/sink.rs | 6 +- src/platform_impl/linux/wayland/mod.rs | 6 +- .../linux/wayland/seat/keyboard/mod.rs | 18 ++-- src/platform_impl/linux/wayland/seat/mod.rs | 4 +- .../linux/wayland/seat/pointer/mod.rs | 18 ++-- .../linux/wayland/seat/text_input/mod.rs | 12 +-- .../linux/wayland/seat/touch/mod.rs | 14 +-- src/platform_impl/linux/wayland/state.rs | 12 +-- .../linux/wayland/types/xdg_activation.rs | 6 +- src/platform_impl/linux/wayland/window/mod.rs | 12 +-- .../linux/wayland/window/state.rs | 4 +- .../linux/x11/event_processor.rs | 102 +++++++++--------- src/platform_impl/linux/x11/mod.rs | 22 ++-- src/platform_impl/linux/x11/window.rs | 16 +-- src/platform_impl/orbital/event_loop.rs | 34 +++--- src/platform_impl/web/event_loop/runner.rs | 4 +- src/platform_impl/web/web_sys/canvas.rs | 4 +- src/platform_impl/windows/drop_handler.rs | 6 +- src/platform_impl/windows/event_loop.rs | 42 ++++---- src/window.rs | 58 +++++----- tests/send_objects.rs | 2 +- 35 files changed, 355 insertions(+), 355 deletions(-) diff --git a/examples/child_window.rs b/examples/child_window.rs index 43ed75c9b1..cffadea43e 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -5,18 +5,18 @@ fn main() -> Result<(), impl std::error::Error> { use winit::application::ApplicationHandler; use winit::dpi::{LogicalPosition, LogicalSize, Position}; - use winit::event::{ElementState, KeyEvent, WindowEvent}; + use winit::event::{ElementState, KeyEvent, SurfaceEvent}; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::raw_window_handle::HasRawWindowHandle; - use winit::window::{Window, WindowAttributes, WindowId}; + use winit::window::{Window, WindowAttributes, SurfaceId}; #[path = "util/fill.rs"] mod fill; #[derive(Default)] struct Application { - parent_window_id: Option, - windows: HashMap>, + parent_window_id: Option, + windows: HashMap>, } impl ApplicationHandler for Application { @@ -36,15 +36,15 @@ fn main() -> Result<(), impl std::error::Error> { fn window_event( &mut self, event_loop: &dyn ActiveEventLoop, - window_id: winit::window::WindowId, - event: WindowEvent, + window_id: winit::window::SurfaceId, + event: SurfaceEvent, ) { match event { - WindowEvent::CloseRequested => { + SurfaceEvent::CloseRequested => { self.windows.clear(); event_loop.exit(); }, - WindowEvent::PointerEntered { device_id: _, .. } => { + SurfaceEvent::PointerEntered { device_id: _, .. } => { // On x11, println when the cursor entered in a window even if the child window // is created by some key inputs. // the child windows are always placed at (0, 0) with size (200, 200) in the @@ -52,7 +52,7 @@ fn main() -> Result<(), impl std::error::Error> { // the cursor around (200, 200) in parent window. println!("cursor entered in the window {window_id:?}"); }, - WindowEvent::KeyboardInput { + SurfaceEvent::KeyboardInput { event: KeyEvent { state: ElementState::Pressed, .. }, .. } => { @@ -62,7 +62,7 @@ fn main() -> Result<(), impl std::error::Error> { println!("Child window created with id: {child_id:?}"); self.windows.insert(child_id, child_window); }, - WindowEvent::RedrawRequested => { + SurfaceEvent::RedrawRequested => { if let Some(window) = self.windows.get(&window_id) { fill::fill_window(window.as_ref()); } diff --git a/examples/control_flow.rs b/examples/control_flow.rs index 47a518c181..6b8781f552 100644 --- a/examples/control_flow.rs +++ b/examples/control_flow.rs @@ -8,10 +8,10 @@ use ::tracing::{info, warn}; #[cfg(web_platform)] use web_time as time; use winit::application::ApplicationHandler; -use winit::event::{ElementState, KeyEvent, StartCause, WindowEvent}; +use winit::event::{ElementState, KeyEvent, StartCause, SurfaceEvent}; use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; use winit::keyboard::{Key, NamedKey}; -use winit::window::{Window, WindowAttributes, WindowId}; +use winit::window::{Window, WindowAttributes, SurfaceId}; #[path = "util/fill.rs"] mod fill; @@ -75,16 +75,16 @@ impl ApplicationHandler for ControlFlowDemo { fn window_event( &mut self, _event_loop: &dyn ActiveEventLoop, - _window_id: WindowId, - event: WindowEvent, + _window_id: SurfaceId, + event: SurfaceEvent, ) { info!("{event:?}"); match event { - WindowEvent::CloseRequested => { + SurfaceEvent::CloseRequested => { self.close_requested = true; }, - WindowEvent::KeyboardInput { + SurfaceEvent::KeyboardInput { event: KeyEvent { logical_key: key, state: ElementState::Pressed, .. }, .. } => match key.as_ref() { @@ -111,7 +111,7 @@ impl ApplicationHandler for ControlFlowDemo { }, _ => (), }, - WindowEvent::RedrawRequested => { + SurfaceEvent::RedrawRequested => { let window = self.window.as_ref().unwrap(); window.pre_present_notify(); fill::fill_window(window.as_ref()); diff --git a/examples/pump_events.rs b/examples/pump_events.rs index 3ec8abe38b..ec18bdbe46 100644 --- a/examples/pump_events.rs +++ b/examples/pump_events.rs @@ -8,10 +8,10 @@ fn main() -> std::process::ExitCode { use std::time::Duration; use winit::application::ApplicationHandler; - use winit::event::WindowEvent; + use winit::event::SurfaceEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::platform::pump_events::{EventLoopExtPumpEvents, PumpStatus}; - use winit::window::{Window, WindowAttributes, WindowId}; + use winit::window::{Window, WindowAttributes, SurfaceId}; #[path = "util/fill.rs"] mod fill; @@ -30,8 +30,8 @@ fn main() -> std::process::ExitCode { fn window_event( &mut self, event_loop: &dyn ActiveEventLoop, - _window_id: WindowId, - event: WindowEvent, + _window_id: SurfaceId, + event: SurfaceEvent, ) { println!("{event:?}"); @@ -41,8 +41,8 @@ fn main() -> std::process::ExitCode { }; match event { - WindowEvent::CloseRequested => event_loop.exit(), - WindowEvent::RedrawRequested => { + SurfaceEvent::CloseRequested => event_loop.exit(), + SurfaceEvent::RedrawRequested => { fill::fill_window(window.as_ref()); window.request_redraw(); }, diff --git a/examples/run_on_demand.rs b/examples/run_on_demand.rs index e6d105ad5e..d17e1672a7 100644 --- a/examples/run_on_demand.rs +++ b/examples/run_on_demand.rs @@ -6,10 +6,10 @@ fn main() -> Result<(), Box> { use std::time::Duration; use winit::application::ApplicationHandler; - use winit::event::WindowEvent; + use winit::event::SurfaceEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::platform::run_on_demand::EventLoopExtRunOnDemand; - use winit::window::{Window, WindowAttributes, WindowId}; + use winit::window::{Window, WindowAttributes, SurfaceId}; #[path = "util/fill.rs"] mod fill; @@ -17,7 +17,7 @@ fn main() -> Result<(), Box> { #[derive(Default)] struct App { idx: usize, - window_id: Option, + window_id: Option, window: Option>, } @@ -40,10 +40,10 @@ fn main() -> Result<(), Box> { fn window_event( &mut self, event_loop: &dyn ActiveEventLoop, - window_id: WindowId, - event: WindowEvent, + window_id: SurfaceId, + event: SurfaceEvent, ) { - if event == WindowEvent::Destroyed && self.window_id == Some(window_id) { + if event == SurfaceEvent::Destroyed && self.window_id == Some(window_id) { println!( "--------------------------------------------------------- Window {} Destroyed", self.idx @@ -59,7 +59,7 @@ fn main() -> Result<(), Box> { }; match event { - WindowEvent::CloseRequested => { + SurfaceEvent::CloseRequested => { println!( "--------------------------------------------------------- Window {} \ CloseRequested", @@ -68,7 +68,7 @@ fn main() -> Result<(), Box> { fill::cleanup_window(window.as_ref()); self.window = None; }, - WindowEvent::RedrawRequested => { + SurfaceEvent::RedrawRequested => { fill::fill_window(window.as_ref()); }, _ => (), diff --git a/examples/util/fill.rs b/examples/util/fill.rs index 446aa38956..6c8d8da0c6 100644 --- a/examples/util/fill.rs +++ b/examples/util/fill.rs @@ -20,7 +20,7 @@ mod platform { use std::num::NonZeroU32; use softbuffer::{Context, Surface}; - use winit::window::{Window, WindowId}; + use winit::window::{Window, SurfaceId}; thread_local! { // NOTE: You should never do things like that, create context and drop it before @@ -37,7 +37,7 @@ mod platform { context: RefCell>, /// The hash map of window IDs to surfaces. - surfaces: HashMap>, + surfaces: HashMap>, } impl GraphicsContext { diff --git a/examples/window.rs b/examples/window.rs index f9f3c8b84c..602bd7b999 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -18,7 +18,7 @@ use softbuffer::{Context, Surface}; use winit::application::ApplicationHandler; use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize}; use winit::error::RequestError; -use winit::event::{DeviceEvent, DeviceId, Ime, MouseButton, MouseScrollDelta, WindowEvent}; +use winit::event::{DeviceEvent, DeviceId, Ime, MouseButton, MouseScrollDelta, SurfaceEvent}; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::keyboard::{Key, ModifiersState}; #[cfg(macos_platform)] @@ -31,7 +31,7 @@ use winit::platform::startup_notify::{ use winit::platform::web::{ActiveEventLoopExtWeb, CustomCursorExtWeb, WindowAttributesExtWeb}; use winit::window::{ Cursor, CursorGrabMode, CustomCursor, CustomCursorSource, Fullscreen, Icon, ResizeDirection, - Theme, Window, WindowAttributes, WindowId, + Theme, Window, WindowAttributes, SurfaceId, }; #[path = "util/tracing.rs"] @@ -79,7 +79,7 @@ struct Application { custom_cursors: Result, RequestError>, /// Application icon. icon: Icon, - windows: HashMap, + windows: HashMap, /// Drawing context. /// /// With OpenGL it could be EGLDisplay. @@ -131,7 +131,7 @@ impl Application { &mut self, event_loop: &dyn ActiveEventLoop, _tab_id: Option, - ) -> Result> { + ) -> Result> { // TODO read-out activation token. #[allow(unused_mut)] @@ -182,14 +182,14 @@ impl Application { Action::Message => { info!("User wake up"); }, - _ => unreachable!("Tried to execute invalid action without `WindowId`"), + _ => unreachable!("Tried to execute invalid action without `SurfaceId`"), } } fn handle_action_with_window( &mut self, event_loop: &dyn ActiveEventLoop, - window_id: WindowId, + window_id: SurfaceId, action: Action, ) { // let cursor_position = self.cursor_position; @@ -380,8 +380,8 @@ impl ApplicationHandler for Application { fn window_event( &mut self, event_loop: &dyn ActiveEventLoop, - window_id: WindowId, - event: WindowEvent, + window_id: SurfaceId, + event: SurfaceEvent, ) { let window = match self.windows.get_mut(&window_id) { Some(window) => window, @@ -389,40 +389,40 @@ impl ApplicationHandler for Application { }; match event { - WindowEvent::SurfaceResized(size) => { + SurfaceEvent::SurfaceResized(size) => { window.resize(size); }, - WindowEvent::Focused(focused) => { + SurfaceEvent::Focused(focused) => { if focused { info!("Window={window_id:?} focused"); } else { info!("Window={window_id:?} unfocused"); } }, - WindowEvent::ScaleFactorChanged { scale_factor, .. } => { + SurfaceEvent::ScaleFactorChanged { scale_factor, .. } => { info!("Window={window_id:?} changed scale to {scale_factor}"); }, - WindowEvent::ThemeChanged(theme) => { + SurfaceEvent::ThemeChanged(theme) => { info!("Theme changed to {theme:?}"); window.set_draw_theme(theme); }, - WindowEvent::RedrawRequested => { + SurfaceEvent::RedrawRequested => { if let Err(err) = window.draw() { error!("Error drawing window: {err}"); } }, - WindowEvent::Occluded(occluded) => { + SurfaceEvent::Occluded(occluded) => { window.set_occluded(occluded); }, - WindowEvent::CloseRequested => { + SurfaceEvent::CloseRequested => { info!("Closing Window={window_id:?}"); self.windows.remove(&window_id); }, - WindowEvent::ModifiersChanged(modifiers) => { + SurfaceEvent::ModifiersChanged(modifiers) => { window.modifiers = modifiers.state(); info!("Modifiers changed to {:?}", window.modifiers); }, - WindowEvent::MouseWheel { delta, .. } => match delta { + SurfaceEvent::MouseWheel { delta, .. } => match delta { MouseScrollDelta::LineDelta(x, y) => { info!("Mouse wheel Line Delta: ({x},{y})"); }, @@ -430,7 +430,7 @@ impl ApplicationHandler for Application { info!("Mouse wheel Pixel Delta: ({},{})", px.x, px.y); }, }, - WindowEvent::KeyboardInput { event, is_synthetic: false, .. } => { + SurfaceEvent::KeyboardInput { event, is_synthetic: false, .. } => { let mods = window.modifiers; // Dispatch actions only on press. @@ -446,7 +446,7 @@ impl ApplicationHandler for Application { } } }, - WindowEvent::PointerButton { button, state, .. } => { + SurfaceEvent::PointerButton { button, state, .. } => { info!("Pointer button {button:?} {state:?}"); let mods = window.modifiers; if let Some(action) = state @@ -457,15 +457,15 @@ impl ApplicationHandler for Application { self.handle_action_with_window(event_loop, window_id, action); } }, - WindowEvent::PointerLeft { .. } => { + SurfaceEvent::PointerLeft { .. } => { info!("Pointer left Window={window_id:?}"); window.cursor_left(); }, - WindowEvent::PointerMoved { position, .. } => { + SurfaceEvent::PointerMoved { position, .. } => { info!("Moved pointer to {position:?}"); window.cursor_moved(position); }, - WindowEvent::ActivationTokenDone { token: _token, .. } => { + SurfaceEvent::ActivationTokenDone { token: _token, .. } => { #[cfg(any(x11_platform, wayland_platform))] { startup_notify::set_activation_token_env(_token); @@ -474,7 +474,7 @@ impl ApplicationHandler for Application { } } }, - WindowEvent::Ime(event) => match event { + SurfaceEvent::Ime(event) => match event { Ime::Enabled => info!("IME enabled for Window={window_id:?}"), Ime::Preedit(text, caret_pos) => { info!("Preedit: {}, with caret at {:?}", text, caret_pos); @@ -484,7 +484,7 @@ impl ApplicationHandler for Application { }, Ime::Disabled => info!("IME disabled for Window={window_id:?}"), }, - WindowEvent::PinchGesture { delta, .. } => { + SurfaceEvent::PinchGesture { delta, .. } => { window.zoom += delta; let zoom = window.zoom; if delta > 0.0 { @@ -493,7 +493,7 @@ impl ApplicationHandler for Application { info!("Zoomed out {delta:.5} (now: {zoom:.5})"); } }, - WindowEvent::RotationGesture { delta, .. } => { + SurfaceEvent::RotationGesture { delta, .. } => { window.rotated += delta; let rotated = window.rotated; if delta > 0.0 { @@ -502,22 +502,22 @@ impl ApplicationHandler for Application { info!("Rotated clockwise {delta:.5} (now: {rotated:.5})"); } }, - WindowEvent::PanGesture { delta, phase, .. } => { + SurfaceEvent::PanGesture { delta, phase, .. } => { window.panned.x += delta.x; window.panned.y += delta.y; info!("Panned ({delta:?})) (now: {:?}), {phase:?}", window.panned); }, - WindowEvent::DoubleTapGesture { .. } => { + SurfaceEvent::DoubleTapGesture { .. } => { info!("Smart zoom"); }, - WindowEvent::TouchpadPressure { .. } - | WindowEvent::HoveredFileCancelled - | WindowEvent::KeyboardInput { .. } - | WindowEvent::PointerEntered { .. } - | WindowEvent::DroppedFile(_) - | WindowEvent::HoveredFile(_) - | WindowEvent::Destroyed - | WindowEvent::Moved(_) => (), + SurfaceEvent::TouchpadPressure { .. } + | SurfaceEvent::HoveredFileCancelled + | SurfaceEvent::KeyboardInput { .. } + | SurfaceEvent::PointerEntered { .. } + | SurfaceEvent::DroppedFile(_) + | SurfaceEvent::HoveredFile(_) + | SurfaceEvent::Destroyed + | SurfaceEvent::Moved(_) => (), } } diff --git a/examples/x11_embed.rs b/examples/x11_embed.rs index 1b9a796ff6..bcf00a110d 100644 --- a/examples/x11_embed.rs +++ b/examples/x11_embed.rs @@ -4,10 +4,10 @@ use std::error::Error; #[cfg(x11_platform)] fn main() -> Result<(), Box> { use winit::application::ApplicationHandler; - use winit::event::WindowEvent; + use winit::event::SurfaceEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::platform::x11::WindowAttributesExtX11; - use winit::window::{Window, WindowAttributes, WindowId}; + use winit::window::{Window, WindowAttributes, SurfaceId}; #[path = "util/fill.rs"] mod fill; @@ -30,13 +30,13 @@ fn main() -> Result<(), Box> { fn window_event( &mut self, event_loop: &dyn ActiveEventLoop, - _window_id: WindowId, - event: WindowEvent, + _window_id: SurfaceId, + event: SurfaceEvent, ) { let window = self.window.as_ref().unwrap(); match event { - WindowEvent::CloseRequested => event_loop.exit(), - WindowEvent::RedrawRequested => { + SurfaceEvent::CloseRequested => event_loop.exit(), + SurfaceEvent::RedrawRequested => { window.pre_present_notify(); fill::fill_window(window.as_ref()); }, diff --git a/src/application.rs b/src/application.rs index f361ca76c7..e59706b9de 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,8 +1,8 @@ //! End user application handling. -use crate::event::{DeviceEvent, DeviceId, StartCause, WindowEvent}; +use crate::event::{DeviceEvent, DeviceId, StartCause, SurfaceEvent}; use crate::event_loop::ActiveEventLoop; -use crate::window::WindowId; +use crate::window::SurfaceId; /// The handler of the application events. pub trait ApplicationHandler { @@ -135,8 +135,8 @@ pub trait ApplicationHandler { /// # fn window_event( /// # &mut self, /// # _event_loop: &dyn ActiveEventLoop, - /// # _window_id: winit::window::WindowId, - /// # _event: winit::event::WindowEvent, + /// # _window_id: winit::window::SurfaceId, + /// # _event: winit::event::SurfaceEvent, /// # ) { /// # } /// # @@ -196,8 +196,8 @@ pub trait ApplicationHandler { fn window_event( &mut self, event_loop: &dyn ActiveEventLoop, - window_id: WindowId, - event: WindowEvent, + window_id: SurfaceId, + event: SurfaceEvent, ); /// Emitted when the OS sends an event to a device. @@ -220,7 +220,7 @@ pub trait ApplicationHandler { /// ups and also lots of corresponding `AboutToWait` events. /// /// This is not an ideal event to drive application rendering from and instead applications - /// should render in response to [`WindowEvent::RedrawRequested`] events. + /// should render in response to [`SurfaceEvent::RedrawRequested`] events. fn about_to_wait(&mut self, event_loop: &dyn ActiveEventLoop) { let _ = event_loop; } @@ -371,8 +371,8 @@ impl ApplicationHandler for &mut A { fn window_event( &mut self, event_loop: &dyn ActiveEventLoop, - window_id: WindowId, - event: WindowEvent, + window_id: SurfaceId, + event: SurfaceEvent, ) { (**self).window_event(event_loop, window_id, event); } @@ -439,8 +439,8 @@ impl ApplicationHandler for Box { fn window_event( &mut self, event_loop: &dyn ActiveEventLoop, - window_id: WindowId, - event: WindowEvent, + window_id: SurfaceId, + event: SurfaceEvent, ) { (**self).window_event(event_loop, window_id, event); } diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 3ba37240e3..151a21692c 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -62,7 +62,7 @@ changelog entry. - Add basic iOS IME support. The soft keyboard can now be shown using `Window::set_ime_allowed`. - On macOS, add `WindowExtMacOS::set_borderless_game` and `WindowAttributesExtMacOS::with_borderless_game` to fully disable the menu bar and dock in Borderless Fullscreen as commonly done in games. -- Add `WindowId::into_raw()` and `from_raw()`. +- Add `SurfaceId::into_raw()` and `from_raw()`. - Add `PointerKind`, `PointerSource`, `ButtonSource`, `FingerId` and `position` to all pointer events as part of the pointer event overhaul. - Add `DeviceId::into_raw()` and `from_raw()`. @@ -109,7 +109,7 @@ changelog entry. `application:didFinishLaunchingWithOptions:` and provide the desired behaviour yourself. - On X11, remove our dependency on libXcursor. (#3749) - Renamed the following APIs to make it clearer that the sizes apply to the underlying surface: - - `WindowEvent::Resized` to `SurfaceResized`. + - `SurfaceEvent::Resized` to `SurfaceResized`. - `InnerSizeWriter` to `SurfaceSizeWriter`. - `WindowAttributes.inner_size` to `surface_size`. - `WindowAttributes.min_inner_size` to `min_surface_size`. @@ -127,7 +127,7 @@ changelog entry. To migrate, you can probably just replace all instances of `inner_size` with `surface_size` in your codebase. - Every event carrying a `DeviceId` now uses `Option` instead. A `None` value signifies that the device can't be uniquely identified. -- Pointer `WindowEvent`s were overhauled. The new events can handle any type of pointer, serving as +- Pointer `SurfaceEvent`s were overhauled. The new events can handle any type of pointer, serving as a single pointer input source. Now your application can handle any pointer type without having to explicitly handle e.g. `Touch`: - Rename `CursorMoved` to `PointerMoved`. @@ -171,14 +171,14 @@ changelog entry. - Remove the `rwh_04` and `rwh_05` cargo feature and the corresponding `raw-window-handle` v0.4 and v0.5 support. v0.6 remains in place and is enabled by default. - Remove `DeviceEvent::Added` and `DeviceEvent::Removed`. -- Remove `DeviceEvent::Motion` and `WindowEvent::AxisMotion`. +- Remove `DeviceEvent::Motion` and `SurfaceEvent::AxisMotion`. - Remove `MonitorHandle::size()` and `refresh_rate_millihertz()` in favor of `MonitorHandle::current_video_mode()`. - On Android, remove all `MonitorHandle` support instead of emitting false data. - Remove `impl From for WindowId` and `impl From for u64`. Replaced with - `WindowId::into_raw()` and `from_raw()`. -- Remove `dummy()` from `WindowId` and `DeviceId`. -- Remove `WindowEvent::Touch` and `Touch` in favor of the new `PointerKind`, `PointerSource` and + `SurfaceId::into_raw()` and `from_raw()`. +- Remove `dummy()` from `SurfaceId` and `DeviceId`. +- Remove `SurfaceEvent::Touch` and `Touch` in favor of the new `PointerKind`, `PointerSource` and `ButtonSource` as part of the new pointer event overhaul. - Remove `Force::altitude_angle`. diff --git a/src/event.rs b/src/event.rs index 5b611dd137..5bdf5d9cbf 100644 --- a/src/event.rs +++ b/src/event.rs @@ -52,7 +52,7 @@ use crate::keyboard::{self, ModifiersKeyState, ModifiersKeys, ModifiersState}; use crate::platform_impl; #[cfg(doc)] use crate::window::{Surface, Window}; -use crate::window::{ActivationToken, Theme, WindowId}; +use crate::window::{ActivationToken, Theme, SurfaceId}; // TODO: Remove once the backends can call `ApplicationHandler` methods directly. For now backends // like Windows and Web require `Event` to wire user events, otherwise each backend will have to @@ -72,7 +72,7 @@ pub(crate) enum Event { /// /// [`ApplicationHandler::window_event()`]: crate::application::ApplicationHandler::window_event() #[allow(clippy::enum_variant_names)] - WindowEvent { window_id: WindowId, event: WindowEvent }, + WindowEvent { window_id: SurfaceId, event: SurfaceEvent }, /// See [`ApplicationHandler::device_event()`] for details. /// @@ -138,9 +138,9 @@ pub enum StartCause { Init, } -/// Describes an event from a [`Window`]. +/// Describes an event from a [`Surface`]. #[derive(Debug, Clone, PartialEq)] -pub enum WindowEvent { +pub enum SurfaceEvent { /// The activation token was delivered back and now could be used. #[cfg_attr(not(any(x11_platform, wayland_platform)), allow(rustdoc::broken_intra_doc_links))] /// Delivered in response to [`request_activation_token`]. @@ -482,23 +482,23 @@ pub enum PointerSource { Mouse, /// Represents a touch event. /// - /// Every time the user touches the screen, a [`WindowEvent::PointerEntered`] and a - /// [`WindowEvent::PointerButton`] with [`ElementState::Pressed`] event with an unique + /// Every time the user touches the screen, a [`SurfaceEvent::PointerEntered`] and a + /// [`SurfaceEvent::PointerButton`] with [`ElementState::Pressed`] event with an unique /// identifier for the finger is emitted. When a finger is lifted, a - /// [`WindowEvent::PointerButton`] with [`ElementState::Released`] and a - /// [`WindowEvent::PointerLeft`] event is generated with the same [`FingerId`]. + /// [`SurfaceEvent::PointerButton`] with [`ElementState::Released`] and a + /// [`SurfaceEvent::PointerLeft`] event is generated with the same [`FingerId`]. /// - /// After a [`WindowEvent::PointerEntered`] event has been emitted, there may be zero or more - /// [`WindowEvent::PointerMoved`] events when the finger is moved or the touch pressure + /// After a [`SurfaceEvent::PointerEntered`] event has been emitted, there may be zero or more + /// [`SurfaceEvent::PointerMoved`] events when the finger is moved or the touch pressure /// changes. /// - /// A [`WindowEvent::PointerLeft`] without a [`WindowEvent::PointerButton`] with + /// A [`SurfaceEvent::PointerLeft`] without a [`SurfaceEvent::PointerButton`] with /// [`ElementState::Released`] event is emitted when the system has canceled tracking this /// touch, such as when the window loses focus, or on mobile devices if the user moves the /// device against their face. /// - /// The [`FingerId`] may be reused by the system after a [`WindowEvent::PointerLeft`] event. - /// The user should assume that a new [`WindowEvent::PointerEntered`] event received with the + /// The [`FingerId`] may be reused by the system after a [`SurfaceEvent::PointerLeft`] event. + /// The user should assume that a new [`SurfaceEvent::PointerEntered`] event received with the /// same ID has nothing to do with the old finger and is a new finger. /// /// ## Platform-specific @@ -533,7 +533,7 @@ impl From for PointerKind { } } -/// Represents the pointer type of a [`WindowEvent::PointerButton`]. +/// Represents the pointer type of a [`SurfaceEvent::PointerButton`]. /// /// **Wayland/X11:** [`Unknown`](Self::Unknown) device types are converted to known variants by the /// system. @@ -632,7 +632,7 @@ pub enum DeviceEvent { /// Change in physical position of a pointing device. /// /// This represents raw, unfiltered physical motion. Not to be confused with - /// [`WindowEvent::PointerMoved`]. + /// [`SurfaceEvent::PointerMoved`]. /// /// ## Platform-specific /// @@ -790,11 +790,11 @@ pub struct KeyEvent { /// done by ignoring events where this property is set. /// /// ```no_run - /// use winit::event::{ElementState, KeyEvent, WindowEvent}; + /// use winit::event::{ElementState, KeyEvent, SurfaceEvent}; /// use winit::keyboard::{KeyCode, PhysicalKey}; - /// # let window_event = WindowEvent::RedrawRequested; // To make the example compile + /// # let window_event = SurfaceEvent::RedrawRequested; // To make the example compile /// match window_event { - /// WindowEvent::KeyboardInput { + /// SurfaceEvent::KeyboardInput { /// event: /// KeyEvent { /// physical_key: PhysicalKey::Code(KeyCode::KeyW), @@ -898,7 +898,7 @@ impl From for Modifiers { /// This is also called a "composition event". /// /// Most keypresses using a latin-like keyboard layout simply generate a -/// [`WindowEvent::KeyboardInput`]. However, one couldn't possibly have a key for every single +/// [`SurfaceEvent::KeyboardInput`]. However, one couldn't possibly have a key for every single /// unicode character that the user might want to type /// - so the solution operating systems employ is to allow the user to type these using _a sequence /// of keypresses_ instead. @@ -1085,7 +1085,7 @@ pub enum MouseScrollDelta { PixelDelta(PhysicalPosition), } -/// Handle to synchronously change the size of the window from the [`WindowEvent`]. +/// Handle to synchronously change the size of the window from the [`SurfaceEvent`]. #[derive(Debug, Clone)] pub struct SurfaceSizeWriter { pub(crate) new_surface_size: Weak>>, @@ -1136,12 +1136,12 @@ mod tests { { use crate::event::Event::*; use crate::event::Ime::Enabled; - use crate::event::WindowEvent::*; + use crate::event::SurfaceEvent::*; use crate::event::{PointerKind, PointerSource}; - use crate::window::WindowId; + use crate::window::SurfaceId; // Mainline events. - let wid = WindowId::from_raw(0); + let wid = SurfaceId::from_raw(0); x(NewEvents(event::StartCause::Init)); x(AboutToWait); x(LoopExiting); diff --git a/src/lib.rs b/src/lib.rs index 52f73f53f0..db7c24a177 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,10 +15,10 @@ //! # Event handling //! //! Once a [`Window`] has been created, it will generate different *events*. A [`Window`] object can -//! generate [`WindowEvent`]s when certain input events occur, such as a cursor moving over the +//! generate [`SurfaceEvent`]s when certain input events occur, such as a cursor moving over the //! window or a key getting pressed while the window is focused. Devices can generate //! [`DeviceEvent`]s, which contain unfiltered event data that isn't specific to a certain window. -//! Some user activity, like mouse movement, can generate both a [`WindowEvent`] *and* a +//! Some user activity, like mouse movement, can generate both a [`SurfaceEvent`] *and* a //! [`DeviceEvent`]. //! //! You can retrieve events by calling [`EventLoop::run_app()`]. This function will @@ -42,9 +42,9 @@ //! //! ```no_run //! use winit::application::ApplicationHandler; -//! use winit::event::WindowEvent; +//! use winit::event::SurfaceEvent; //! use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; -//! use winit::window::{Window, WindowId, WindowAttributes}; +//! use winit::window::{Window, SurfaceId, WindowAttributes}; //! //! #[derive(Default)] //! struct App { @@ -56,13 +56,13 @@ //! self.window = Some(event_loop.create_window(WindowAttributes::default()).unwrap()); //! } //! -//! fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, id: WindowId, event: WindowEvent) { +//! fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, id: SurfaceId, event: SurfaceEvent) { //! match event { -//! WindowEvent::CloseRequested => { +//! SurfaceEvent::CloseRequested => { //! println!("The close button was pressed; stopping"); //! event_loop.exit(); //! }, -//! WindowEvent::RedrawRequested => { +//! SurfaceEvent::RedrawRequested => { //! // Redraw the application. //! // //! // It's preferable for applications that do not render continuously to render in @@ -98,7 +98,7 @@ //! event_loop.run_app(&mut app); //! ``` //! -//! [`WindowEvent`] has a [`WindowId`] member. In multi-window environments, it should be +//! [`SurfaceEvent`] has a [`SurfaceId`] member. In multi-window environments, it should be //! compared to the value returned by [`Surface::id()`] to determine which [`Window`] //! dispatched the event. //! @@ -131,7 +131,7 @@ //! factor. If a window hasn't received a [`ScaleFactorChanged`] event, its scale factor //! can be found by calling [`window.scale_factor()`]. //! -//! [`ScaleFactorChanged`]: event::WindowEvent::ScaleFactorChanged +//! [`ScaleFactorChanged`]: event::SurfaceEvent::ScaleFactorChanged //! [`window.scale_factor()`]: window::Surface::scale_factor //! //! # Cargo Features @@ -208,12 +208,12 @@ //! [`EventLoop::run_app()`]: event_loop::EventLoop::run_app //! [`exit()`]: event_loop::ActiveEventLoop::exit //! [`Window`]: window::Window -//! [`WindowId`]: window::WindowId +//! [`SurfaceId`]: window::SurfaceId //! [`WindowAttributes`]: window::WindowAttributes //! [window_new]: window::Window::new //! [`create_window`]: event_loop::ActiveEventLoop::create_window //! [`Surface::id()`]: window::Surface::id -//! [`WindowEvent`]: event::WindowEvent +//! [`SurfaceEvent`]: event::SurfaceEvent //! [`DeviceEvent`]: event::DeviceEvent //! [`Event::UserEvent`]: event::Event::UserEvent //! [`exiting()`]: crate::application::ApplicationHandler::exiting diff --git a/src/platform/web.rs b/src/platform/web.rs index 7002a8682a..0e86e00ef0 100644 --- a/src/platform/web.rs +++ b/src/platform/web.rs @@ -27,18 +27,18 @@ //! - [`padding`](https://developer.mozilla.org/en-US/docs/Web/CSS/padding) //! //! The following APIs can't take them into account and will therefore provide inaccurate results: -//! - [`WindowEvent::SurfaceResized`] and [`Window::(set_)surface_size()`] -//! - [`WindowEvent::Occluded`] -//! - [`WindowEvent::PointerMoved`], [`WindowEvent::PointerEntered`] and -//! [`WindowEvent::PointerLeft`]. +//! - [`SurfaceEvent::SurfaceResized`] and [`Window::(set_)surface_size()`] +//! - [`SurfaceEvent::Occluded`] +//! - [`SurfaceEvent::PointerMoved`], [`SurfaceEvent::PointerEntered`] and +//! [`SurfaceEvent::PointerLeft`]. //! - [`Window::set_outer_position()`] //! -//! [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized +//! [`SurfaceEvent::SurfaceResized`]: crate::event::SurfaceEvent::SurfaceResized //! [`Window::(set_)surface_size()`]: crate::window::Surface::surface_size -//! [`WindowEvent::Occluded`]: crate::event::WindowEvent::Occluded -//! [`WindowEvent::PointerMoved`]: crate::event::WindowEvent::PointerMoved -//! [`WindowEvent::PointerEntered`]: crate::event::WindowEvent::PointerEntered -//! [`WindowEvent::PointerLeft`]: crate::event::WindowEvent::PointerLeft +//! [`SurfaceEvent::Occluded`]: crate::event::SurfaceEvent::Occluded +//! [`SurfaceEvent::PointerMoved`]: crate::event::SurfaceEvent::PointerMoved +//! [`SurfaceEvent::PointerEntered`]: crate::event::SurfaceEvent::PointerEntered +//! [`SurfaceEvent::PointerLeft`]: crate::event::SurfaceEvent::PointerLeft //! [`Window::set_outer_position()`]: crate::window::Window::set_outer_position use std::cell::Ref; diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 912e61e54a..104221f5d5 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -191,12 +191,12 @@ impl EventLoop { }, MainEvent::GainedFocus => { HAS_FOCUS.store(true, Ordering::Relaxed); - let event = event::WindowEvent::Focused(true); + let event = event::SurfaceEvent::Focused(true); app.window_event(&self.window_target, GLOBAL_WINDOW, event); }, MainEvent::LostFocus => { HAS_FOCUS.store(false, Ordering::Relaxed); - let event = event::WindowEvent::Focused(false); + let event = event::SurfaceEvent::Focused(false); app.window_event(&self.window_target, GLOBAL_WINDOW, event); }, MainEvent::ConfigChanged { .. } => { @@ -204,7 +204,7 @@ impl EventLoop { let scale_factor = scale_factor(&self.android_app); if (scale_factor - old_scale_factor).abs() < f64::EPSILON { let new_surface_size = Arc::new(Mutex::new(screen_size(&self.android_app))); - let event = event::WindowEvent::ScaleFactorChanged { + let event = event::SurfaceEvent::ScaleFactorChanged { surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade( &new_surface_size, )), @@ -287,14 +287,14 @@ impl EventLoop { } else { PhysicalSize::new(0, 0) }; - let event = event::WindowEvent::SurfaceResized(size); + let event = event::SurfaceEvent::SurfaceResized(size); app.window_event(&self.window_target, GLOBAL_WINDOW, event); } pending_redraw |= self.redraw_flag.get_and_reset(); if pending_redraw { pending_redraw = false; - let event = event::WindowEvent::RedrawRequested; + let event = event::SurfaceEvent::RedrawRequested; app.window_event(&self.window_target, GLOBAL_WINDOW, event); } } @@ -347,7 +347,7 @@ impl EventLoop { match action { MotionAction::Down | MotionAction::PointerDown => { - let event = event::WindowEvent::PointerEntered { + let event = event::SurfaceEvent::PointerEntered { device_id, position, kind: match tool_type { @@ -360,7 +360,7 @@ impl EventLoop { }, }; app.window_event(&self.window_target, GLOBAL_WINDOW, event); - let event = event::WindowEvent::PointerButton { + let event = event::SurfaceEvent::PointerButton { device_id, state: event::ElementState::Pressed, position, @@ -376,7 +376,7 @@ impl EventLoop { app.window_event(&self.window_target, GLOBAL_WINDOW, event); }, MotionAction::Move => { - let event = event::WindowEvent::PointerMoved { + let event = event::SurfaceEvent::PointerMoved { device_id, position, source: match tool_type { @@ -392,7 +392,7 @@ impl EventLoop { }, MotionAction::Up | MotionAction::PointerUp | MotionAction::Cancel => { if let MotionAction::Up | MotionAction::PointerUp = action { - let event = event::WindowEvent::PointerButton { + let event = event::SurfaceEvent::PointerButton { device_id, state: event::ElementState::Released, position, @@ -408,7 +408,7 @@ impl EventLoop { app.window_event(&self.window_target, GLOBAL_WINDOW, event); } - let event = event::WindowEvent::PointerLeft { + let event = event::SurfaceEvent::PointerLeft { device_id, position: Some(position), kind: match tool_type { @@ -451,7 +451,7 @@ impl EventLoop { &mut self.combining_accent, ); - let event = event::WindowEvent::KeyboardInput { + let event = event::SurfaceEvent::KeyboardInput { device_id: Some(DeviceId::from_raw(key.device_id() as i64)), event: event::KeyEvent { state, diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index b7bf9f5a13..c615550783 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -15,7 +15,7 @@ use crate::application::ApplicationHandler; use crate::cursor::OnlyCursorImage; use crate::dpi::LogicalSize; use crate::error::{EventLoopError, OsError, RequestError}; -use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent}; +use crate::event::{Event, StartCause, SurfaceSizeWriter, SurfaceEvent}; use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents}; use crate::platform::pump_events::PumpStatus; use crate::platform_impl::platform::min_timeout; @@ -30,7 +30,7 @@ use sink::EventSink; use super::state::{WindowCompositorUpdate, WinitState}; use super::window::state::FrameCallbackState; -use super::{logical_to_physical_rounded, WindowId}; +use super::{logical_to_physical_rounded, SurfaceId}; type WaylandDispatcher = calloop::Dispatcher<'static, WaylandSource, WinitState>; @@ -41,7 +41,7 @@ pub struct EventLoop { buffer_sink: EventSink, compositor_updates: Vec, - window_ids: Vec, + window_ids: Vec, /// The Wayland dispatcher to has raw access to the queue when needed, such as /// when creating a new window. @@ -312,7 +312,7 @@ impl EventLoop { let old_physical_size = physical_size; let new_surface_size = Arc::new(Mutex::new(physical_size)); - let event = WindowEvent::ScaleFactorChanged { + let event = SurfaceEvent::ScaleFactorChanged { scale_factor, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)), }; @@ -360,12 +360,12 @@ impl EventLoop { size }); - let event = WindowEvent::SurfaceResized(physical_size); + let event = SurfaceEvent::SurfaceResized(physical_size); app.window_event(&self.active_event_loop, window_id, event); } if compositor_update.close_window { - app.window_event(&self.active_event_loop, window_id, WindowEvent::CloseRequested); + app.window_event(&self.active_event_loop, window_id, SurfaceEvent::CloseRequested); } } @@ -412,7 +412,7 @@ impl EventLoop { if window_requests.get(window_id).unwrap().take_closed() { mem::drop(window_requests.remove(window_id)); mem::drop(state.windows.get_mut().remove(window_id)); - return Some(WindowEvent::Destroyed); + return Some(SurfaceEvent::Destroyed); } let mut window = @@ -430,7 +430,7 @@ impl EventLoop { // Redraw the frame while at it. redraw_requested |= window.refresh_frame(); - redraw_requested.then_some(WindowEvent::RedrawRequested) + redraw_requested.then_some(SurfaceEvent::RedrawRequested) }); if let Some(event) = event { diff --git a/src/platform_impl/linux/wayland/event_loop/sink.rs b/src/platform_impl/linux/wayland/event_loop/sink.rs index a7ad7a22f6..8f988afc02 100644 --- a/src/platform_impl/linux/wayland/event_loop/sink.rs +++ b/src/platform_impl/linux/wayland/event_loop/sink.rs @@ -2,8 +2,8 @@ use std::vec::Drain; -use crate::event::{DeviceEvent, Event, WindowEvent}; -use crate::window::WindowId; +use crate::event::{DeviceEvent, Event, SurfaceEvent}; +use crate::window::SurfaceId; /// An event loop's sink to deliver events from the Wayland event callbacks /// to the winit's user. @@ -31,7 +31,7 @@ impl EventSink { /// Add new window event to a queue. #[inline] - pub fn push_window_event(&mut self, event: WindowEvent, window_id: WindowId) { + pub fn push_window_event(&mut self, event: SurfaceEvent, window_id: SurfaceId) { self.window_events.push(Event::WindowEvent { event, window_id }); } diff --git a/src/platform_impl/linux/wayland/mod.rs b/src/platform_impl/linux/wayland/mod.rs index d85134fc29..5aa0b4561a 100644 --- a/src/platform_impl/linux/wayland/mod.rs +++ b/src/platform_impl/linux/wayland/mod.rs @@ -8,7 +8,7 @@ pub use window::Window; pub(super) use crate::cursor::OnlyCursorImage as CustomCursor; use crate::dpi::{LogicalSize, PhysicalSize}; -use crate::window::WindowId; +use crate::window::SurfaceId; mod event_loop; mod output; @@ -29,8 +29,8 @@ impl FingerId { /// Get the WindowId out of the surface. #[inline] -fn make_wid(surface: &WlSurface) -> WindowId { - WindowId::from_raw(surface.id().as_ptr() as usize) +fn make_wid(surface: &WlSurface) -> SurfaceId { + SurfaceId::from_raw(surface.id().as_ptr() as usize) } /// The default routine does floor, but we need round on Wayland. diff --git a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs index 871df785e3..dba5209b11 100644 --- a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs +++ b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs @@ -12,12 +12,12 @@ use sctk::reexports::client::protocol::wl_seat::WlSeat; use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, WEnum}; use tracing::warn; -use crate::event::{ElementState, WindowEvent}; +use crate::event::{ElementState, SurfaceEvent}; use crate::keyboard::ModifiersState; use crate::platform_impl::common::xkb::Context; use crate::platform_impl::wayland::event_loop::sink::EventSink; use crate::platform_impl::wayland::state::WinitState; -use crate::platform_impl::wayland::{self, WindowId}; +use crate::platform_impl::wayland::{self, SurfaceId}; impl Dispatch for WinitState { fn event( @@ -83,13 +83,13 @@ impl Dispatch for WinitState { // The keyboard focus is considered as general focus. if was_unfocused { - state.events_sink.push_window_event(WindowEvent::Focused(true), window_id); + state.events_sink.push_window_event(SurfaceEvent::Focused(true), window_id); } // HACK: this is just for GNOME not fixing their ordering issue of modifiers. if std::mem::take(&mut seat_state.modifiers_pending) { state.events_sink.push_window_event( - WindowEvent::ModifiersChanged(seat_state.modifiers.into()), + SurfaceEvent::ModifiersChanged(seat_state.modifiers.into()), window_id, ); } @@ -122,11 +122,11 @@ impl Dispatch for WinitState { if !focused { // Notify that no modifiers are being pressed. state.events_sink.push_window_event( - WindowEvent::ModifiersChanged(ModifiersState::empty().into()), + SurfaceEvent::ModifiersChanged(ModifiersState::empty().into()), window_id, ); - state.events_sink.push_window_event(WindowEvent::Focused(false), window_id); + state.events_sink.push_window_event(SurfaceEvent::Focused(false), window_id); } }, WlKeyboardEvent::Key { key, state: WEnum::Value(WlKeyState::Pressed), .. } => { @@ -245,7 +245,7 @@ impl Dispatch for WinitState { }; state.events_sink.push_window_event( - WindowEvent::ModifiersChanged(seat_state.modifiers.into()), + SurfaceEvent::ModifiersChanged(seat_state.modifiers.into()), window_id, ); }, @@ -344,7 +344,7 @@ impl Default for RepeatInfo { #[derive(Debug)] pub struct KeyboardData { /// The currently focused window surface. Could be `None` on bugged compositors, like mutter. - window_id: Mutex>, + window_id: Mutex>, /// The seat used to create this keyboard. seat: WlSeat, @@ -371,7 +371,7 @@ fn key_input( if let Some(mut key_context) = keyboard_state.xkb_context.key_context() { let event = key_context.process_key_event(keycode, state, repeat); - let event = WindowEvent::KeyboardInput { device_id: None, event, is_synthetic: false }; + let event = SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false }; event_sink.push_window_event(event, window_id); } } diff --git a/src/platform_impl/linux/wayland/seat/mod.rs b/src/platform_impl/linux/wayland/seat/mod.rs index 36af28a535..6291df7004 100644 --- a/src/platform_impl/linux/wayland/seat/mod.rs +++ b/src/platform_impl/linux/wayland/seat/mod.rs @@ -13,7 +13,7 @@ use sctk::seat::pointer::{ThemeSpec, ThemedPointer}; use sctk::seat::{Capability as SeatCapability, SeatHandler, SeatState}; use tracing::warn; -use crate::event::WindowEvent; +use crate::event::SurfaceEvent; use crate::keyboard::ModifiersState; use crate::platform_impl::wayland::state::WinitState; @@ -219,7 +219,7 @@ impl WinitState { let had_focus = window.has_focus(); window.remove_seat_focus(seat); if had_focus != window.has_focus() { - self.events_sink.push_window_event(WindowEvent::Focused(false), *window_id); + self.events_sink.push_window_event(SurfaceEvent::Focused(false), *window_id); } } } diff --git a/src/platform_impl/linux/wayland/seat/pointer/mod.rs b/src/platform_impl/linux/wayland/seat/pointer/mod.rs index c6d151901f..661781feea 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/mod.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/mod.rs @@ -29,11 +29,11 @@ use sctk::seat::SeatState; use crate::dpi::{LogicalPosition, PhysicalPosition}; use crate::event::{ ElementState, MouseButton, MouseScrollDelta, PointerKind, PointerSource, TouchPhase, - WindowEvent, + SurfaceEvent, }; use crate::platform_impl::wayland::state::WinitState; -use crate::platform_impl::wayland::{self, WindowId}; +use crate::platform_impl::wayland::{self, SurfaceId}; pub mod relative_pointer; @@ -126,7 +126,7 @@ impl PointerHandler for WinitState { // Regular events on the main surface. PointerEventKind::Enter { .. } => { self.events_sink.push_window_event( - WindowEvent::PointerEntered { + SurfaceEvent::PointerEntered { device_id: None, position, kind: PointerKind::Mouse, @@ -146,7 +146,7 @@ impl PointerHandler for WinitState { pointer.winit_data().inner.lock().unwrap().surface = None; self.events_sink.push_window_event( - WindowEvent::PointerLeft { + SurfaceEvent::PointerLeft { device_id: None, position: Some(position), kind: PointerKind::Mouse, @@ -156,7 +156,7 @@ impl PointerHandler for WinitState { }, PointerEventKind::Motion { .. } => { self.events_sink.push_window_event( - WindowEvent::PointerMoved { + SurfaceEvent::PointerMoved { device_id: None, position, source: PointerSource::Mouse, @@ -176,7 +176,7 @@ impl PointerHandler for WinitState { ElementState::Released }; self.events_sink.push_window_event( - WindowEvent::PointerButton { + SurfaceEvent::PointerButton { device_id: None, state, position, @@ -226,7 +226,7 @@ impl PointerHandler for WinitState { }; self.events_sink.push_window_event( - WindowEvent::MouseWheel { device_id: None, delta, phase }, + SurfaceEvent::MouseWheel { device_id: None, delta, phase }, window_id, ) }, @@ -309,7 +309,7 @@ impl WinitPointerData { } /// Active window. - pub fn focused_window(&self) -> Option { + pub fn focused_window(&self) -> Option { self.inner.lock().unwrap().surface } @@ -349,7 +349,7 @@ pub struct WinitPointerDataInner { latest_button_serial: u32, /// Currently focused window. - surface: Option, + surface: Option, /// Current axis phase. phase: TouchPhase, diff --git a/src/platform_impl/linux/wayland/seat/text_input/mod.rs b/src/platform_impl/linux/wayland/seat/text_input/mod.rs index dff3723513..8d15ddf0ff 100644 --- a/src/platform_impl/linux/wayland/seat/text_input/mod.rs +++ b/src/platform_impl/linux/wayland/seat/text_input/mod.rs @@ -9,7 +9,7 @@ use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3:: ContentHint, ContentPurpose, Event as TextInputEvent, ZwpTextInputV3, }; -use crate::event::{Ime, WindowEvent}; +use crate::event::{Ime, SurfaceEvent}; use crate::platform_impl::wayland; use crate::platform_impl::wayland::state::WinitState; use crate::window::ImePurpose; @@ -73,7 +73,7 @@ impl Dispatch for TextInputState { text_input.enable(); text_input.set_content_type_by_purpose(window.ime_purpose()); text_input.commit(); - state.events_sink.push_window_event(WindowEvent::Ime(Ime::Enabled), window_id); + state.events_sink.push_window_event(SurfaceEvent::Ime(Ime::Enabled), window_id); } window.text_input_entered(text_input); @@ -96,7 +96,7 @@ impl Dispatch for TextInputState { window.text_input_left(text_input); - state.events_sink.push_window_event(WindowEvent::Ime(Ime::Disabled), window_id); + state.events_sink.push_window_event(SurfaceEvent::Ime(Ime::Disabled), window_id); }, TextInputEvent::PreeditString { text, cursor_begin, cursor_end } => { let text = text.unwrap_or_default(); @@ -121,7 +121,7 @@ impl Dispatch for TextInputState { // Clear preedit at the start of `Done`. state.events_sink.push_window_event( - WindowEvent::Ime(Ime::Preedit(String::new(), None)), + SurfaceEvent::Ime(Ime::Preedit(String::new(), None)), window_id, ); @@ -129,7 +129,7 @@ impl Dispatch for TextInputState { if let Some(text) = text_input_data.pending_commit.take() { state .events_sink - .push_window_event(WindowEvent::Ime(Ime::Commit(text)), window_id); + .push_window_event(SurfaceEvent::Ime(Ime::Commit(text)), window_id); } // Send preedit. @@ -138,7 +138,7 @@ impl Dispatch for TextInputState { preedit.cursor_begin.map(|b| (b, preedit.cursor_end.unwrap_or(b))); state.events_sink.push_window_event( - WindowEvent::Ime(Ime::Preedit(preedit.text, cursor_range)), + SurfaceEvent::Ime(Ime::Preedit(preedit.text, cursor_range)), window_id, ); } diff --git a/src/platform_impl/linux/wayland/seat/touch/mod.rs b/src/platform_impl/linux/wayland/seat/touch/mod.rs index cadfbc647f..9ce948bb52 100644 --- a/src/platform_impl/linux/wayland/seat/touch/mod.rs +++ b/src/platform_impl/linux/wayland/seat/touch/mod.rs @@ -8,7 +8,7 @@ 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, PointerKind, PointerSource, SurfaceEvent}; use crate::platform_impl::wayland::state::WinitState; use crate::platform_impl::wayland::{self, FingerId}; @@ -47,7 +47,7 @@ impl TouchHandler for WinitState { crate::event::FingerId(crate::platform_impl::FingerId::Wayland(FingerId(id))); self.events_sink.push_window_event( - WindowEvent::PointerEntered { + SurfaceEvent::PointerEntered { device_id: None, position, kind: PointerKind::Touch(finger_id), @@ -55,7 +55,7 @@ impl TouchHandler for WinitState { window_id, ); self.events_sink.push_window_event( - WindowEvent::PointerButton { + SurfaceEvent::PointerButton { device_id: None, state: ElementState::Pressed, position, @@ -99,7 +99,7 @@ impl TouchHandler for WinitState { crate::event::FingerId(crate::platform_impl::FingerId::Wayland(FingerId(id))); self.events_sink.push_window_event( - WindowEvent::PointerButton { + SurfaceEvent::PointerButton { device_id: None, state: ElementState::Released, position, @@ -108,7 +108,7 @@ impl TouchHandler for WinitState { window_id, ); self.events_sink.push_window_event( - WindowEvent::PointerLeft { + SurfaceEvent::PointerLeft { device_id: None, position: Some(position), kind: PointerKind::Touch(finger_id), @@ -149,7 +149,7 @@ impl TouchHandler for WinitState { touch_point.location = LogicalPosition::::from(position); self.events_sink.push_window_event( - WindowEvent::PointerMoved { + SurfaceEvent::PointerMoved { device_id: None, position: touch_point.location.to_physical(scale_factor), source: PointerSource::Touch { @@ -182,7 +182,7 @@ impl TouchHandler for WinitState { let position = touch_point.location.to_physical(scale_factor); self.events_sink.push_window_event( - WindowEvent::PointerLeft { + SurfaceEvent::PointerLeft { device_id: None, position: Some(position), kind: PointerKind::Touch(crate::event::FingerId( diff --git a/src/platform_impl/linux/wayland/state.rs b/src/platform_impl/linux/wayland/state.rs index bec0a55d3a..7e0bb0f91c 100644 --- a/src/platform_impl/linux/wayland/state.rs +++ b/src/platform_impl/linux/wayland/state.rs @@ -33,7 +33,7 @@ use crate::platform_impl::wayland::types::wp_fractional_scaling::FractionalScali use crate::platform_impl::wayland::types::wp_viewporter::ViewporterState; use crate::platform_impl::wayland::types::xdg_activation::XdgActivationState; use crate::platform_impl::wayland::window::{WindowRequests, WindowState}; -use crate::platform_impl::wayland::WindowId; +use crate::platform_impl::wayland::SurfaceId; /// Winit's Wayland state. pub struct WinitState { @@ -62,10 +62,10 @@ pub struct WinitState { pub xdg_shell: XdgShell, /// The currently present windows. - pub windows: RefCell>>>, + pub windows: RefCell>>>, /// The requests from the `Window` to EventLoop, such as close operations and redraw requests. - pub window_requests: RefCell>>, + pub window_requests: RefCell>>, /// The events that were generated directly from the window. pub window_events_sink: Arc>, @@ -240,7 +240,7 @@ impl WinitState { } } - pub fn queue_close(updates: &mut Vec, window_id: WindowId) { + pub fn queue_close(updates: &mut Vec, window_id: SurfaceId) { let pos = if let Some(pos) = updates.iter().position(|update| update.window_id == window_id) { pos @@ -410,7 +410,7 @@ impl ProvidesRegistryState for WinitState { #[derive(Debug, Clone, Copy)] pub struct WindowCompositorUpdate { /// The id of the window this updates belongs to. - pub window_id: WindowId, + pub window_id: SurfaceId, /// New window size. pub resized: bool, @@ -423,7 +423,7 @@ pub struct WindowCompositorUpdate { } impl WindowCompositorUpdate { - fn new(window_id: WindowId) -> Self { + fn new(window_id: SurfaceId) -> Self { Self { window_id, resized: false, scale_changed: false, close_window: false } } } diff --git a/src/platform_impl/linux/wayland/types/xdg_activation.rs b/src/platform_impl/linux/wayland/types/xdg_activation.rs index 13f9663eaa..d945f36fe4 100644 --- a/src/platform_impl/linux/wayland/types/xdg_activation.rs +++ b/src/platform_impl/linux/wayland/types/xdg_activation.rs @@ -14,7 +14,7 @@ use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1:: use crate::event_loop::AsyncRequestSerial; use crate::platform_impl::wayland::state::WinitState; -use crate::window::{ActivationToken, WindowId}; +use crate::window::{ActivationToken, SurfaceId}; pub struct XdgActivationState { xdg_activation: XdgActivationV1, @@ -76,7 +76,7 @@ impl Dispatch for XdgA }, XdgActivationTokenData::Obtain((window_id, serial)) => { state.events_sink.push_window_event( - crate::event::WindowEvent::ActivationTokenDone { + crate::event::SurfaceEvent::ActivationTokenDone { serial: *serial, token: ActivationToken::_new(token), }, @@ -94,7 +94,7 @@ pub enum XdgActivationTokenData { /// Request user attention for the given surface. Attention((WlSurface, Weak)), /// Get a token to be passed outside of the winit. - Obtain((WindowId, AsyncRequestSerial)), + Obtain((SurfaceId, AsyncRequestSerial)), } delegate_dispatch!(WinitState: [ XdgActivationV1: GlobalData] => XdgActivationState); diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index be15670fc4..421c39f3b9 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -19,14 +19,14 @@ use super::types::xdg_activation::XdgActivationTokenData; use super::ActiveEventLoop; use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{Ime, WindowEvent}; +use crate::event::{Ime, SurfaceEvent}; use crate::event_loop::AsyncRequestSerial; use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::platform_impl::{Fullscreen, MonitorHandle as PlatformMonitorHandle}; use crate::window::{ Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Surface as CoreSurface, Theme, UserAttentionType, Window as CoreWindow, WindowAttributes, - WindowButtons, WindowId, WindowLevel, + WindowButtons, SurfaceId, WindowLevel, }; pub(crate) mod state; @@ -39,7 +39,7 @@ pub struct Window { window: SctkWindow, /// Window id. - window_id: WindowId, + window_id: SurfaceId, /// The state of the window. window_state: Arc>, @@ -183,7 +183,7 @@ impl Window { let window_requests = Arc::new(window_requests); state.window_requests.get_mut().insert(window_id, window_requests.clone()); - // Setup the event sync to insert `WindowEvents` right from the window. + // Setup the event sync to insert `SurfaceEvents` right from the window. let window_events_sink = state.window_events_sink.clone(); let mut wayland_source = event_loop_window_target.wayland_dispatcher.as_source_mut(); @@ -273,7 +273,7 @@ impl rwh_06::HasDisplayHandle for Window { } impl CoreSurface for Window { - fn id(&self) -> WindowId { + fn id(&self) -> SurfaceId { self.window_id } @@ -598,7 +598,7 @@ impl CoreWindow for Window { let mut window_state = self.window_state.lock().unwrap(); if window_state.ime_allowed() != allowed && window_state.set_ime_allowed(allowed) { - let event = WindowEvent::Ime(if allowed { Ime::Enabled } else { Ime::Disabled }); + let event = SurfaceEvent::Ime(if allowed { Ime::Enabled } else { Ime::Disabled }); self.window_events_sink.lock().unwrap().push_window_event(event, self.window_id); self.event_loop_awakener.ping(); } diff --git a/src/platform_impl/linux/wayland/window/state.rs b/src/platform_impl/linux/wayland/window/state.rs index 8c859edfc1..303333f4ef 100644 --- a/src/platform_impl/linux/wayland/window/state.rs +++ b/src/platform_impl/linux/wayland/window/state.rs @@ -39,7 +39,7 @@ use crate::platform_impl::wayland::state::{WindowCompositorUpdate, WinitState}; use crate::platform_impl::wayland::types::cursor::{CustomCursor, SelectedCursor}; use crate::platform_impl::wayland::types::kwin_blur::KWinBlurManager; use crate::platform_impl::PlatformCustomCursor; -use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, WindowId}; +use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, SurfaceId}; #[cfg(feature = "sctk-adwaita")] pub type WinitFrame = sctk_adwaita::AdwaitaFrame; @@ -423,7 +423,7 @@ impl WindowState { seat: &WlSeat, serial: u32, timestamp: Duration, - window_id: WindowId, + window_id: SurfaceId, updates: &mut Vec, ) -> Option { match self.frame.as_mut()?.on_click(timestamp, click, pressed)? { diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index c5b2907067..9adbe07df3 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -23,7 +23,7 @@ use xkbcommon_dl::xkb_mod_mask_t; use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::event::{ ButtonSource, DeviceEvent, DeviceId, ElementState, Event, Ime, MouseButton, MouseScrollDelta, - PointerKind, PointerSource, RawKeyEvent, SurfaceSizeWriter, TouchPhase, WindowEvent, + PointerKind, PointerSource, RawKeyEvent, SurfaceSizeWriter, TouchPhase, SurfaceEvent, }; use crate::keyboard::ModifiersState; use crate::platform_impl::common::xkb::{self, XkbState}; @@ -34,7 +34,7 @@ use crate::platform_impl::x11::atoms::*; use crate::platform_impl::x11::util::cookie::GenericEventCookie; use crate::platform_impl::x11::{ mkdid, mkfid, mkwid, util, CookieResultExt, Device, DeviceInfo, Dnd, DndState, ImeReceiver, - ScrollOrientation, UnownedWindow, WindowId, + ScrollOrientation, UnownedWindow, SurfaceId, }; /// The maximum amount of X modifiers to replay. @@ -99,22 +99,22 @@ impl EventProcessor { while let Ok((window, event)) = self.ime_event_receiver.try_recv() { let window_id = mkwid(window as xproto::Window); let event = match event { - ImeEvent::Enabled => WindowEvent::Ime(Ime::Enabled), + ImeEvent::Enabled => SurfaceEvent::Ime(Ime::Enabled), ImeEvent::Start => { self.is_composing = true; - WindowEvent::Ime(Ime::Preedit("".to_owned(), None)) + SurfaceEvent::Ime(Ime::Preedit("".to_owned(), None)) }, ImeEvent::Update(text, position) if self.is_composing => { - WindowEvent::Ime(Ime::Preedit(text, Some((position, position)))) + SurfaceEvent::Ime(Ime::Preedit(text, Some((position, position)))) }, ImeEvent::End => { self.is_composing = false; // Issue empty preedit on `Done`. - WindowEvent::Ime(Ime::Preedit(String::new(), None)) + SurfaceEvent::Ime(Ime::Preedit(String::new(), None)) }, ImeEvent::Disabled => { self.is_composing = false; - WindowEvent::Ime(Ime::Disabled) + SurfaceEvent::Ime(Ime::Disabled) }, _ => continue, }; @@ -340,7 +340,7 @@ impl EventProcessor { F: Fn(&Arc) -> Ret, { let mut deleted = false; - let window_id = WindowId::from_raw(window_id as _); + let window_id = SurfaceId::from_raw(window_id as _); let result = self .target .windows @@ -371,7 +371,7 @@ impl EventProcessor { let window_id = mkwid(window); if xev.data.get_long(0) as xproto::Atom == self.target.wm_delete_window { - let event = Event::WindowEvent { window_id, event: WindowEvent::CloseRequested }; + let event = Event::WindowEvent { window_id, event: SurfaceEvent::CloseRequested }; callback(&self.target, event); return; } @@ -523,7 +523,7 @@ impl EventProcessor { for path in path_list { let event = Event::WindowEvent { window_id, - event: WindowEvent::DroppedFile(path.clone()), + event: SurfaceEvent::DroppedFile(path.clone()), }; callback(&self.target, event); } @@ -548,7 +548,7 @@ impl EventProcessor { if xev.message_type == atoms[XdndLeave] as c_ulong { self.dnd.reset(); - let event = Event::WindowEvent { window_id, event: WindowEvent::HoveredFileCancelled }; + let event = Event::WindowEvent { window_id, event: SurfaceEvent::HoveredFileCancelled }; callback(&self.target, event); } } @@ -577,7 +577,7 @@ impl EventProcessor { for path in path_list { let event = Event::WindowEvent { window_id, - event: WindowEvent::HoveredFile(path.clone()), + event: SurfaceEvent::HoveredFile(path.clone()), }; callback(&self.target, event); } @@ -659,7 +659,7 @@ impl EventProcessor { if moved { callback( &self.target, - Event::WindowEvent { window_id, event: WindowEvent::Moved(outer.into()) }, + Event::WindowEvent { window_id, event: SurfaceEvent::Moved(outer.into()) }, ); } outer @@ -710,7 +710,7 @@ impl EventProcessor { &self.target, Event::WindowEvent { window_id, - event: WindowEvent::ScaleFactorChanged { + event: SurfaceEvent::ScaleFactorChanged { scale_factor: new_scale_factor, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade( &surface_size, @@ -771,7 +771,7 @@ impl EventProcessor { &self.target, Event::WindowEvent { window_id, - event: WindowEvent::SurfaceResized(new_surface_size.into()), + event: SurfaceEvent::SurfaceResized(new_surface_size.into()), }, ); } @@ -803,7 +803,7 @@ impl EventProcessor { // window, given that we can't rely on `CreateNotify`, due to it being not // sent. let focus = self.with_window(window, |window| window.has_focus()).unwrap_or_default(); - let event = Event::WindowEvent { window_id, event: WindowEvent::Focused(focus) }; + let event = Event::WindowEvent { window_id, event: SurfaceEvent::Focused(focus) }; callback(&self.target, event); } @@ -817,7 +817,7 @@ impl EventProcessor { // In the event that the window's been destroyed without being dropped first, we // cleanup again here. - self.target.windows.borrow_mut().remove(&WindowId::from_raw(window as _)); + self.target.windows.borrow_mut().remove(&SurfaceId::from_raw(window as _)); // Since all XIM stuff needs to happen from the same thread, we destroy the input // context here instead of when dropping the window. @@ -827,7 +827,7 @@ impl EventProcessor { .expect("Failed to destroy input context"); } - callback(&self.target, Event::WindowEvent { window_id, event: WindowEvent::Destroyed }); + callback(&self.target, Event::WindowEvent { window_id, event: SurfaceEvent::Destroyed }); } fn property_notify(&mut self, xev: &XPropertyEvent, mut callback: F) @@ -852,7 +852,7 @@ impl EventProcessor { let event = Event::WindowEvent { window_id: mkwid(xwindow), - event: WindowEvent::Occluded(xev.state == xlib::VisibilityFullyObscured), + event: SurfaceEvent::Occluded(xev.state == xlib::VisibilityFullyObscured), }; callback(&self.target, event); @@ -871,7 +871,7 @@ impl EventProcessor { let window = xev.window as xproto::Window; let window_id = mkwid(window); - let event = Event::WindowEvent { window_id, event: WindowEvent::RedrawRequested }; + let event = Event::WindowEvent { window_id, event: SurfaceEvent::RedrawRequested }; callback(&self.target, event); } @@ -953,7 +953,7 @@ impl EventProcessor { let event = key_processor.process_key_event(keycode, state, repeat); let event = Event::WindowEvent { window_id, - event: WindowEvent::KeyboardInput { + event: SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false, @@ -977,12 +977,12 @@ impl EventProcessor { if !written.is_empty() { let event = Event::WindowEvent { window_id, - event: WindowEvent::Ime(Ime::Preedit(String::new(), None)), + event: SurfaceEvent::Ime(Ime::Preedit(String::new(), None)), }; callback(&self.target, event); let event = - Event::WindowEvent { window_id, event: WindowEvent::Ime(Ime::Commit(written)) }; + Event::WindowEvent { window_id, event: SurfaceEvent::Ime(Ime::Commit(written)) }; self.is_composing = false; callback(&self.target, event); @@ -992,7 +992,7 @@ impl EventProcessor { fn send_synthic_modifier_from_core( &mut self, - window_id: crate::window::WindowId, + window_id: crate::window::SurfaceId, state: u16, mut callback: F, ) where @@ -1017,7 +1017,7 @@ impl EventProcessor { let mods: ModifiersState = xkb_state.modifiers().into(); let event = - Event::WindowEvent { window_id, event: WindowEvent::ModifiersChanged(mods.into()) }; + Event::WindowEvent { window_id, event: SurfaceEvent::ModifiersChanged(mods.into()) }; callback(&self.target, event); } @@ -1040,20 +1040,20 @@ impl EventProcessor { let position = PhysicalPosition::new(event.event_x, event.event_y); let event = match event.detail as u32 { - xlib::Button1 => WindowEvent::PointerButton { + xlib::Button1 => SurfaceEvent::PointerButton { device_id, state, position, button: MouseButton::Left.into(), }, - xlib::Button2 => WindowEvent::PointerButton { + xlib::Button2 => SurfaceEvent::PointerButton { device_id, state, position, button: MouseButton::Middle.into(), }, - xlib::Button3 => WindowEvent::PointerButton { + xlib::Button3 => SurfaceEvent::PointerButton { device_id, state, position, @@ -1064,7 +1064,7 @@ impl EventProcessor { // those. In practice, even clicky scroll wheels appear to be reported by // evdev (and XInput2 in turn) as axis motion, so we don't otherwise // special-case these button presses. - 4..=7 => WindowEvent::MouseWheel { + 4..=7 => SurfaceEvent::MouseWheel { device_id, delta: match event.detail { 4 => MouseScrollDelta::LineDelta(0.0, 1.0), @@ -1075,20 +1075,20 @@ impl EventProcessor { }, phase: TouchPhase::Moved, }, - 8 => WindowEvent::PointerButton { + 8 => SurfaceEvent::PointerButton { device_id, state, position, button: MouseButton::Back.into(), }, - 9 => WindowEvent::PointerButton { + 9 => SurfaceEvent::PointerButton { device_id, state, position, button: MouseButton::Forward.into(), }, - x => WindowEvent::PointerButton { + x => SurfaceEvent::PointerButton { device_id, state, position, @@ -1122,7 +1122,7 @@ impl EventProcessor { let event = Event::WindowEvent { window_id, - event: WindowEvent::PointerMoved { + event: SurfaceEvent::PointerMoved { device_id, position, source: PointerSource::Mouse, @@ -1165,7 +1165,7 @@ impl EventProcessor { ScrollOrientation::Vertical => MouseScrollDelta::LineDelta(0.0, -delta as f32), }; - let event = WindowEvent::MouseWheel { device_id, delta, phase: TouchPhase::Moved }; + let event = SurfaceEvent::MouseWheel { device_id, delta, phase: TouchPhase::Moved }; events.push(Event::WindowEvent { window_id, event }); } @@ -1211,7 +1211,7 @@ impl EventProcessor { let event = Event::WindowEvent { window_id, - event: WindowEvent::PointerEntered { + event: SurfaceEvent::PointerEntered { device_id, position, kind: PointerKind::Mouse, @@ -1235,7 +1235,7 @@ impl EventProcessor { if self.window_exists(window) { let event = Event::WindowEvent { window_id: mkwid(window), - event: WindowEvent::PointerLeft { + event: SurfaceEvent::PointerLeft { device_id: Some(mkdid(event.deviceid as xinput::DeviceId)), position: Some(PhysicalPosition::new(event.event_x, event.event_y)), kind: PointerKind::Mouse, @@ -1273,7 +1273,7 @@ impl EventProcessor { window.shared_state_lock().has_focus = true; } - let event = Event::WindowEvent { window_id, event: WindowEvent::Focused(true) }; + let event = Event::WindowEvent { window_id, event: SurfaceEvent::Focused(true) }; callback(&self.target, event); // Issue key press events for all pressed keys @@ -1297,7 +1297,7 @@ impl EventProcessor { let event = Event::WindowEvent { window_id, - event: WindowEvent::PointerMoved { device_id, position, source: PointerSource::Mouse }, + event: SurfaceEvent::PointerMoved { device_id, position, source: PointerSource::Mouse }, }; callback(&self.target, event); } @@ -1348,7 +1348,7 @@ impl EventProcessor { window.shared_state_lock().has_focus = false; } - let event = Event::WindowEvent { window_id, event: WindowEvent::Focused(false) }; + let event = Event::WindowEvent { window_id, event: SurfaceEvent::Focused(false) }; callback(&self.target, event) } } @@ -1371,7 +1371,7 @@ impl EventProcessor { if is_first_touch(&mut self.first_touch, &mut self.num_touch, id, phase) { let event = Event::WindowEvent { window_id, - event: WindowEvent::PointerMoved { + event: SurfaceEvent::PointerMoved { device_id: None, position: position.cast(), source: PointerSource::Mouse, @@ -1387,7 +1387,7 @@ impl EventProcessor { xinput2::XI_TouchBegin => { let event = Event::WindowEvent { window_id, - event: WindowEvent::PointerEntered { + event: SurfaceEvent::PointerEntered { device_id, position, kind: PointerKind::Touch(finger_id), @@ -1396,7 +1396,7 @@ impl EventProcessor { callback(&self.target, event); let event = Event::WindowEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id, state: ElementState::Pressed, position, @@ -1408,7 +1408,7 @@ impl EventProcessor { xinput2::XI_TouchUpdate => { let event = Event::WindowEvent { window_id, - event: WindowEvent::PointerMoved { + event: SurfaceEvent::PointerMoved { device_id, position, source: PointerSource::Touch { finger_id, force: None }, @@ -1419,7 +1419,7 @@ impl EventProcessor { xinput2::XI_TouchEnd => { let event = Event::WindowEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id, state: ElementState::Released, position, @@ -1429,7 +1429,7 @@ impl EventProcessor { callback(&self.target, event); let event = Event::WindowEvent { window_id, - event: WindowEvent::PointerLeft { + event: SurfaceEvent::PointerLeft { device_id, position: Some(position), kind: PointerKind::Touch(finger_id), @@ -1656,7 +1656,7 @@ impl EventProcessor { } } - fn update_mods_from_query(&mut self, window_id: crate::window::WindowId, mut callback: F) + fn update_mods_from_query(&mut self, window_id: crate::window::SurfaceId, mut callback: F) where F: FnMut(&ActiveEventLoop, Event), { @@ -1690,7 +1690,7 @@ impl EventProcessor { pub(crate) fn update_mods_from_core_event( &mut self, - window_id: crate::window::WindowId, + window_id: crate::window::SurfaceId, state: u16, mut callback: F, ) where @@ -1769,7 +1769,7 @@ impl EventProcessor { /// unless `force` is passed. The `force` should be passed when the active window changes. fn send_modifiers( &self, - window_id: crate::window::WindowId, + window_id: crate::window::SurfaceId, modifiers: ModifiersState, force: bool, callback: &mut F, @@ -1779,7 +1779,7 @@ impl EventProcessor { if self.modifiers.replace(modifiers) != modifiers || force { let event = Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(self.modifiers.get().into()), + event: SurfaceEvent::ModifiersChanged(self.modifiers.get().into()), }; callback(&self.target, event); } @@ -1787,7 +1787,7 @@ impl EventProcessor { fn handle_pressed_keys( target: &ActiveEventLoop, - window_id: crate::window::WindowId, + window_id: crate::window::SurfaceId, state: ElementState, xkb_context: &mut Context, callback: &mut F, @@ -1816,7 +1816,7 @@ impl EventProcessor { let event = key_processor.process_key_event(keycode as u32, state, false); let event = Event::WindowEvent { window_id, - event: WindowEvent::KeyboardInput { device_id: None, event, is_synthetic: true }, + event: SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: true }, }; callback(target, event); } diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index c3bfaa4420..a1d2099cc7 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -24,7 +24,7 @@ use x11rb::xcb_ffi::ReplyOrIdError; use crate::application::ApplicationHandler; use crate::error::{EventLoopError, RequestError}; -use crate::event::{DeviceId, Event, StartCause, WindowEvent}; +use crate::event::{DeviceId, Event, StartCause, SurfaceEvent}; use crate::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, OwnedDisplayHandle as RootOwnedDisplayHandle, @@ -36,7 +36,7 @@ use crate::platform_impl::x11::window::Window; use crate::platform_impl::{OwnedDisplayHandle, PlatformCustomCursor}; use crate::window::{ CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, - WindowAttributes, WindowId, + WindowAttributes, SurfaceId, }; mod activation; @@ -136,8 +136,8 @@ pub struct ActiveEventLoop { exit: Cell>, root: xproto::Window, ime: Option>, - windows: RefCell>>, - redraw_sender: WakeSender, + windows: RefCell>>, + redraw_sender: WakeSender, activation_sender: WakeSender, event_loop_proxy: EventLoopProxy, device_events: Cell, @@ -147,14 +147,14 @@ pub struct EventLoop { loop_running: bool, event_loop: Loop<'static, EventLoopState>, event_processor: EventProcessor, - redraw_receiver: PeekableReceiver, + redraw_receiver: PeekableReceiver, activation_receiver: PeekableReceiver, /// The current state of the event loop. state: EventLoopState, } -type ActivationToken = (WindowId, crate::event_loop::AsyncRequestSerial); +type ActivationToken = (SurfaceId, crate::event_loop::AsyncRequestSerial); struct EventLoopState { /// The latest readiness state for the x11 file descriptor @@ -529,7 +529,7 @@ impl EventLoop { match token { Some(Ok(token)) => { - let event = WindowEvent::ActivationTokenDone { + let event = SurfaceEvent::ActivationTokenDone { serial, token: crate::window::ActivationToken::_new(token), }; @@ -559,7 +559,7 @@ impl EventLoop { app.window_event( &self.event_processor.target, window_id, - WindowEvent::RedrawRequested, + SurfaceEvent::RedrawRequested, ); } } @@ -574,7 +574,7 @@ impl EventLoop { while unsafe { self.event_processor.poll_one_event(xev.as_mut_ptr()) } { let mut xev = unsafe { xev.assume_init() }; self.event_processor.process_event(&mut xev, |window_target, event: Event| { - if let Event::WindowEvent { window_id, event: WindowEvent::RedrawRequested } = event + if let Event::WindowEvent { window_id, event: SurfaceEvent::RedrawRequested } = event { window_target.redraw_sender.send(window_id); } else { @@ -987,8 +987,8 @@ impl<'a, E: fmt::Debug> CookieResultExt for Result, E> { } } -fn mkwid(w: xproto::Window) -> crate::window::WindowId { - crate::window::WindowId::from_raw(w as _) +fn mkwid(w: xproto::Window) -> crate::window::SurfaceId { + crate::window::SurfaceId::from_raw(w as _) } fn mkdid(w: xinput::DeviceId) -> DeviceId { DeviceId::from_raw(w as i64) diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 44d999d31f..e22fb2a4d4 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -23,7 +23,7 @@ use super::{ use crate::cursor::{Cursor, CustomCursor as RootCustomCursor}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{Event, SurfaceSizeWriter, WindowEvent}; +use crate::event::{Event, SurfaceSizeWriter, SurfaceEvent}; use crate::event_loop::AsyncRequestSerial; use crate::platform::x11::WindowType; use crate::platform_impl::x11::atoms::*; @@ -36,7 +36,7 @@ use crate::platform_impl::{ }; use crate::window::{ CursorGrabMode, ImePurpose, ResizeDirection, Surface as CoreSurface, Theme, UserAttentionType, - Window as CoreWindow, WindowAttributes, WindowButtons, WindowId, WindowLevel, + Window as CoreWindow, WindowAttributes, WindowButtons, SurfaceId, WindowLevel, }; pub(crate) struct Window(Arc); @@ -62,7 +62,7 @@ impl Window { } impl CoreSurface for Window { - fn id(&self) -> WindowId { + fn id(&self) -> SurfaceId { self.0.id() } @@ -434,7 +434,7 @@ pub struct UnownedWindow { cursor_visible: Mutex, ime_sender: Mutex, pub shared_state: Mutex, - redraw_sender: WakeSender, + redraw_sender: WakeSender, activation_sender: WakeSender, } macro_rules! leap { @@ -1234,7 +1234,7 @@ impl UnownedWindow { let surface_size = Arc::new(Mutex::new(PhysicalSize::new(new_width, new_height))); callback(Event::WindowEvent { window_id: self.id(), - event: WindowEvent::ScaleFactorChanged { + event: SurfaceEvent::ScaleFactorChanged { scale_factor: new_monitor.scale_factor, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&surface_size)), }, @@ -2142,8 +2142,8 @@ impl UnownedWindow { } #[inline] - pub fn id(&self) -> WindowId { - WindowId::from_raw(self.xwindow as _) + pub fn id(&self) -> SurfaceId { + SurfaceId::from_raw(self.xwindow as _) } pub(super) fn sync_counter_id(&self) -> Option { @@ -2152,7 +2152,7 @@ impl UnownedWindow { #[inline] pub fn request_redraw(&self) { - self.redraw_sender.send(WindowId::from_raw(self.xwindow as _)); + self.redraw_sender.send(SurfaceId::from_raw(self.xwindow as _)); } #[inline] diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index e69a5e723f..2ab9e5b9e3 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -361,7 +361,7 @@ impl EventLoop { key_without_modifiers = logical_key.clone(); } - let event = event::WindowEvent::KeyboardInput { + let event = event::SurfaceEvent::KeyboardInput { device_id: None, event: event::KeyEvent { logical_key, @@ -385,7 +385,7 @@ impl EventLoop { app.window_event( window_target, window_id, - event::WindowEvent::ModifiersChanged(event_state.modifiers()), + event::SurfaceEvent::ModifiersChanged(event_state.modifiers()), ); } }, @@ -393,19 +393,19 @@ impl EventLoop { app.window_event( window_target, window_id, - event::WindowEvent::Ime(Ime::Preedit("".into(), None)), + event::SurfaceEvent::Ime(Ime::Preedit("".into(), None)), ); app.window_event( window_target, window_id, - event::WindowEvent::Ime(Ime::Commit(character.into())), + event::SurfaceEvent::Ime(Ime::Commit(character.into())), ); }, EventOption::Mouse(MouseEvent { x, y }) => { app.window_event( window_target, window_id, - event::WindowEvent::PointerMoved { + event::SurfaceEvent::PointerMoved { device_id: None, position: (x, y).into(), source: event::PointerSource::Mouse, @@ -424,7 +424,7 @@ impl EventLoop { app.window_event( window_target, window_id, - event::WindowEvent::PointerButton { + event::SurfaceEvent::PointerButton { device_id: None, state, position: dpi::PhysicalPosition::default(), @@ -437,7 +437,7 @@ impl EventLoop { app.window_event( window_target, window_id, - event::WindowEvent::MouseWheel { + event::SurfaceEvent::MouseWheel { device_id: None, delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32), phase: event::TouchPhase::Moved, @@ -445,23 +445,23 @@ impl EventLoop { ); }, EventOption::Quit(QuitEvent {}) => { - app.window_event(window_target, window_id, event::WindowEvent::CloseRequested); + app.window_event(window_target, window_id, event::SurfaceEvent::CloseRequested); }, EventOption::Focus(FocusEvent { focused }) => { - app.window_event(window_target, window_id, event::WindowEvent::Focused(focused)); + app.window_event(window_target, window_id, event::SurfaceEvent::Focused(focused)); }, EventOption::Move(MoveEvent { x, y }) => { app.window_event( window_target, window_id, - event::WindowEvent::Moved((x, y).into()), + event::SurfaceEvent::Moved((x, y).into()), ); }, EventOption::Resize(ResizeEvent { width, height }) => { app.window_event( window_target, window_id, - event::WindowEvent::SurfaceResized((width, height).into()), + event::SurfaceEvent::SurfaceResized((width, height).into()), ); // Acknowledge resize after event loop. @@ -470,13 +470,13 @@ impl EventLoop { // TODO: Screen, Clipboard, Drop EventOption::Hover(HoverEvent { entered }) => { let event = if entered { - event::WindowEvent::PointerEntered { + event::SurfaceEvent::PointerEntered { device_id: None, position: dpi::PhysicalPosition::default(), kind: event::PointerKind::Mouse, } } else { - event::WindowEvent::PointerLeft { + event::SurfaceEvent::PointerLeft { device_id: None, position: None, kind: event::PointerKind::Mouse, @@ -514,11 +514,11 @@ impl EventLoop { self.windows.push((window, EventState::default())); // Send resize event on create to indicate first size. - let event = event::WindowEvent::SurfaceResized((properties.w, properties.h).into()); + let event = event::SurfaceEvent::SurfaceResized((properties.w, properties.h).into()); app.window_event(&self.window_target, window_id, event); // Send moved event on create to indicate first position. - let event = event::WindowEvent::Moved((properties.x, properties.y).into()); + let event = event::SurfaceEvent::Moved((properties.x, properties.y).into()); app.window_event(&self.window_target, window_id, event); } @@ -527,7 +527,7 @@ impl EventLoop { let mut destroys = self.window_target.destroys.lock().unwrap(); destroys.pop_front() } { - app.window_event(&self.window_target, destroy_id, event::WindowEvent::Destroyed); + app.window_event(&self.window_target, destroy_id, event::SurfaceEvent::Destroyed); self.windows .retain(|(window, _event_state)| WindowId::from_raw(window.fd) != destroy_id); } @@ -595,7 +595,7 @@ impl EventLoop { app.window_event( &self.window_target, window_id, - event::WindowEvent::RedrawRequested, + event::SurfaceEvent::RedrawRequested, ); } diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index b46968e8f7..a6eb953aea 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -437,7 +437,7 @@ impl Shared { // This is used to differentiate windows when handling events pub fn generate_id(&self) -> usize { let id = self.0.id.get(); - self.0.id.set(id.checked_add(1).expect("exhausted `WindowId`")); + self.0.id.set(id.checked_add(1).expect("exhausted `SurfaceId`")); id } @@ -568,7 +568,7 @@ impl Shared { self.0.all_canvases.borrow_mut().retain(|&(item_id, ..)| item_id != id); self.handle_event(Event::WindowEvent { window_id: id, - event: crate::event::WindowEvent::Destroyed, + event: crate::event::SurfaceEvent::Destroyed, }); self.0.redraw_pending.borrow_mut().remove(&id); } diff --git a/src/platform_impl/web/web_sys/canvas.rs b/src/platform_impl/web/web_sys/canvas.rs index 08b1a3dd23..2f79671a09 100644 --- a/src/platform_impl/web/web_sys/canvas.rs +++ b/src/platform_impl/web/web_sys/canvas.rs @@ -490,7 +490,7 @@ impl Canvas { let new_size = Arc::new(Mutex::new(current_size)); event_handler(crate::event::Event::WindowEvent { window_id: self.id, - event: crate::event::WindowEvent::ScaleFactorChanged { + event: crate::event::SurfaceEvent::ScaleFactorChanged { scale_factor: scale, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_size)), }, @@ -518,7 +518,7 @@ impl Canvas { self.set_old_size(new_size); runner.send_event(crate::event::Event::WindowEvent { window_id: self.id, - event: crate::event::WindowEvent::SurfaceResized(new_size), + event: crate::event::SurfaceEvent::SurfaceResized(new_size), }) } } diff --git a/src/platform_impl/windows/drop_handler.rs b/src/platform_impl/windows/drop_handler.rs index 99c413bfaa..baff09896c 100644 --- a/src/platform_impl/windows/drop_handler.rs +++ b/src/platform_impl/windows/drop_handler.rs @@ -80,7 +80,7 @@ impl FileDropHandler { _pt: *const POINTL, pdwEffect: *mut u32, ) -> HRESULT { - use crate::event::WindowEvent::HoveredFile; + use crate::event::SurfaceEvent::HoveredFile; let drop_handler = unsafe { Self::from_interface(this) }; let hdrop = unsafe { Self::iterate_filenames(pDataObj, |filename| { @@ -115,7 +115,7 @@ impl FileDropHandler { } pub unsafe extern "system" fn DragLeave(this: *mut IDropTarget) -> HRESULT { - use crate::event::WindowEvent::HoveredFileCancelled; + use crate::event::SurfaceEvent::HoveredFileCancelled; let drop_handler = unsafe { Self::from_interface(this) }; if drop_handler.hovered_is_valid { drop_handler.send_event(Event::WindowEvent { @@ -134,7 +134,7 @@ impl FileDropHandler { _pt: *const POINTL, _pdwEffect: *mut u32, ) -> HRESULT { - use crate::event::WindowEvent::DroppedFile; + use crate::event::SurfaceEvent::DroppedFile; let drop_handler = unsafe { Self::from_interface(this) }; let hdrop = unsafe { Self::iterate_filenames(pDataObj, |filename| { diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index c4618520f1..f16d81727f 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -903,7 +903,7 @@ fn normalize_pointer_pressure(pressure: u32) -> Option { /// Emit a `ModifiersChanged` event whenever modifiers have changed. /// Returns the current modifier state fn update_modifiers(window: HWND, userdata: &WindowData) { - use crate::event::WindowEvent::ModifiersChanged; + use crate::event::SurfaceEvent::ModifiersChanged; let modifiers = { let mut layouts = LAYOUT_CACHE.lock().unwrap(); @@ -925,7 +925,7 @@ fn update_modifiers(window: HWND, userdata: &WindowData) { } unsafe fn gain_active_focus(window: HWND, userdata: &WindowData) { - use crate::event::WindowEvent::Focused; + use crate::event::SurfaceEvent::Focused; update_modifiers(window, userdata); @@ -936,7 +936,7 @@ unsafe fn gain_active_focus(window: HWND, userdata: &WindowData) { } unsafe fn lose_active_focus(window: HWND, userdata: &WindowData) { - use crate::event::WindowEvent::{Focused, ModifiersChanged}; + use crate::event::SurfaceEvent::{Focused, ModifiersChanged}; userdata.window_state_lock().modifiers_state = ModifiersState::empty(); userdata.send_event(Event::WindowEvent { @@ -1038,7 +1038,7 @@ unsafe fn public_window_callback_inner( .unwrap_or_else(|| result = ProcResult::Value(-1)); let keyboard_callback = || { - use crate::event::WindowEvent::KeyboardInput; + use crate::event::SurfaceEvent::KeyboardInput; let events = userdata.key_event_builder.process_message(window, msg, wparam, lparam, &mut result); for event in events { @@ -1126,7 +1126,7 @@ unsafe fn public_window_callback_inner( }, WM_CLOSE => { - use crate::event::WindowEvent::CloseRequested; + use crate::event::SurfaceEvent::CloseRequested; userdata.send_event(Event::WindowEvent { window_id: WindowId::from_raw(window as usize), event: CloseRequested, @@ -1135,7 +1135,7 @@ unsafe fn public_window_callback_inner( }, WM_DESTROY => { - use crate::event::WindowEvent::Destroyed; + use crate::event::SurfaceEvent::Destroyed; unsafe { RevokeDragDrop(window) }; userdata.send_event(Event::WindowEvent { window_id: WindowId::from_raw(window as usize), @@ -1255,7 +1255,7 @@ unsafe fn public_window_callback_inner( // WM_MOVE supplies client area positions, so we send Moved here instead. WM_WINDOWPOSCHANGED => { - use crate::event::WindowEvent::Moved; + use crate::event::SurfaceEvent::Moved; let windowpos = lparam as *const WINDOWPOS; if unsafe { (*windowpos).flags & SWP_NOMOVE != SWP_NOMOVE } { @@ -1272,7 +1272,7 @@ unsafe fn public_window_callback_inner( }, WM_SIZE => { - use crate::event::WindowEvent::SurfaceResized; + use crate::event::SurfaceEvent::SurfaceResized; let w = super::loword(lparam as u32) as u32; let h = super::hiword(lparam as u32) as u32; @@ -1504,7 +1504,7 @@ unsafe fn public_window_callback_inner( let mut w = userdata.window_state_lock(); w.set_window_flags_in_place(|f| f.set(WindowFlags::MINIMIZED, true)); } - // Send `WindowEvent::Minimized` here if we decide to implement one + // Send `SurfaceEvent::Minimized` here if we decide to implement one if wparam == SC_SCREENSAVE as usize { let window_state = userdata.window_state_lock(); @@ -1518,7 +1518,7 @@ unsafe fn public_window_callback_inner( }, WM_MOUSEMOVE => { - use crate::event::WindowEvent::{PointerEntered, PointerLeft, PointerMoved}; + use crate::event::SurfaceEvent::{PointerEntered, PointerLeft, PointerMoved}; use crate::event::{PointerKind, PointerSource}; let x = super::get_x_lparam(lparam as u32) as i32; @@ -1597,7 +1597,7 @@ unsafe fn public_window_callback_inner( WM_MOUSELEAVE => { use crate::event::PointerKind::Mouse; - use crate::event::WindowEvent::PointerLeft; + use crate::event::SurfaceEvent::PointerLeft; { let mut w = userdata.window_state_lock(); @@ -1669,7 +1669,7 @@ unsafe fn public_window_callback_inner( WM_LBUTTONDOWN => { use crate::event::ElementState::Pressed; use crate::event::MouseButton::Left; - use crate::event::WindowEvent::PointerButton; + use crate::event::SurfaceEvent::PointerButton; unsafe { capture_mouse(window, &mut userdata.window_state_lock()) }; @@ -1694,7 +1694,7 @@ unsafe fn public_window_callback_inner( WM_LBUTTONUP => { use crate::event::ElementState::Released; use crate::event::MouseButton::Left; - use crate::event::WindowEvent::PointerButton; + use crate::event::SurfaceEvent::PointerButton; unsafe { release_mouse(userdata.window_state_lock()) }; @@ -1719,7 +1719,7 @@ unsafe fn public_window_callback_inner( WM_RBUTTONDOWN => { use crate::event::ElementState::Pressed; use crate::event::MouseButton::Right; - use crate::event::WindowEvent::PointerButton; + use crate::event::SurfaceEvent::PointerButton; unsafe { capture_mouse(window, &mut userdata.window_state_lock()) }; @@ -1744,7 +1744,7 @@ unsafe fn public_window_callback_inner( WM_RBUTTONUP => { use crate::event::ElementState::Released; use crate::event::MouseButton::Right; - use crate::event::WindowEvent::PointerButton; + use crate::event::SurfaceEvent::PointerButton; unsafe { release_mouse(userdata.window_state_lock()) }; @@ -1769,7 +1769,7 @@ unsafe fn public_window_callback_inner( WM_MBUTTONDOWN => { use crate::event::ElementState::Pressed; use crate::event::MouseButton::Middle; - use crate::event::WindowEvent::PointerButton; + use crate::event::SurfaceEvent::PointerButton; unsafe { capture_mouse(window, &mut userdata.window_state_lock()) }; @@ -1794,7 +1794,7 @@ unsafe fn public_window_callback_inner( WM_MBUTTONUP => { use crate::event::ElementState::Released; use crate::event::MouseButton::Middle; - use crate::event::WindowEvent::PointerButton; + use crate::event::SurfaceEvent::PointerButton; unsafe { release_mouse(userdata.window_state_lock()) }; @@ -1819,7 +1819,7 @@ unsafe fn public_window_callback_inner( WM_XBUTTONDOWN => { use crate::event::ElementState::Pressed; use crate::event::MouseButton::{Back, Forward, Other}; - use crate::event::WindowEvent::PointerButton; + use crate::event::SurfaceEvent::PointerButton; let xbutton = super::get_xbutton_wparam(wparam as u32); unsafe { capture_mouse(window, &mut userdata.window_state_lock()) }; @@ -1850,7 +1850,7 @@ unsafe fn public_window_callback_inner( WM_XBUTTONUP => { use crate::event::ElementState::Released; use crate::event::MouseButton::{Back, Forward, Other}; - use crate::event::WindowEvent::PointerButton; + use crate::event::SurfaceEvent::PointerButton; let xbutton = super::get_xbutton_wparam(wparam as u32); unsafe { release_mouse(userdata.window_state_lock()) }; @@ -2251,7 +2251,7 @@ unsafe fn public_window_callback_inner( // Only sent on Windows 8.1 or newer. On Windows 7 and older user has to log out to change // DPI, therefore all applications are closed while DPI is changing. WM_DPICHANGED => { - use crate::event::WindowEvent::ScaleFactorChanged; + use crate::event::SurfaceEvent::ScaleFactorChanged; // This message actually provides two DPI values - x and y. However MSDN says that // "you only need to use either the X-axis or the Y-axis value when scaling your @@ -2458,7 +2458,7 @@ unsafe fn public_window_callback_inner( }, WM_SETTINGCHANGE => { - use crate::event::WindowEvent::ThemeChanged; + use crate::event::SurfaceEvent::ThemeChanged; let preferred_theme = userdata.window_state_lock().preferred_theme; diff --git a/src/window.rs b/src/window.rs index 197046b98e..12fbf29270 100644 --- a/src/window.rs +++ b/src/window.rs @@ -14,32 +14,32 @@ use crate::monitor::{MonitorHandle, VideoModeHandle}; use crate::platform_impl::PlatformSpecificWindowAttributes; use crate::utils::AsAny; -/// Identifier of a window. Unique for each window. +/// Identifier of a surface. Unique for each surface. /// -/// Can be obtained with [`window.id()`][`Surface::id`]. +/// Can be obtained with [`surface.id()`][`Surface::id`]. /// -/// Whenever you receive an event specific to a window, this event contains a `WindowId` which you -/// can then compare to the ids of your windows. +/// Whenever you receive an event specific to a surface, this event contains a `SurfaceId` which you +/// can then compare to the IDs of your surfaces. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId(usize); +pub struct SurfaceId(usize); -impl WindowId { - /// Convert the `WindowId` into the underlying integer. +impl SurfaceId { + /// Convert the `SurfaceId` into the underlying integer. /// /// This is useful if you need to pass the ID across an FFI boundary, or store it in an atomic. pub const fn into_raw(self) -> usize { self.0 } - /// Construct a `WindowId` from the underlying integer. + /// Construct a `SurfaceId` from the underlying integer. /// - /// This should only be called with integers returned from [`WindowId::into_raw`]. + /// This should only be called with integers returned from [`SurfaceId::into_raw`]. pub const fn from_raw(id: usize) -> Self { Self(id) } } -impl fmt::Debug for WindowId { +impl fmt::Debug for SurfaceId { fn fmt(&self, fmtr: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(fmtr) } @@ -370,13 +370,13 @@ impl WindowAttributes { /// Whether the window will be initially focused or not. /// /// The window should be assumed as not focused by default - /// following by the [`WindowEvent::Focused`]. + /// following by the [`SurfaceEvent::Focused`]. /// /// ## Platform-specific: /// /// **Android / iOS / X11 / Wayland / Orbital:** Unsupported. /// - /// [`WindowEvent::Focused`]: crate::event::WindowEvent::Focused. + /// [`SurfaceEvent::Focused`]: crate::event::SurfaceEvent::Focused. #[inline] pub fn with_active(mut self, active: bool) -> Self { self.active = active; @@ -440,13 +440,13 @@ impl WindowAttributes { /// not be closed by dropping the [`Surface`]. pub trait Surface: AsAny + Send + Sync { /// Returns an identifier unique to the window. - fn id(&self) -> WindowId; + fn id(&self) -> SurfaceId; /// Returns the scale factor that can be used to map logical pixels to physical pixels, and /// vice versa. /// /// Note that this value can change depending on user action (for example if the window is - /// moved to another screen); as such, tracking [`WindowEvent::ScaleFactorChanged`] events is + /// moved to another screen); as such, tracking [`SurfaceEvent::ScaleFactorChanged`] events is /// the most robust way to track the DPI you need to use to draw. /// /// This value may differ from [`MonitorHandle::scale_factor`]. @@ -496,7 +496,7 @@ pub trait Surface: AsAny + Send + Sync { /// both the screen scaling and the browser zoom level and can go below `1.0`. /// - **Orbital:** This is currently unimplemented, and this function always returns 1.0. /// - /// [`WindowEvent::ScaleFactorChanged`]: crate::event::WindowEvent::ScaleFactorChanged + /// [`SurfaceEvent::ScaleFactorChanged`]: crate::event::SurfaceEvent::ScaleFactorChanged /// [windows_1]: https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows /// [apple_1]: https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html /// [apple_2]: https://developer.apple.com/design/human-interface-guidelines/macos/icons-and-images/image-size-and-resolution/ @@ -505,7 +505,7 @@ pub trait Surface: AsAny + Send + Sync { /// [`contentScaleFactor`]: https://developer.apple.com/documentation/uikit/uiview/1622657-contentscalefactor?language=objc fn scale_factor(&self) -> f64; - /// Queues a [`WindowEvent::RedrawRequested`] event to be emitted that aligns with the windowing + /// Queues a [`SurfaceEvent::RedrawRequested`] event to be emitted that aligns with the windowing /// system drawing loop. /// /// This is the **strongly encouraged** method of redrawing windows, as it can integrate with @@ -527,10 +527,10 @@ pub trait Surface: AsAny + Send + Sync { /// `RedrawRequested` is emitted in sync with any `WM_PAINT` messages. /// - **Wayland:** The events are aligned with the frame callbacks when /// [`Surface::pre_present_notify`] is used. - /// - **Web:** [`WindowEvent::RedrawRequested`] will be aligned with the + /// - **Web:** [`SurfaceEvent::RedrawRequested`] will be aligned with the /// `requestAnimationFrame`. /// - /// [`WindowEvent::RedrawRequested`]: crate::event::WindowEvent::RedrawRequested + /// [`SurfaceEvent::RedrawRequested`]: crate::event::SurfaceEvent::RedrawRequested fn request_redraw(&self); /// Notify the windowing system before presenting to the window. @@ -538,7 +538,7 @@ pub trait Surface: AsAny + Send + Sync { /// You should call this event after your drawing operations, but before you submit /// the buffer to the display or commit your drawings. Doing so will help winit to properly /// schedule and make assumptions about its internal state. For example, it could properly - /// throttle [`WindowEvent::RedrawRequested`]. + /// throttle [`SurfaceEvent::RedrawRequested`]. /// /// ## Example /// @@ -562,9 +562,9 @@ pub trait Surface: AsAny + Send + Sync { /// ## Platform-specific /// /// - **Android / iOS / X11 / Web / Windows / macOS / Orbital:** Unsupported. - /// - **Wayland:** Schedules a frame callback to throttle [`WindowEvent::RedrawRequested`]. + /// - **Wayland:** Schedules a frame callback to throttle [`SurfaceEvent::RedrawRequested`]. /// - /// [`WindowEvent::RedrawRequested`]: crate::event::WindowEvent::RedrawRequested + /// [`SurfaceEvent::RedrawRequested`]: crate::event::SurfaceEvent::RedrawRequested fn pre_present_notify(&self); /// Returns the size of the window's render-able surface. @@ -591,7 +591,7 @@ pub trait Surface: AsAny + Send + Sync { /// is returned immediately, and the user one is ignored. /// /// When `None` is returned, it means that the request went to the display system, - /// and the actual size will be delivered later with the [`WindowEvent::SurfaceResized`]. + /// and the actual size will be delivered later with the [`SurfaceEvent::SurfaceResized`]. /// /// See [`Surface::surface_size`] for more information about the values. /// @@ -613,7 +613,7 @@ pub trait Surface: AsAny + Send + Sync { /// /// - **Web:** Sets the size of the canvas element. Doesn't account for CSS [`transform`]. /// - /// [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized + /// [`SurfaceEvent::SurfaceResized`]: crate::event::SurfaceEvent::SurfaceResized /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform #[must_use] fn request_surface_size(&self, size: Size) -> Option>; @@ -969,7 +969,7 @@ pub trait Window: Surface { /// Sets whether the window is resizable or not. /// /// Note that making the window unresizable doesn't exempt you from handling - /// [`WindowEvent::SurfaceResized`], as that event can still be triggered by DPI scaling, + /// [`SurfaceEvent::SurfaceResized`], as that event can still be triggered by DPI scaling, /// entering fullscreen mode, etc. Also, the window could still be resized by calling /// [`Surface::request_surface_size`]. /// @@ -980,7 +980,7 @@ pub trait Window: Surface { /// - **X11:** Due to a bug in XFCE, this has no effect on Xfwm. /// - **iOS / Android / Web:** Unsupported. /// - /// [`WindowEvent::SurfaceResized`]: crate::event::WindowEvent::SurfaceResized + /// [`SurfaceEvent::SurfaceResized`]: crate::event::SurfaceEvent::SurfaceResized fn set_resizable(&self, resizable: bool); /// Gets the window's current resizable state. @@ -1187,8 +1187,8 @@ pub trait Window: Surface { /// - **Android / Web / Orbital:** Unsupported. /// - **X11**: Enabling IME will disable dead keys reporting during compose. /// - /// [`Ime`]: crate::event::WindowEvent::Ime - /// [`KeyboardInput`]: crate::event::WindowEvent::KeyboardInput + /// [`Ime`]: crate::event::SurfaceEvent::Ime + /// [`KeyboardInput`]: crate::event::SurfaceEvent::KeyboardInput fn set_ime_allowed(&self, allowed: bool); /// Sets the IME purpose for the window using [`ImePurpose`]. @@ -1212,9 +1212,9 @@ pub trait Window: Surface { /// Gets whether the window has keyboard focus. /// - /// This queries the same state information as [`WindowEvent::Focused`]. + /// This queries the same state information as [`SurfaceEvent::Focused`]. /// - /// [`WindowEvent::Focused`]: crate::event::WindowEvent::Focused + /// [`SurfaceEvent::Focused`]: crate::event::SurfaceEvent::Focused fn has_focus(&self) -> bool; /// Requests user attention to the window, this has no effect if the application diff --git a/tests/send_objects.rs b/tests/send_objects.rs index 9bc4db8eb6..a1892c671d 100644 --- a/tests/send_objects.rs +++ b/tests/send_objects.rs @@ -18,7 +18,7 @@ fn window_builder_send() { #[test] fn ids_send() { - needs_send::(); + needs_send::(); needs_send::(); needs_send::(); } From 190633b8c4abcc6818e9b4dacca91ca01944b6bc Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Sat, 12 Oct 2024 21:51:38 -0400 Subject: [PATCH 11/29] port web backend names --- src/platform_impl/web/event_loop/runner.rs | 22 +-- .../web/event_loop/window_target.rs | 60 +++--- src/platform_impl/web/web_sys/canvas.rs | 6 +- src/platform_impl/web/window.rs | 176 +++++++++--------- 4 files changed, 134 insertions(+), 130 deletions(-) diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index a6eb953aea..8709a0e5c1 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -15,13 +15,13 @@ use super::super::monitor::MonitorHandler; use super::backend; use super::state::State; use crate::dpi::PhysicalSize; -use crate::event::{DeviceEvent, ElementState, Event, RawKeyEvent, StartCause, WindowEvent}; +use crate::event::{DeviceEvent, ElementState, Event, RawKeyEvent, StartCause, SurfaceEvent}; use crate::event_loop::{ControlFlow, DeviceEvents}; use crate::platform::web::{PollStrategy, WaitUntilStrategy}; use crate::platform_impl::platform::backend::EventListenerHandle; use crate::platform_impl::platform::r#async::{DispatchRunner, Waker, WakerSpawner}; use crate::platform_impl::platform::window::Inner; -use crate::window::WindowId; +use crate::window::SurfaceId; pub struct Shared(Rc); @@ -51,9 +51,9 @@ struct Execution { navigator: Navigator, document: Document, #[allow(clippy::type_complexity)] - all_canvases: RefCell, DispatchRunner)>>, - redraw_pending: RefCell>, - destroy_pending: RefCell>, + all_canvases: RefCell, DispatchRunner)>>, + redraw_pending: RefCell>, + destroy_pending: RefCell>, pub(crate) monitor: Rc, page_transition_event_handle: RefCell>, device_events: Cell, @@ -204,14 +204,14 @@ impl Shared { pub fn add_canvas( &self, - id: WindowId, + id: SurfaceId, canvas: Weak, runner: DispatchRunner, ) { self.0.all_canvases.borrow_mut().push((id, canvas, runner)); } - pub fn notify_destroy_window(&self, id: WindowId) { + pub fn notify_destroy_window(&self, id: SurfaceId) { self.0.destroy_pending.borrow_mut().push_back(id); } @@ -423,7 +423,7 @@ impl Shared { { runner.send_event(Event::WindowEvent { window_id: *id, - event: WindowEvent::Occluded(!is_visible), + event: SurfaceEvent::Occluded(!is_visible), }); } } @@ -442,7 +442,7 @@ impl Shared { id } - pub fn request_redraw(&self, id: WindowId) { + pub fn request_redraw(&self, id: SurfaceId) { self.0.redraw_pending.borrow_mut().insert(id); self.send_events::(iter::empty()); } @@ -585,11 +585,11 @@ impl Shared { self.process_destroy_pending_windows(); // Collect all of the redraw events to avoid double-locking the RefCell - let redraw_events: Vec = self.0.redraw_pending.borrow_mut().drain().collect(); + let redraw_events: Vec = self.0.redraw_pending.borrow_mut().drain().collect(); for window_id in redraw_events { self.handle_event(Event::WindowEvent { window_id, - event: WindowEvent::RedrawRequested, + event: SurfaceEvent::RedrawRequested, }); } diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 9c6d680feb..46d4df8c52 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -10,7 +10,7 @@ use super::super::{lock, KeyEventExtra}; use super::runner::{EventWrapper, WeakShared}; use super::{backend, runner, EventLoopProxy}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{ElementState, Event, KeyEvent, TouchPhase, WindowEvent}; +use crate::event::{ElementState, Event, KeyEvent, TouchPhase, SurfaceEvent}; use crate::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopProxy as RootEventLoopProxy, OwnedDisplayHandle as RootOwnedDisplayHandle, @@ -21,7 +21,7 @@ use crate::platform::web::{CustomCursorFuture, PollStrategy, WaitUntilStrategy}; use crate::platform_impl::platform::cursor::CustomCursor; use crate::platform_impl::platform::r#async::Waker; use crate::platform_impl::Window; -use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, Theme, WindowId}; +use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, Theme, SurfaceId}; #[derive(Default)] struct ModifiersShared(Rc>); @@ -62,15 +62,15 @@ impl ActiveEventLoop { self.runner.start(event_handler); } - pub fn generate_id(&self) -> WindowId { - WindowId::from_raw(self.runner.generate_id()) + pub fn generate_id(&self) -> SurfaceId { + SurfaceId::from_raw(self.runner.generate_id()) } pub fn create_custom_cursor_async(&self, source: CustomCursorSource) -> CustomCursorFuture { CustomCursorFuture(CustomCursor::new_async(self, source.inner)) } - pub fn register(&self, canvas: &Rc, window_id: WindowId) { + pub fn register(&self, canvas: &Rc, window_id: SurfaceId) { let canvas_clone = canvas.clone(); canvas.on_touch_start(); @@ -85,13 +85,13 @@ impl ActiveEventLoop { modifiers.set(ModifiersState::empty()); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(ModifiersState::empty().into()), + event: SurfaceEvent::ModifiersChanged(ModifiersState::empty().into()), } }); runner.send_events(clear_modifiers.into_iter().chain(iter::once(Event::WindowEvent { window_id, - event: WindowEvent::Focused(false), + event: SurfaceEvent::Focused(false), }))); }); @@ -101,7 +101,7 @@ impl ActiveEventLoop { if !has_focus.replace(true) { runner.send_event(Event::WindowEvent { window_id, - event: WindowEvent::Focused(true), + event: SurfaceEvent::Focused(true), }); } }); @@ -120,7 +120,7 @@ impl ActiveEventLoop { if focused { canvas.has_focus.set(true); self.runner - .send_event(Event::WindowEvent { window_id, event: WindowEvent::Focused(true) }) + .send_event(Event::WindowEvent { window_id, event: SurfaceEvent::Focused(true) }) } let runner = self.runner.clone(); @@ -131,14 +131,14 @@ impl ActiveEventLoop { modifiers.set(active_modifiers); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(active_modifiers.into()), + event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events( iter::once(Event::WindowEvent { window_id, - event: WindowEvent::KeyboardInput { + event: SurfaceEvent::KeyboardInput { device_id: None, event: KeyEvent { physical_key, @@ -165,14 +165,14 @@ impl ActiveEventLoop { modifiers.set(active_modifiers); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(active_modifiers.into()), + event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events( iter::once(Event::WindowEvent { window_id, - event: WindowEvent::KeyboardInput { + event: SurfaceEvent::KeyboardInput { device_id: None, event: KeyEvent { physical_key, @@ -202,13 +202,13 @@ impl ActiveEventLoop { modifiers.set(active_modifiers); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(active_modifiers.into()), + event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent { window_id, - event: WindowEvent::PointerLeft { device_id, position: Some(position), kind }, + event: SurfaceEvent::PointerLeft { device_id, position: Some(position), kind }, }))) } }); @@ -223,13 +223,13 @@ impl ActiveEventLoop { modifiers.set(active_modifiers); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(active_modifiers.into()), + event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent { window_id, - event: WindowEvent::PointerEntered { device_id, position, kind }, + event: SurfaceEvent::PointerEntered { device_id, position, kind }, }))) } }); @@ -247,13 +247,13 @@ impl ActiveEventLoop { modifiers.set(active_modifiers); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(active_modifiers.into()), + event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); modifiers.into_iter().chain(iter::once(Event::WindowEvent { window_id, - event: WindowEvent::PointerMoved { device_id, position, source }, + event: SurfaceEvent::PointerMoved { device_id, position, source }, })) })); } @@ -269,13 +269,13 @@ impl ActiveEventLoop { modifiers.set(active_modifiers); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(active_modifiers.into()), + event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(modifiers.into_iter().chain([Event::WindowEvent { window_id, - event: WindowEvent::PointerButton { device_id, state, position, button }, + event: SurfaceEvent::PointerButton { device_id, state, position, button }, }])); } }, @@ -290,13 +290,13 @@ impl ActiveEventLoop { modifiers.set(active_modifiers); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(active_modifiers.into()), + event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id, state: ElementState::Pressed, position, @@ -317,13 +317,13 @@ impl ActiveEventLoop { modifiers.set(active_modifiers); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(active_modifiers.into()), + event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id, state: ElementState::Released, position, @@ -341,14 +341,14 @@ impl ActiveEventLoop { modifiers.set(active_modifiers); Event::WindowEvent { window_id, - event: WindowEvent::ModifiersChanged(active_modifiers.into()), + event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(modifiers_changed.into_iter().chain(iter::once( Event::WindowEvent { window_id, - event: WindowEvent::MouseWheel { + event: SurfaceEvent::MouseWheel { device_id: None, delta, phase: TouchPhase::Moved, @@ -362,7 +362,7 @@ impl ActiveEventLoop { let theme = if is_dark_mode { Theme::Dark } else { Theme::Light }; runner.send_event(Event::WindowEvent { window_id, - event: WindowEvent::ThemeChanged(theme), + event: SurfaceEvent::ThemeChanged(theme), }); }); @@ -389,7 +389,7 @@ impl ActiveEventLoop { canvas.set_old_size(new_size); runner.send_event(Event::WindowEvent { window_id, - event: WindowEvent::SurfaceResized(new_size), + event: SurfaceEvent::SurfaceResized(new_size), }); canvas.request_animation_frame(); } @@ -405,7 +405,7 @@ impl ActiveEventLoop { { runner.send_event(Event::WindowEvent { window_id, - event: WindowEvent::Occluded(!is_intersecting), + event: SurfaceEvent::Occluded(!is_intersecting), }); } diff --git a/src/platform_impl/web/web_sys/canvas.rs b/src/platform_impl/web/web_sys/canvas.rs index 2f79671a09..3fedb945a8 100644 --- a/src/platform_impl/web/web_sys/canvas.rs +++ b/src/platform_impl/web/web_sys/canvas.rs @@ -27,13 +27,13 @@ use crate::event::{ }; use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey}; use crate::platform_impl::Fullscreen; -use crate::window::{WindowAttributes, WindowId}; +use crate::window::{WindowAttributes, SurfaceId}; #[allow(dead_code)] pub struct Canvas { main_thread: MainThreadMarker, common: Common, - id: WindowId, + id: SurfaceId, pub has_focus: Rc>, pub prevent_default: Rc>, pub is_intersecting: Cell>, @@ -79,7 +79,7 @@ pub struct Style { impl Canvas { pub(crate) fn create( main_thread: MainThreadMarker, - id: WindowId, + id: SurfaceId, window: web_sys::Window, navigator: Navigator, document: Document, diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index 5eb02c498d..dd6a1ac27e 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -13,9 +13,9 @@ use crate::error::{NotSupportedError, RequestError}; use crate::icon::Icon; use crate::monitor::MonitorHandle as RootMonitorHandle; use crate::window::{ - Cursor, CursorGrabMode, Fullscreen as RootFullscreen, ImePurpose, ResizeDirection, Theme, - UserAttentionType, Window as RootWindow, WindowAttributes, WindowButtons, WindowId, - WindowLevel, + Cursor, CursorGrabMode, Fullscreen as RootFullscreen, ImePurpose, ResizeDirection, + Surface as RootSurface, SurfaceId, Theme, UserAttentionType, Window as RootWindow, + WindowAttributes, WindowButtons, WindowLevel, }; pub struct Window { @@ -23,7 +23,7 @@ pub struct Window { } pub struct Inner { - id: WindowId, + id: SurfaceId, pub window: web_sys::Window, monitor: Rc, canvas: Rc, @@ -90,8 +90,8 @@ impl Window { } } -impl RootWindow for Window { - fn id(&self) -> WindowId { +impl RootSurface for Window { + fn id(&self) -> SurfaceId { self.inner.queue(|inner| inner.id) } @@ -105,6 +105,90 @@ impl RootWindow for Window { fn pre_present_notify(&self) {} + fn surface_size(&self) -> PhysicalSize { + self.inner.queue(|inner| inner.canvas.surface_size()) + } + + fn request_surface_size(&self, size: Size) -> Option> { + self.inner.queue(|inner| { + let size = size.to_logical(self.scale_factor()); + backend::set_canvas_size( + inner.canvas.document(), + inner.canvas.raw(), + inner.canvas.style(), + size, + ); + None + }) + } + + fn set_transparent(&self, _: bool) {} + + fn set_cursor(&self, cursor: Cursor) { + self.inner.dispatch(move |inner| inner.canvas.cursor.set_cursor(cursor)) + } + + fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> { + Err(NotSupportedError::new("set_cursor_position is not supported").into()) + } + + fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> { + Ok(self.inner.queue(|inner| { + match mode { + CursorGrabMode::None => inner.canvas.document().exit_pointer_lock(), + CursorGrabMode::Locked => lock::request_pointer_lock( + inner.canvas.navigator(), + inner.canvas.document(), + inner.canvas.raw(), + ), + CursorGrabMode::Confined => { + return Err(NotSupportedError::new("confined cursor mode is not supported")) + }, + } + + Ok(()) + })?) + } + + fn set_cursor_visible(&self, visible: bool) { + self.inner.dispatch(move |inner| inner.canvas.cursor.set_cursor_visible(visible)) + } + + fn set_cursor_hittest(&self, _: bool) -> Result<(), RequestError> { + Err(NotSupportedError::new("set_cursor_hittest is not supported").into()) + } + + fn current_monitor(&self) -> Option { + Some(self.inner.queue(|inner| inner.monitor.current_monitor()).into()) + } + + fn available_monitors(&self) -> Box> { + Box::new( + self.inner + .queue(|inner| inner.monitor.available_monitors()) + .into_iter() + .map(RootMonitorHandle::from), + ) + } + + fn primary_monitor(&self) -> Option { + self.inner.queue(|inner| inner.monitor.primary_monitor()).map(RootMonitorHandle::from) + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + self + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + self + } +} + +impl RootWindow for Window { + + fn reset_dead_keys(&self) { // Not supported } @@ -130,23 +214,6 @@ impl RootWindow for Window { }) } - fn surface_size(&self) -> PhysicalSize { - self.inner.queue(|inner| inner.canvas.surface_size()) - } - - fn request_surface_size(&self, size: Size) -> Option> { - self.inner.queue(|inner| { - let size = size.to_logical(self.scale_factor()); - backend::set_canvas_size( - inner.canvas.document(), - inner.canvas.raw(), - inner.canvas.style(), - size, - ); - None - }) - } - fn outer_size(&self) -> PhysicalSize { // Note: the canvas element has no window decorations, so this is equal to `surface_size`. self.surface_size() @@ -188,8 +255,6 @@ impl RootWindow for Window { self.inner.queue(|inner| inner.canvas.set_attribute("alt", title)) } - fn set_transparent(&self, _: bool) {} - fn set_blur(&self, _: bool) {} fn set_visible(&self, _: bool) { @@ -314,36 +379,6 @@ impl RootWindow for Window { String::new() } - fn set_cursor(&self, cursor: Cursor) { - self.inner.dispatch(move |inner| inner.canvas.cursor.set_cursor(cursor)) - } - - fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> { - Err(NotSupportedError::new("set_cursor_position is not supported").into()) - } - - fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> { - Ok(self.inner.queue(|inner| { - match mode { - CursorGrabMode::None => inner.canvas.document().exit_pointer_lock(), - CursorGrabMode::Locked => lock::request_pointer_lock( - inner.canvas.navigator(), - inner.canvas.document(), - inner.canvas.raw(), - ), - CursorGrabMode::Confined => { - return Err(NotSupportedError::new("confined cursor mode is not supported")) - }, - } - - Ok(()) - })?) - } - - fn set_cursor_visible(&self, visible: bool) { - self.inner.dispatch(move |inner| inner.canvas.cursor.set_cursor_visible(visible)) - } - fn drag_window(&self) -> Result<(), RequestError> { Err(NotSupportedError::new("drag_window is not supported").into()) } @@ -353,37 +388,6 @@ impl RootWindow for Window { } fn show_window_menu(&self, _: Position) {} - - fn set_cursor_hittest(&self, _: bool) -> Result<(), RequestError> { - Err(NotSupportedError::new("set_cursor_hittest is not supported").into()) - } - - fn current_monitor(&self) -> Option { - Some(self.inner.queue(|inner| inner.monitor.current_monitor()).into()) - } - - fn available_monitors(&self) -> Box> { - Box::new( - self.inner - .queue(|inner| inner.monitor.available_monitors()) - .into_iter() - .map(RootMonitorHandle::from), - ) - } - - fn primary_monitor(&self) -> Option { - self.inner.queue(|inner| inner.monitor.primary_monitor()).map(RootMonitorHandle::from) - } - - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { - self - } - - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { - self - } } #[cfg(feature = "rwh_06")] From bc10ce94aa8412094064fed2d1accbf6b85fde80 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Fri, 18 Oct 2024 17:58:56 -0400 Subject: [PATCH 12/29] Rename enum variant to SurfaceEvent, fix Windows --- src/event.rs | 4 +- src/platform_impl/windows/drop_handler.rs | 14 +- src/platform_impl/windows/event_loop.rs | 210 +++++------ .../windows/event_loop/runner.rs | 16 +- src/platform_impl/windows/window.rs | 343 +++++++++--------- 5 files changed, 296 insertions(+), 291 deletions(-) diff --git a/src/event.rs b/src/event.rs index 5bdf5d9cbf..f673e46f16 100644 --- a/src/event.rs +++ b/src/event.rs @@ -72,7 +72,7 @@ pub(crate) enum Event { /// /// [`ApplicationHandler::window_event()`]: crate::application::ApplicationHandler::window_event() #[allow(clippy::enum_variant_names)] - WindowEvent { window_id: SurfaceId, event: SurfaceEvent }, + SurfaceEvent { window_id: SurfaceId, event: SurfaceEvent }, /// See [`ApplicationHandler::device_event()`] for details. /// @@ -1149,7 +1149,7 @@ mod tests { x(Resumed); // Window events. - let with_window_event = |wev| x(WindowEvent { window_id: wid, event: wev }); + let with_window_event = |wev| x(SurfaceEvent { window_id: wid, event: wev }); with_window_event(CloseRequested); with_window_event(Destroyed); diff --git a/src/platform_impl/windows/drop_handler.rs b/src/platform_impl/windows/drop_handler.rs index baff09896c..2745331a27 100644 --- a/src/platform_impl/windows/drop_handler.rs +++ b/src/platform_impl/windows/drop_handler.rs @@ -15,7 +15,7 @@ use crate::event::Event; use crate::platform_impl::platform::definitions::{ IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl, }; -use crate::window::WindowId; +use crate::window::SurfaceId; #[repr(C)] pub struct FileDropHandlerData { @@ -84,8 +84,8 @@ impl FileDropHandler { let drop_handler = unsafe { Self::from_interface(this) }; let hdrop = unsafe { Self::iterate_filenames(pDataObj, |filename| { - drop_handler.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(drop_handler.window as usize), + drop_handler.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(drop_handler.window as usize), event: HoveredFile(filename), }); }) @@ -118,8 +118,8 @@ impl FileDropHandler { use crate::event::SurfaceEvent::HoveredFileCancelled; let drop_handler = unsafe { Self::from_interface(this) }; if drop_handler.hovered_is_valid { - drop_handler.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(drop_handler.window as usize), + drop_handler.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(drop_handler.window as usize), event: HoveredFileCancelled, }); } @@ -138,8 +138,8 @@ impl FileDropHandler { let drop_handler = unsafe { Self::from_interface(this) }; let hdrop = unsafe { Self::iterate_filenames(pDataObj, |filename| { - drop_handler.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(drop_handler.window as usize), + drop_handler.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(drop_handler.window as usize), event: DroppedFile(filename), }); }) diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index f16d81727f..2e88a1e364 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -59,7 +59,7 @@ use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::error::{EventLoopError, RequestError}; use crate::event::{ Event, FingerId as RootFingerId, Force, Ime, RawKeyEvent, SurfaceSizeWriter, TouchPhase, - WindowEvent, + SurfaceEvent, }; use crate::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, @@ -85,7 +85,7 @@ use crate::platform_impl::Window; use crate::utils::Lazy; use crate::window::{ CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, - WindowAttributes, WindowId, + WindowAttributes, SurfaceId, }; pub(crate) struct WindowData { @@ -227,7 +227,7 @@ impl EventLoop { unsafe { runner.set_event_handler(move |event| match event { Event::NewEvents(cause) => app.new_events(event_loop_windows_ref, cause), - Event::WindowEvent { window_id, event } => { + Event::SurfaceEvent { window_id, event } => { app.window_event(event_loop_windows_ref, window_id, event) }, Event::DeviceEvent { device_id, event } => { @@ -293,7 +293,7 @@ impl EventLoop { unsafe { runner.set_event_handler(move |event| match event { Event::NewEvents(cause) => app.new_events(event_loop_windows_ref, cause), - Event::WindowEvent { window_id, event } => { + Event::SurfaceEvent { window_id, event } => { app.window_event(event_loop_windows_ref, window_id, event) }, Event::DeviceEvent { device_id, event } => { @@ -917,8 +917,8 @@ fn update_modifiers(window: HWND, userdata: &WindowData) { // Drop lock drop(window_state); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: ModifiersChanged(modifiers.into()), }); } @@ -929,8 +929,8 @@ unsafe fn gain_active_focus(window: HWND, userdata: &WindowData) { update_modifiers(window, userdata); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: Focused(true), }); } @@ -939,13 +939,13 @@ unsafe fn lose_active_focus(window: HWND, userdata: &WindowData) { use crate::event::SurfaceEvent::{Focused, ModifiersChanged}; userdata.window_state_lock().modifiers_state = ModifiersState::empty(); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: ModifiersChanged(ModifiersState::empty().into()), }); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: Focused(false), }); } @@ -1042,8 +1042,8 @@ unsafe fn public_window_callback_inner( let events = userdata.key_event_builder.process_message(window, msg, wparam, lparam, &mut result); for event in events { - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: KeyboardInput { device_id: None, event: event.event, @@ -1127,8 +1127,8 @@ unsafe fn public_window_callback_inner( WM_CLOSE => { use crate::event::SurfaceEvent::CloseRequested; - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: CloseRequested, }); result = ProcResult::Value(0); @@ -1137,8 +1137,8 @@ unsafe fn public_window_callback_inner( WM_DESTROY => { use crate::event::SurfaceEvent::Destroyed; unsafe { RevokeDragDrop(window) }; - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: Destroyed, }); result = ProcResult::Value(0); @@ -1158,9 +1158,9 @@ unsafe fn public_window_callback_inner( // window outside the normal flow of the event loop. This way mark event as handled // and request a normal redraw with `RedrawWindow`. if !userdata.event_loop_runner.should_buffer() { - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::RedrawRequested, + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::RedrawRequested, }); } @@ -1261,8 +1261,8 @@ unsafe fn public_window_callback_inner( if unsafe { (*windowpos).flags & SWP_NOMOVE != SWP_NOMOVE } { let physical_position = unsafe { PhysicalPosition::new((*windowpos).x, (*windowpos).y) }; - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: Moved(physical_position), }); } @@ -1277,8 +1277,8 @@ unsafe fn public_window_callback_inner( let h = super::hiword(lparam as u32) as u32; let physical_size = PhysicalSize::new(w, h); - let event = Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + let event = Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: SurfaceResized(physical_size), }; @@ -1392,9 +1392,9 @@ unsafe fn public_window_callback_inner( if ime_allowed { userdata.window_state_lock().ime_state = ImeState::Enabled; - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::Ime(Ime::Enabled), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::Ime(Ime::Enabled), }); } @@ -1412,9 +1412,9 @@ unsafe fn public_window_callback_inner( let ime_context = unsafe { ImeContext::current(window) }; if lparam == 0 { - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::Ime(Ime::Preedit(String::new(), None)), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::Ime(Ime::Preedit(String::new(), None)), }); } @@ -1424,13 +1424,13 @@ unsafe fn public_window_callback_inner( if let Some(text) = unsafe { ime_context.get_composed_text() } { userdata.window_state_lock().ime_state = ImeState::Enabled; - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::Ime(Ime::Preedit(String::new(), None)), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::Ime(Ime::Preedit(String::new(), None)), }); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::Ime(Ime::Commit(text)), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::Ime(Ime::Commit(text)), }); } } @@ -1443,9 +1443,9 @@ unsafe fn public_window_callback_inner( userdata.window_state_lock().ime_state = ImeState::Preedit; let cursor_range = first.map(|f| (f, last.unwrap_or(f))); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::Ime(Ime::Preedit(text, cursor_range)), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::Ime(Ime::Preedit(text, cursor_range)), }); } } @@ -1466,22 +1466,22 @@ unsafe fn public_window_callback_inner( // trying receiving composing result and commit if exists. let ime_context = unsafe { ImeContext::current(window) }; if let Some(text) = unsafe { ime_context.get_composed_text() } { - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::Ime(Ime::Preedit(String::new(), None)), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::Ime(Ime::Preedit(String::new(), None)), }); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::Ime(Ime::Commit(text)), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::Ime(Ime::Commit(text)), }); } } userdata.window_state_lock().ime_state = ImeState::Disabled; - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::Ime(Ime::Disabled), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::Ime(Ime::Disabled), }); } @@ -1538,8 +1538,8 @@ unsafe fn public_window_callback_inner( .ok(); drop(w); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerEntered { device_id: None, position, @@ -1563,8 +1563,8 @@ unsafe fn public_window_callback_inner( .ok(); drop(w); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerLeft { device_id: None, position: Some(position), @@ -1586,8 +1586,8 @@ unsafe fn public_window_callback_inner( if cursor_moved { update_modifiers(window, userdata); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerMoved { device_id: None, position, source: PointerSource::Mouse }, }); } @@ -1604,8 +1604,8 @@ unsafe fn public_window_callback_inner( w.mouse.set_cursor_flags(window, |f| f.set(CursorFlags::IN_WINDOW, false)).ok(); } - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerLeft { device_id: None, position: None, kind: Mouse }, }); @@ -1620,9 +1620,9 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::MouseWheel { + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::MouseWheel { device_id: None, delta: LineDelta(0.0, value), phase: TouchPhase::Moved, @@ -1640,9 +1640,9 @@ unsafe fn public_window_callback_inner( update_modifiers(window, userdata); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::MouseWheel { + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::MouseWheel { device_id: None, delta: LineDelta(value, 0.0), phase: TouchPhase::Moved, @@ -1679,8 +1679,8 @@ unsafe fn public_window_callback_inner( let y = super::get_y_lparam(lparam as u32) as i32; let position = PhysicalPosition::new(x as f64, y as f64); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerButton { device_id: None, state: Pressed, @@ -1704,8 +1704,8 @@ unsafe fn public_window_callback_inner( let y = super::get_y_lparam(lparam as u32) as i32; let position = PhysicalPosition::new(x as f64, y as f64); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerButton { device_id: None, state: Released, @@ -1729,8 +1729,8 @@ unsafe fn public_window_callback_inner( let y = super::get_y_lparam(lparam as u32) as i32; let position = PhysicalPosition::new(x as f64, y as f64); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerButton { device_id: None, state: Pressed, @@ -1754,8 +1754,8 @@ unsafe fn public_window_callback_inner( let y = super::get_y_lparam(lparam as u32) as i32; let position = PhysicalPosition::new(x as f64, y as f64); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerButton { device_id: None, state: Released, @@ -1779,8 +1779,8 @@ unsafe fn public_window_callback_inner( let y = super::get_y_lparam(lparam as u32) as i32; let position = PhysicalPosition::new(x as f64, y as f64); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerButton { device_id: None, state: Pressed, @@ -1804,8 +1804,8 @@ unsafe fn public_window_callback_inner( let y = super::get_y_lparam(lparam as u32) as i32; let position = PhysicalPosition::new(x as f64, y as f64); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerButton { device_id: None, state: Released, @@ -1830,8 +1830,8 @@ unsafe fn public_window_callback_inner( let y = super::get_y_lparam(lparam as u32) as i32; let position = PhysicalPosition::new(x as f64, y as f64); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerButton { device_id: None, state: Pressed, @@ -1861,8 +1861,8 @@ unsafe fn public_window_callback_inner( let y = super::get_y_lparam(lparam as u32) as i32; let position = PhysicalPosition::new(x as f64, y as f64); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: PointerButton { device_id: None, state: Released, @@ -1917,24 +1917,24 @@ unsafe fn public_window_callback_inner( let y = position.y as f64 + (input.y % 100) as f64 / 100f64; let position = PhysicalPosition::new(x, y); - let window_id = WindowId::from_raw(window as usize); + let window_id = SurfaceId::from_raw(window as usize); let finger_id = RootFingerId(FingerId { id: input.dwID, primary: util::has_flag(input.dwFlags, TOUCHEVENTF_PRIMARY), }); if util::has_flag(input.dwFlags, TOUCHEVENTF_DOWN) { - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerEntered { + event: SurfaceEvent::PointerEntered { device_id: None, position, kind: PointerKind::Touch(finger_id), }, }); - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id: None, state: Pressed, position, @@ -1942,27 +1942,27 @@ unsafe fn public_window_callback_inner( }, }); } else if util::has_flag(input.dwFlags, TOUCHEVENTF_UP) { - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id: None, state: Released, position, button: Touch { finger_id, force: None }, }, }); - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerLeft { + event: SurfaceEvent::PointerLeft { device_id: None, position: Some(position), kind: PointerKind::Touch(finger_id), }, }); } else if util::has_flag(input.dwFlags, TOUCHEVENTF_MOVE) { - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerMoved { + event: SurfaceEvent::PointerMoved { device_id: None, position, source: PointerSource::Touch { finger_id, force: None }, @@ -2085,16 +2085,16 @@ unsafe fn public_window_callback_inner( let y = location.y as f64 + y.fract(); let position = PhysicalPosition::new(x, y); - let window_id = WindowId::from_raw(window as usize); + let window_id = SurfaceId::from_raw(window as usize); let finger_id = RootFingerId(FingerId { id: pointer_info.pointerId, primary: util::has_flag(pointer_info.pointerFlags, POINTER_FLAG_PRIMARY), }); if util::has_flag(pointer_info.pointerFlags, POINTER_FLAG_DOWN) { - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerEntered { + event: SurfaceEvent::PointerEntered { device_id: None, position, kind: if let PT_TOUCH = pointer_info.pointerType { @@ -2104,9 +2104,9 @@ unsafe fn public_window_callback_inner( }, }, }); - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id: None, state: Pressed, position, @@ -2118,9 +2118,9 @@ unsafe fn public_window_callback_inner( }, }); } else if util::has_flag(pointer_info.pointerFlags, POINTER_FLAG_UP) { - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id: None, state: Released, position, @@ -2131,9 +2131,9 @@ unsafe fn public_window_callback_inner( }, }, }); - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerLeft { + event: SurfaceEvent::PointerLeft { device_id: None, position: Some(position), kind: if let PT_TOUCH = pointer_info.pointerType { @@ -2144,9 +2144,9 @@ unsafe fn public_window_callback_inner( }, }); } else if util::has_flag(pointer_info.pointerFlags, POINTER_FLAG_UPDATE) { - userdata.send_event(Event::WindowEvent { + userdata.send_event(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerMoved { + event: SurfaceEvent::PointerMoved { device_id: None, position, source: if let PT_TOUCH = pointer_info.pointerType { @@ -2317,8 +2317,8 @@ unsafe fn public_window_callback_inner( }; let new_surface_size = Arc::new(Mutex::new(new_physical_surface_size)); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: ScaleFactorChanged { scale_factor: new_scale_factor, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)), @@ -2469,8 +2469,8 @@ unsafe fn public_window_callback_inner( if window_state.current_theme != new_theme { window_state.current_theme = new_theme; drop(window_state); - userdata.send_event(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), + userdata.send_event(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), event: ThemeChanged(new_theme), }); } diff --git a/src/platform_impl/windows/event_loop/runner.rs b/src/platform_impl/windows/event_loop/runner.rs index 3b712167ec..dbe142b2c7 100644 --- a/src/platform_impl/windows/event_loop/runner.rs +++ b/src/platform_impl/windows/event_loop/runner.rs @@ -9,10 +9,10 @@ use windows_sys::Win32::Foundation::HWND; use super::ControlFlow; use crate::dpi::PhysicalSize; -use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent}; +use crate::event::{Event, StartCause, SurfaceSizeWriter, SurfaceEvent}; use crate::platform_impl::platform::event_loop::{WindowData, GWL_USERDATA}; use crate::platform_impl::platform::get_window_long; -use crate::window::WindowId; +use crate::window::SurfaceId; type EventHandler = Cell>>; @@ -201,7 +201,7 @@ impl EventLoopRunner { } pub(crate) fn send_event(&self, event: Event) { - if let Event::WindowEvent { event: WindowEvent::RedrawRequested, .. } = event { + if let Event::SurfaceEvent { event: SurfaceEvent::RedrawRequested, .. } = event { self.call_event_handler(event); // As a rule, to ensure that `pump_events` can't block an external event loop // for too long, we always guarantee that `pump_events` will return control to @@ -356,8 +356,8 @@ impl EventLoopRunner { impl BufferedEvent { pub fn from_event(event: Event) -> BufferedEvent { match event { - Event::WindowEvent { - event: WindowEvent::ScaleFactorChanged { scale_factor, surface_size_writer }, + Event::SurfaceEvent { + event: SurfaceEvent::ScaleFactorChanged { scale_factor, surface_size_writer }, window_id, } => BufferedEvent::ScaleFactorChanged( window_id.into_raw() as HWND, @@ -373,9 +373,9 @@ impl BufferedEvent { Self::Event(event) => dispatch(event), Self::ScaleFactorChanged(window, scale_factor, new_surface_size) => { let user_new_surface_size = Arc::new(Mutex::new(new_surface_size)); - dispatch(Event::WindowEvent { - window_id: WindowId::from_raw(window as usize), - event: WindowEvent::ScaleFactorChanged { + dispatch(Event::SurfaceEvent { + window_id: SurfaceId::from_raw(window as usize), + event: SurfaceEvent::ScaleFactorChanged { scale_factor, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade( &user_new_surface_size, diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 7d76da0695..bb896ba747 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -69,7 +69,7 @@ use crate::platform_impl::platform::window_state::{ use crate::platform_impl::platform::{monitor, util, Fullscreen, SelectedCursor}; use crate::window::{ CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme, - UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, WindowId, + UserAttentionType, Window as CoreWindow, Surface as CoreSurface, WindowAttributes, WindowButtons, SurfaceId, WindowLevel, }; @@ -365,12 +365,54 @@ impl rwh_06::HasWindowHandle for Window { } } -impl CoreWindow for Window { - fn set_title(&self, text: &str) { - let wide_text = util::encode_wide(text); +impl CoreSurface for Window { + fn id(&self) -> SurfaceId { + SurfaceId::from_raw(self.hwnd() as usize) + } + fn scale_factor(&self) -> f64 { + self.window_state_lock().scale_factor + } + + fn pre_present_notify(&self) {} + + fn request_redraw(&self) { + // NOTE: mark that we requested a redraw to handle requests during `WM_PAINT` handling. + self.window_state.lock().unwrap().redraw_requested = true; unsafe { - SetWindowTextW(self.hwnd(), wide_text.as_ptr()); + RedrawWindow(self.hwnd(), ptr::null(), 0, RDW_INTERNALPAINT); + } + } + + fn surface_size(&self) -> PhysicalSize { + let mut rect: RECT = unsafe { mem::zeroed() }; + if unsafe { GetClientRect(self.hwnd(), &mut rect) } == false.into() { + panic!( + "Unexpected GetClientRect failure: please report this error to \ + rust-windowing/winit" + ) + } + PhysicalSize::new((rect.right - rect.left) as u32, (rect.bottom - rect.top) as u32) + } + + fn request_surface_size(&self, size: Size) -> Option> { + let scale_factor = self.scale_factor(); + let physical_size = size.to_physical::(scale_factor); + + let window_flags = self.window_state_lock().window_flags; + window_flags.set_size(self.hwnd(), physical_size); + + if physical_size != self.surface_size() { + let window_state = Arc::clone(&self.window_state); + let window = self.window; + self.thread_executor.execute_in_thread(move || { + let _ = &window; + WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| { + f.set(WindowFlags::MAXIMIZED, false) + }); + }); } + + None } fn set_transparent(&self, transparent: bool) { @@ -384,32 +426,149 @@ impl CoreWindow for Window { }); } - fn set_blur(&self, _blur: bool) {} + fn set_cursor(&self, cursor: Cursor) { + match cursor { + Cursor::Icon(icon) => { + self.window_state_lock().mouse.selected_cursor = SelectedCursor::Named(icon); + self.thread_executor.execute_in_thread(move || unsafe { + let cursor = LoadCursorW(0, util::to_windows_cursor(icon)); + SetCursor(cursor); + }); + }, + Cursor::Custom(cursor) => { + self.window_state_lock().mouse.selected_cursor = + SelectedCursor::Custom(cursor.inner.0.clone()); + self.thread_executor.execute_in_thread(move || unsafe { + SetCursor(cursor.inner.0.as_raw_handle()); + }); + }, + } + } + + fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> { + let confine = match mode { + CursorGrabMode::None => false, + CursorGrabMode::Confined => true, + CursorGrabMode::Locked => { + return Err(NotSupportedError::new("locked cursor is not supported").into()) + }, + }; - fn set_visible(&self, visible: bool) { let window = self.window; let window_state = Arc::clone(&self.window_state); + let (tx, rx) = channel(); + self.thread_executor.execute_in_thread(move || { let _ = &window; + let result = window_state + .lock() + .unwrap() + .mouse + .set_cursor_flags(window, |f| f.set(CursorFlags::GRABBED, confine)) + .map_err(|err| os_error!(err).into()); + let _ = tx.send(result); + }); + + rx.recv().unwrap() + } + + fn set_cursor_visible(&self, visible: bool) { + let window = self.window; + let window_state = Arc::clone(&self.window_state); + let (tx, rx) = channel(); + + self.thread_executor.execute_in_thread(move || { + let _ = &window; + let result = window_state + .lock() + .unwrap() + .mouse + .set_cursor_flags(window, |f| f.set(CursorFlags::HIDDEN, !visible)) + .map_err(|e| e.to_string()); + let _ = tx.send(result); + }); + rx.recv().unwrap().ok(); + } + + fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { + let scale_factor = self.scale_factor(); + let (x, y) = position.to_physical::(scale_factor).into(); + + let mut point = POINT { x, y }; + unsafe { + if ClientToScreen(self.hwnd(), &mut point) == false.into() { + return Err(os_error!(io::Error::last_os_error()).into()); + } + if SetCursorPos(point.x, point.y) == false.into() { + return Err(os_error!(io::Error::last_os_error()).into()); + } + } + Ok(()) + } + + fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { + let window = self.window; + let window_state = Arc::clone(&self.window_state); + self.thread_executor.execute_in_thread(move || { WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| { - f.set(WindowFlags::VISIBLE, visible) + f.set(WindowFlags::IGNORE_CURSOR_EVENT, !hittest) }); }); + + Ok(()) } - fn is_visible(&self) -> Option { - Some(unsafe { IsWindowVisible(self.window) == 1 }) + fn current_monitor(&self) -> Option { + Some(CoreMonitorHandle { inner: monitor::current_monitor(self.hwnd()) }) } - fn request_redraw(&self) { - // NOTE: mark that we requested a redraw to handle requests during `WM_PAINT` handling. - self.window_state.lock().unwrap().redraw_requested = true; + fn available_monitors(&self) -> Box> { + Box::new(monitor::available_monitors().into_iter().map(|inner| CoreMonitorHandle { inner })) + } + + fn primary_monitor(&self) -> Option { + Some(CoreMonitorHandle { inner: monitor::primary_monitor() }) + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + self + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + self + } + + fn as_window(&self) -> Option<&dyn CoreWindow> { + Some(self) + } +} + +impl CoreWindow for Window { + fn set_title(&self, text: &str) { + let wide_text = util::encode_wide(text); unsafe { - RedrawWindow(self.hwnd(), ptr::null(), 0, RDW_INTERNALPAINT); + SetWindowTextW(self.hwnd(), wide_text.as_ptr()); } } - fn pre_present_notify(&self) {} + fn set_blur(&self, _blur: bool) {} + + fn set_visible(&self, visible: bool) { + let window = self.window; + let window_state = Arc::clone(&self.window_state); + self.thread_executor.execute_in_thread(move || { + let _ = &window; + WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| { + f.set(WindowFlags::VISIBLE, visible) + }); + }); + } + + fn is_visible(&self) -> Option { + Some(unsafe { IsWindowVisible(self.window) == 1 }) + } fn outer_position(&self) -> Result, RequestError> { util::WindowArea::Outer @@ -458,17 +617,6 @@ impl CoreWindow for Window { } } - fn surface_size(&self) -> PhysicalSize { - let mut rect: RECT = unsafe { mem::zeroed() }; - if unsafe { GetClientRect(self.hwnd(), &mut rect) } == false.into() { - panic!( - "Unexpected GetClientRect failure: please report this error to \ - rust-windowing/winit" - ) - } - PhysicalSize::new((rect.right - rect.left) as u32, (rect.bottom - rect.top) as u32) - } - fn outer_size(&self) -> PhysicalSize { util::WindowArea::Outer .get_rect(self.hwnd()) @@ -478,27 +626,6 @@ impl CoreWindow for Window { .unwrap() } - fn request_surface_size(&self, size: Size) -> Option> { - let scale_factor = self.scale_factor(); - let physical_size = size.to_physical::(scale_factor); - - let window_flags = self.window_state_lock().window_flags; - window_flags.set_size(self.hwnd(), physical_size); - - if physical_size != self.surface_size() { - let window_state = Arc::clone(&self.window_state); - let window = self.window; - self.thread_executor.execute_in_thread(move || { - let _ = &window; - WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| { - f.set(WindowFlags::MAXIMIZED, false) - }); - }); - } - - None - } - fn set_min_surface_size(&self, size: Option) { self.window_state_lock().min_size = size; // Make windows re-check the window size bounds. @@ -569,90 +696,6 @@ impl CoreWindow for Window { buttons } - fn set_cursor(&self, cursor: Cursor) { - match cursor { - Cursor::Icon(icon) => { - self.window_state_lock().mouse.selected_cursor = SelectedCursor::Named(icon); - self.thread_executor.execute_in_thread(move || unsafe { - let cursor = LoadCursorW(0, util::to_windows_cursor(icon)); - SetCursor(cursor); - }); - }, - Cursor::Custom(cursor) => { - self.window_state_lock().mouse.selected_cursor = - SelectedCursor::Custom(cursor.inner.0.clone()); - self.thread_executor.execute_in_thread(move || unsafe { - SetCursor(cursor.inner.0.as_raw_handle()); - }); - }, - } - } - - fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> { - let confine = match mode { - CursorGrabMode::None => false, - CursorGrabMode::Confined => true, - CursorGrabMode::Locked => { - return Err(NotSupportedError::new("locked cursor is not supported").into()) - }, - }; - - let window = self.window; - let window_state = Arc::clone(&self.window_state); - let (tx, rx) = channel(); - - self.thread_executor.execute_in_thread(move || { - let _ = &window; - let result = window_state - .lock() - .unwrap() - .mouse - .set_cursor_flags(window, |f| f.set(CursorFlags::GRABBED, confine)) - .map_err(|err| os_error!(err).into()); - let _ = tx.send(result); - }); - - rx.recv().unwrap() - } - - fn set_cursor_visible(&self, visible: bool) { - let window = self.window; - let window_state = Arc::clone(&self.window_state); - let (tx, rx) = channel(); - - self.thread_executor.execute_in_thread(move || { - let _ = &window; - let result = window_state - .lock() - .unwrap() - .mouse - .set_cursor_flags(window, |f| f.set(CursorFlags::HIDDEN, !visible)) - .map_err(|e| e.to_string()); - let _ = tx.send(result); - }); - rx.recv().unwrap().ok(); - } - - fn scale_factor(&self) -> f64 { - self.window_state_lock().scale_factor - } - - fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { - let scale_factor = self.scale_factor(); - let (x, y) = position.to_physical::(scale_factor).into(); - - let mut point = POINT { x, y }; - unsafe { - if ClientToScreen(self.hwnd(), &mut point) == false.into() { - return Err(os_error!(io::Error::last_os_error()).into()); - } - if SetCursorPos(point.x, point.y) == false.into() { - return Err(os_error!(io::Error::last_os_error()).into()); - } - } - Ok(()) - } - fn drag_window(&self) -> Result<(), RequestError> { unsafe { self.handle_os_dragging(HTCAPTION as WPARAM); @@ -684,22 +727,6 @@ impl CoreWindow for Window { } } - fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { - let window = self.window; - let window_state = Arc::clone(&self.window_state); - self.thread_executor.execute_in_thread(move || { - WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| { - f.set(WindowFlags::IGNORE_CURSOR_EVENT, !hittest) - }); - }); - - Ok(()) - } - - fn id(&self) -> WindowId { - WindowId::from_raw(self.hwnd() as usize) - } - fn set_minimized(&self, minimized: bool) { let window = self.window; let window_state = Arc::clone(&self.window_state); @@ -924,18 +951,6 @@ impl CoreWindow for Window { }); } - fn current_monitor(&self) -> Option { - Some(CoreMonitorHandle { inner: monitor::current_monitor(self.hwnd()) }) - } - - fn available_monitors(&self) -> Box> { - Box::new(monitor::available_monitors().into_iter().map(|inner| CoreMonitorHandle { inner })) - } - - fn primary_monitor(&self) -> Option { - Some(CoreMonitorHandle { inner: monitor::primary_monitor() }) - } - fn set_window_icon(&self, window_icon: Option) { if let Some(ref window_icon) = window_icon { window_icon.inner.set_for_window(self.hwnd(), IconType::Small); @@ -1053,16 +1068,6 @@ impl CoreWindow for Window { ); } } - - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { - self - } - - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { - self - } } pub(super) struct InitData<'a> { From 07cfc01968aafaf31e293b80b9e089d82380c46e Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Fri, 18 Oct 2024 18:03:44 -0400 Subject: [PATCH 13/29] Fix Linux and Web platforms --- .../linux/wayland/event_loop/mod.rs | 4 +- .../linux/wayland/event_loop/sink.rs | 2 +- .../linux/x11/event_processor.rs | 64 +++++++++---------- src/platform_impl/linux/x11/mod.rs | 4 +- src/platform_impl/linux/x11/window.rs | 2 +- src/platform_impl/web/event_loop/mod.rs | 2 +- src/platform_impl/web/event_loop/runner.rs | 6 +- .../web/event_loop/window_target.rs | 50 +++++++-------- src/platform_impl/web/web_sys/canvas.rs | 4 +- 9 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index c615550783..e153d02726 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -375,7 +375,7 @@ impl EventLoop { }); for event in buffer_sink.drain() { match event { - Event::WindowEvent { window_id, event } => { + Event::SurfaceEvent { window_id, event } => { app.window_event(&self.active_event_loop, window_id, event) }, Event::DeviceEvent { device_id, event } => { @@ -391,7 +391,7 @@ impl EventLoop { }); for event in buffer_sink.drain() { match event { - Event::WindowEvent { window_id, event } => { + Event::SurfaceEvent { window_id, event } => { app.window_event(&self.active_event_loop, window_id, event) }, Event::DeviceEvent { device_id, event } => { diff --git a/src/platform_impl/linux/wayland/event_loop/sink.rs b/src/platform_impl/linux/wayland/event_loop/sink.rs index 8f988afc02..d530fda1a5 100644 --- a/src/platform_impl/linux/wayland/event_loop/sink.rs +++ b/src/platform_impl/linux/wayland/event_loop/sink.rs @@ -32,7 +32,7 @@ impl EventSink { /// Add new window event to a queue. #[inline] pub fn push_window_event(&mut self, event: SurfaceEvent, window_id: SurfaceId) { - self.window_events.push(Event::WindowEvent { event, window_id }); + self.window_events.push(Event::SurfaceEvent { event, window_id }); } #[inline] diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 9adbe07df3..fc1d557378 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -119,7 +119,7 @@ impl EventProcessor { _ => continue, }; - callback(&self.target, Event::WindowEvent { window_id, event }); + callback(&self.target, Event::SurfaceEvent { window_id, event }); } } @@ -371,7 +371,7 @@ impl EventProcessor { let window_id = mkwid(window); if xev.data.get_long(0) as xproto::Atom == self.target.wm_delete_window { - let event = Event::WindowEvent { window_id, event: SurfaceEvent::CloseRequested }; + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::CloseRequested }; callback(&self.target, event); return; } @@ -521,7 +521,7 @@ impl EventProcessor { let (source_window, state) = if let Some(source_window) = self.dnd.source_window { if let Some(Ok(ref path_list)) = self.dnd.result { for path in path_list { - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::DroppedFile(path.clone()), }; @@ -548,7 +548,7 @@ impl EventProcessor { if xev.message_type == atoms[XdndLeave] as c_ulong { self.dnd.reset(); - let event = Event::WindowEvent { window_id, event: SurfaceEvent::HoveredFileCancelled }; + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::HoveredFileCancelled }; callback(&self.target, event); } } @@ -575,7 +575,7 @@ impl EventProcessor { let parse_result = self.dnd.parse_data(&mut data); if let Ok(ref path_list) = parse_result { for path in path_list { - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::HoveredFile(path.clone()), }; @@ -659,7 +659,7 @@ impl EventProcessor { if moved { callback( &self.target, - Event::WindowEvent { window_id, event: SurfaceEvent::Moved(outer.into()) }, + Event::SurfaceEvent { window_id, event: SurfaceEvent::Moved(outer.into()) }, ); } outer @@ -708,7 +708,7 @@ impl EventProcessor { let surface_size = Arc::new(Mutex::new(new_surface_size)); callback( &self.target, - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ScaleFactorChanged { scale_factor: new_scale_factor, @@ -769,7 +769,7 @@ impl EventProcessor { if resized { callback( &self.target, - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::SurfaceResized(new_surface_size.into()), }, @@ -803,7 +803,7 @@ impl EventProcessor { // window, given that we can't rely on `CreateNotify`, due to it being not // sent. let focus = self.with_window(window, |window| window.has_focus()).unwrap_or_default(); - let event = Event::WindowEvent { window_id, event: SurfaceEvent::Focused(focus) }; + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(focus) }; callback(&self.target, event); } @@ -827,7 +827,7 @@ impl EventProcessor { .expect("Failed to destroy input context"); } - callback(&self.target, Event::WindowEvent { window_id, event: SurfaceEvent::Destroyed }); + callback(&self.target, Event::SurfaceEvent { window_id, event: SurfaceEvent::Destroyed }); } fn property_notify(&mut self, xev: &XPropertyEvent, mut callback: F) @@ -850,7 +850,7 @@ impl EventProcessor { { let xwindow = xev.window as xproto::Window; - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id: mkwid(xwindow), event: SurfaceEvent::Occluded(xev.state == xlib::VisibilityFullyObscured), }; @@ -871,7 +871,7 @@ impl EventProcessor { let window = xev.window as xproto::Window; let window_id = mkwid(window); - let event = Event::WindowEvent { window_id, event: SurfaceEvent::RedrawRequested }; + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::RedrawRequested }; callback(&self.target, event); } @@ -951,7 +951,7 @@ impl EventProcessor { if let Some(mut key_processor) = self.xkb_context.key_context() { let event = key_processor.process_key_event(keycode, state, repeat); - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::KeyboardInput { device_id: None, @@ -975,14 +975,14 @@ impl EventProcessor { { let written = self.target.xconn.lookup_utf8(ic, xev); if !written.is_empty() { - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::Ime(Ime::Preedit(String::new(), None)), }; callback(&self.target, event); let event = - Event::WindowEvent { window_id, event: SurfaceEvent::Ime(Ime::Commit(written)) }; + Event::SurfaceEvent { window_id, event: SurfaceEvent::Ime(Ime::Commit(written)) }; self.is_composing = false; callback(&self.target, event); @@ -1017,7 +1017,7 @@ impl EventProcessor { let mods: ModifiersState = xkb_state.modifiers().into(); let event = - Event::WindowEvent { window_id, event: SurfaceEvent::ModifiersChanged(mods.into()) }; + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(mods.into()) }; callback(&self.target, event); } @@ -1096,7 +1096,7 @@ impl EventProcessor { }, }; - let event = Event::WindowEvent { window_id, event }; + let event = Event::SurfaceEvent { window_id, event }; callback(&self.target, event); } @@ -1120,7 +1120,7 @@ impl EventProcessor { if cursor_moved == Some(true) { let position = PhysicalPosition::new(event.event_x, event.event_y); - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerMoved { device_id, @@ -1166,7 +1166,7 @@ impl EventProcessor { }; let event = SurfaceEvent::MouseWheel { device_id, delta, phase: TouchPhase::Moved }; - events.push(Event::WindowEvent { window_id, event }); + events.push(Event::SurfaceEvent { window_id, event }); } value = unsafe { value.offset(1) }; @@ -1209,7 +1209,7 @@ impl EventProcessor { let device_id = Some(device_id); let position = PhysicalPosition::new(event.event_x, event.event_y); - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerEntered { device_id, @@ -1233,7 +1233,7 @@ impl EventProcessor { // Leave, FocusIn, and FocusOut can be received by a window that's already // been destroyed, which the user presumably doesn't want to deal with. if self.window_exists(window) { - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id: mkwid(window), event: SurfaceEvent::PointerLeft { device_id: Some(mkdid(event.deviceid as xinput::DeviceId)), @@ -1273,7 +1273,7 @@ impl EventProcessor { window.shared_state_lock().has_focus = true; } - let event = Event::WindowEvent { window_id, event: SurfaceEvent::Focused(true) }; + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(true) }; callback(&self.target, event); // Issue key press events for all pressed keys @@ -1295,7 +1295,7 @@ impl EventProcessor { .get(&mkdid(xev.deviceid as xinput::DeviceId)) .map(|device| mkdid(device.attachment as xinput::DeviceId)); - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerMoved { device_id, position, source: PointerSource::Mouse }, }; @@ -1348,7 +1348,7 @@ impl EventProcessor { window.shared_state_lock().has_focus = false; } - let event = Event::WindowEvent { window_id, event: SurfaceEvent::Focused(false) }; + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(false) }; callback(&self.target, event) } } @@ -1369,7 +1369,7 @@ impl EventProcessor { // Mouse cursor position changes when touch events are received. // Only the first concurrently active touch ID moves the mouse cursor. if is_first_touch(&mut self.first_touch, &mut self.num_touch, id, phase) { - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerMoved { device_id: None, @@ -1385,7 +1385,7 @@ impl EventProcessor { match phase { xinput2::XI_TouchBegin => { - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerEntered { device_id, @@ -1394,7 +1394,7 @@ impl EventProcessor { }, }; callback(&self.target, event); - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerButton { device_id, @@ -1406,7 +1406,7 @@ impl EventProcessor { callback(&self.target, event); }, xinput2::XI_TouchUpdate => { - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerMoved { device_id, @@ -1417,7 +1417,7 @@ impl EventProcessor { callback(&self.target, event); }, xinput2::XI_TouchEnd => { - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerButton { device_id, @@ -1427,7 +1427,7 @@ impl EventProcessor { }, }; callback(&self.target, event); - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerLeft { device_id, @@ -1777,7 +1777,7 @@ impl EventProcessor { // NOTE: Always update the modifiers to account for case when they've changed // and forced was `true`. if self.modifiers.replace(modifiers) != modifiers || force { - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(self.modifiers.get().into()), }; @@ -1814,7 +1814,7 @@ impl EventProcessor { for keycode in target.xconn.query_keymap().into_iter().filter(|k| *k >= KEYCODE_OFFSET) { let event = key_processor.process_key_event(keycode as u32, state, false); - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: true }, }; diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index a1d2099cc7..61609eb0e0 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -574,12 +574,12 @@ impl EventLoop { while unsafe { self.event_processor.poll_one_event(xev.as_mut_ptr()) } { let mut xev = unsafe { xev.assume_init() }; self.event_processor.process_event(&mut xev, |window_target, event: Event| { - if let Event::WindowEvent { window_id, event: SurfaceEvent::RedrawRequested } = event + if let Event::SurfaceEvent { window_id, event: SurfaceEvent::RedrawRequested } = event { window_target.redraw_sender.send(window_id); } else { match event { - Event::WindowEvent { window_id, event } => { + Event::SurfaceEvent { window_id, event } => { app.window_event(window_target, window_id, event) }, Event::DeviceEvent { device_id, event } => { diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index e22fb2a4d4..d5bb7ca213 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -1232,7 +1232,7 @@ impl UnownedWindow { let old_surface_size = PhysicalSize::new(width, height); let surface_size = Arc::new(Mutex::new(PhysicalSize::new(new_width, new_height))); - callback(Event::WindowEvent { + callback(Event::SurfaceEvent { window_id: self.id(), event: SurfaceEvent::ScaleFactorChanged { scale_factor: new_monitor.scale_factor, diff --git a/src/platform_impl/web/event_loop/mod.rs b/src/platform_impl/web/event_loop/mod.rs index 9c13266814..306427b511 100644 --- a/src/platform_impl/web/event_loop/mod.rs +++ b/src/platform_impl/web/event_loop/mod.rs @@ -90,7 +90,7 @@ impl EventLoop { fn handle_event(app: &mut A, target: &ActiveEventLoop, event: Event) { match event { Event::NewEvents(cause) => app.new_events(target, cause), - Event::WindowEvent { window_id, event } => app.window_event(target, window_id, event), + Event::SurfaceEvent { window_id, event } => app.window_event(target, window_id, event), Event::DeviceEvent { device_id, event } => app.device_event(target, device_id, event), Event::UserWakeUp => app.proxy_wake_up(target), Event::Suspended => app.suspended(target), diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index 8709a0e5c1..fdf0bdff9d 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -421,7 +421,7 @@ impl Shared { if let (false, Some(true) | None) | (true, Some(true)) = (is_visible, canvas.is_intersecting.get()) { - runner.send_event(Event::WindowEvent { + runner.send_event(Event::SurfaceEvent { window_id: *id, event: SurfaceEvent::Occluded(!is_visible), }); @@ -566,7 +566,7 @@ impl Shared { fn process_destroy_pending_windows(&self) { while let Some(id) = self.0.destroy_pending.borrow_mut().pop_front() { self.0.all_canvases.borrow_mut().retain(|&(item_id, ..)| item_id != id); - self.handle_event(Event::WindowEvent { + self.handle_event(Event::SurfaceEvent { window_id: id, event: crate::event::SurfaceEvent::Destroyed, }); @@ -587,7 +587,7 @@ impl Shared { // Collect all of the redraw events to avoid double-locking the RefCell let redraw_events: Vec = self.0.redraw_pending.borrow_mut().drain().collect(); for window_id in redraw_events { - self.handle_event(Event::WindowEvent { + self.handle_event(Event::SurfaceEvent { window_id, event: SurfaceEvent::RedrawRequested, }); diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 46d4df8c52..c799e9d13c 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -83,13 +83,13 @@ impl ActiveEventLoop { let clear_modifiers = (!modifiers.get().is_empty()).then(|| { modifiers.set(ModifiersState::empty()); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(ModifiersState::empty().into()), } }); - runner.send_events(clear_modifiers.into_iter().chain(iter::once(Event::WindowEvent { + runner.send_events(clear_modifiers.into_iter().chain(iter::once(Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(false), }))); @@ -99,7 +99,7 @@ impl ActiveEventLoop { let has_focus = canvas.has_focus.clone(); canvas.on_focus(move || { if !has_focus.replace(true) { - runner.send_event(Event::WindowEvent { + runner.send_event(Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(true), }); @@ -120,7 +120,7 @@ impl ActiveEventLoop { if focused { canvas.has_focus.set(true); self.runner - .send_event(Event::WindowEvent { window_id, event: SurfaceEvent::Focused(true) }) + .send_event(Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(true) }) } let runner = self.runner.clone(); @@ -129,14 +129,14 @@ impl ActiveEventLoop { move |physical_key, logical_key, text, location, repeat, active_modifiers| { let modifiers_changed = (modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events( - iter::once(Event::WindowEvent { + iter::once(Event::SurfaceEvent { window_id, event: SurfaceEvent::KeyboardInput { device_id: None, @@ -163,14 +163,14 @@ impl ActiveEventLoop { move |physical_key, logical_key, text, location, repeat, active_modifiers| { let modifiers_changed = (modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events( - iter::once(Event::WindowEvent { + iter::once(Event::SurfaceEvent { window_id, event: SurfaceEvent::KeyboardInput { device_id: None, @@ -200,13 +200,13 @@ impl ActiveEventLoop { move |active_modifiers, device_id, position, kind| { let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); - runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent { + runner.send_events(focus.into_iter().chain(iter::once(Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerLeft { device_id, position: Some(position), kind }, }))) @@ -221,13 +221,13 @@ impl ActiveEventLoop { move |active_modifiers, device_id, position, kind| { let focus = (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); - runner.send_events(focus.into_iter().chain(iter::once(Event::WindowEvent { + runner.send_events(focus.into_iter().chain(iter::once(Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerEntered { device_id, position, kind }, }))) @@ -245,13 +245,13 @@ impl ActiveEventLoop { let modifiers = (has_focus.get() && modifiers.get() != active_modifiers) .then(|| { modifiers.set(active_modifiers); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); - modifiers.into_iter().chain(iter::once(Event::WindowEvent { + modifiers.into_iter().chain(iter::once(Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerMoved { device_id, position, source }, })) @@ -267,13 +267,13 @@ impl ActiveEventLoop { let modifiers = (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); - runner.send_events(modifiers.into_iter().chain([Event::WindowEvent { + runner.send_events(modifiers.into_iter().chain([Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerButton { device_id, state, position, button }, }])); @@ -288,13 +288,13 @@ impl ActiveEventLoop { move |active_modifiers, device_id, position, button| { let modifiers = (modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); - runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent { + runner.send_events(modifiers.into_iter().chain(iter::once(Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerButton { device_id, @@ -315,13 +315,13 @@ impl ActiveEventLoop { let modifiers = (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); - runner.send_events(modifiers.into_iter().chain(iter::once(Event::WindowEvent { + runner.send_events(modifiers.into_iter().chain(iter::once(Event::SurfaceEvent { window_id, event: SurfaceEvent::PointerButton { device_id, @@ -339,14 +339,14 @@ impl ActiveEventLoop { let modifiers_changed = (has_focus.get() && modifiers.get() != active_modifiers).then(|| { modifiers.set(active_modifiers); - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::ModifiersChanged(active_modifiers.into()), } }); runner.send_events(modifiers_changed.into_iter().chain(iter::once( - Event::WindowEvent { + Event::SurfaceEvent { window_id, event: SurfaceEvent::MouseWheel { device_id: None, @@ -360,7 +360,7 @@ impl ActiveEventLoop { let runner = self.runner.clone(); canvas.on_dark_mode(move |is_dark_mode| { let theme = if is_dark_mode { Theme::Dark } else { Theme::Light }; - runner.send_event(Event::WindowEvent { + runner.send_event(Event::SurfaceEvent { window_id, event: SurfaceEvent::ThemeChanged(theme), }); @@ -387,7 +387,7 @@ impl ActiveEventLoop { canvas.set_current_size(new_size); if canvas.old_size() != new_size { canvas.set_old_size(new_size); - runner.send_event(Event::WindowEvent { + runner.send_event(Event::SurfaceEvent { window_id, event: SurfaceEvent::SurfaceResized(new_size), }); @@ -403,7 +403,7 @@ impl ActiveEventLoop { if backend::is_visible(runner.document()) && !(is_intersecting && canvas_clone.is_intersecting.get().is_none()) { - runner.send_event(Event::WindowEvent { + runner.send_event(Event::SurfaceEvent { window_id, event: SurfaceEvent::Occluded(!is_intersecting), }); diff --git a/src/platform_impl/web/web_sys/canvas.rs b/src/platform_impl/web/web_sys/canvas.rs index 3fedb945a8..80c36bfccf 100644 --- a/src/platform_impl/web/web_sys/canvas.rs +++ b/src/platform_impl/web/web_sys/canvas.rs @@ -488,7 +488,7 @@ impl Canvas { self.set_current_size(current_size); let new_size = { let new_size = Arc::new(Mutex::new(current_size)); - event_handler(crate::event::Event::WindowEvent { + event_handler(crate::event::Event::SurfaceEvent { window_id: self.id, event: crate::event::SurfaceEvent::ScaleFactorChanged { scale_factor: scale, @@ -516,7 +516,7 @@ impl Canvas { } else if self.old_size() != new_size { // Then we at least send a resized event. self.set_old_size(new_size); - runner.send_event(crate::event::Event::WindowEvent { + runner.send_event(crate::event::Event::SurfaceEvent { window_id: self.id, event: crate::event::SurfaceEvent::SurfaceResized(new_size), }) From dde143bb27df11154f47631ced170cd837658af1 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Fri, 18 Oct 2024 18:20:08 -0400 Subject: [PATCH 14/29] Add changelog entry --- src/changelog/unreleased.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 151a21692c..2ebda8345f 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -66,6 +66,7 @@ changelog entry. - Add `PointerKind`, `PointerSource`, `ButtonSource`, `FingerId` and `position` to all pointer events as part of the pointer event overhaul. - Add `DeviceId::into_raw()` and `from_raw()`. +- Add the `Surface` trait to represent a generic drawable area. ### Changed @@ -150,6 +151,10 @@ changelog entry. the primary finger in a multi-touch interaction. - In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`. - Remove `Force::Calibrated::altitude_angle`. +- Various window-related things are renamed to account for the fact they work with all surfaces. + - Rename `WindowId` to `SurfaceId`. + - Rename `WindowEvent` to `SurfaceEvent`. + - Rename `Event::WindowEvent` to `Event::SurfaceEvent`. ### Removed From 44d205d42ae137291d078ff9b9820824ef9060f4 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Fri, 18 Oct 2024 20:17:15 -0400 Subject: [PATCH 15/29] implement as_window for Web window --- src/platform_impl/web/window.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index dd6a1ac27e..ac6884a2af 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -184,6 +184,10 @@ impl RootSurface for Window { fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { self } + + fn as_window(&self) -> Option<&dyn RootWindow> { + Some(self) + } } impl RootWindow for Window { From c5efc692f6453b32ce32b9165980d91bcac2851c Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Mon, 21 Oct 2024 18:31:12 -0400 Subject: [PATCH 16/29] implement Android --- src/platform_impl/android/mod.rs | 79 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 104221f5d5..853e85b20f 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -25,7 +25,7 @@ use crate::platform::pump_events::PumpStatus; use crate::window::{ self, CursorGrabMode, CustomCursor, CustomCursorSource, Fullscreen, ImePurpose, ResizeDirection, Theme, Window as CoreWindow, WindowAttributes, WindowButtons, WindowId, - WindowLevel, + WindowLevel, Surface as CoreSurface }; mod keycodes; @@ -804,7 +804,7 @@ impl rwh_06::HasWindowHandle for Window { } } -impl CoreWindow for Window { +impl CoreSurface for Window { fn id(&self) -> WindowId { GLOBAL_WINDOW } @@ -831,6 +831,45 @@ impl CoreWindow for Window { fn pre_present_notify(&self) {} + fn surface_size(&self) -> PhysicalSize { + self.outer_size() + } + + fn request_surface_size(&self, _size: Size) -> Option> { + Some(self.surface_size()) + } + + fn set_transparent(&self, _transparent: bool) {} + + fn set_cursor(&self, _: Cursor) {} + + fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> { + Err(NotSupportedError::new("set_cursor_position is not supported").into()) + } + + fn set_cursor_grab(&self, _: CursorGrabMode) -> Result<(), RequestError> { + Err(NotSupportedError::new("set_cursor_grab is not supported").into()) + } + + fn set_cursor_visible(&self, _: bool) {} + + fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), RequestError> { + Err(NotSupportedError::new("set_cursor_hittest is not supported").into()) + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + self + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + self + } +} + +impl CoreWindow for Window { + fn inner_position(&self) -> Result, RequestError> { Err(NotSupportedError::new("inner_position is not supported").into()) } @@ -843,14 +882,6 @@ impl CoreWindow for Window { // no effect } - fn surface_size(&self) -> PhysicalSize { - self.outer_size() - } - - fn request_surface_size(&self, _size: Size) -> Option> { - Some(self.surface_size()) - } - fn outer_size(&self) -> PhysicalSize { screen_size(&self.app) } @@ -867,8 +898,6 @@ impl CoreWindow for Window { fn set_title(&self, _title: &str) {} - fn set_transparent(&self, _transparent: bool) {} - fn set_blur(&self, _blur: bool) {} fn set_visible(&self, _visibility: bool) {} @@ -929,18 +958,6 @@ impl CoreWindow for Window { fn request_user_attention(&self, _request_type: Option) {} - fn set_cursor(&self, _: Cursor) {} - - fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> { - Err(NotSupportedError::new("set_cursor_position is not supported").into()) - } - - fn set_cursor_grab(&self, _: CursorGrabMode) -> Result<(), RequestError> { - Err(NotSupportedError::new("set_cursor_grab is not supported").into()) - } - - fn set_cursor_visible(&self, _: bool) {} - fn drag_window(&self) -> Result<(), RequestError> { Err(NotSupportedError::new("drag_window is not supported").into()) } @@ -952,10 +969,6 @@ impl CoreWindow for Window { #[inline] fn show_window_menu(&self, _position: Position) {} - fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), RequestError> { - Err(NotSupportedError::new("set_cursor_hittest is not supported").into()) - } - fn set_theme(&self, _theme: Option) {} fn theme(&self) -> Option { @@ -973,16 +986,6 @@ impl CoreWindow for Window { } fn reset_dead_keys(&self) {} - - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { - self - } - - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { - self - } } #[derive(Default, Clone, Debug)] From f47c3f17b200faf78d7fa9949a0db160843c0d70 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Mon, 21 Oct 2024 19:42:58 -0400 Subject: [PATCH 17/29] fix SurfaceId on Android --- src/platform_impl/android/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 853e85b20f..9387834d40 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -24,7 +24,7 @@ use crate::monitor::MonitorHandle as RootMonitorHandle; use crate::platform::pump_events::PumpStatus; use crate::window::{ self, CursorGrabMode, CustomCursor, CustomCursorSource, Fullscreen, ImePurpose, - ResizeDirection, Theme, Window as CoreWindow, WindowAttributes, WindowButtons, WindowId, + ResizeDirection, Theme, Window as CoreWindow, WindowAttributes, WindowButtons, SurfaceId, WindowLevel, Surface as CoreSurface }; From 9b34bc5a8e244738ad30614954b2f9b83cc1c584 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Mon, 21 Oct 2024 19:42:58 -0400 Subject: [PATCH 18/29] fix SurfaceId on Android --- src/platform_impl/android/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 9387834d40..f60f74cfff 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -124,7 +124,7 @@ impl Default for PlatformSpecificEventLoopAttributes { } // Android currently only supports one window -const GLOBAL_WINDOW: WindowId = WindowId::from_raw(0); +const GLOBAL_WINDOW: SurfaceId = SurfaceId::from_raw(0); impl EventLoop { pub(crate) fn new( @@ -805,7 +805,7 @@ impl rwh_06::HasWindowHandle for Window { } impl CoreSurface for Window { - fn id(&self) -> WindowId { + fn id(&self) -> SurfaceId { GLOBAL_WINDOW } From 14285968b0881bf0abfc03e7f46cbef00eb478d6 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Tue, 22 Oct 2024 14:31:16 -0400 Subject: [PATCH 19/29] try to fix apple and orbital --- src/platform_impl/apple/appkit/app_state.rs | 14 ++--- src/platform_impl/apple/appkit/view.rs | 56 +++++++++--------- src/platform_impl/apple/appkit/window.rs | 8 +-- .../apple/appkit/window_delegate.rs | 36 ++++++------ src/platform_impl/apple/uikit/app_state.rs | 22 +++---- src/platform_impl/apple/uikit/view.rs | 58 +++++++++---------- src/platform_impl/apple/uikit/window.rs | 24 ++++---- src/platform_impl/orbital/event_loop.rs | 14 ++--- src/platform_impl/orbital/window.rs | 10 ++-- 9 files changed, 121 insertions(+), 121 deletions(-) diff --git a/src/platform_impl/apple/appkit/app_state.rs b/src/platform_impl/apple/appkit/app_state.rs index 6c1769ff3b..61694bd1b9 100644 --- a/src/platform_impl/apple/appkit/app_state.rs +++ b/src/platform_impl/apple/appkit/app_state.rs @@ -13,9 +13,9 @@ use super::event_loop::{stop_app_immediately, ActiveEventLoop, PanicInfo}; use super::menu; use super::observer::{EventLoopWaker, RunLoop}; use crate::application::ApplicationHandler; -use crate::event::{StartCause, WindowEvent}; +use crate::event::{StartCause, SurfaceEvent}; use crate::event_loop::ControlFlow; -use crate::window::WindowId; +use crate::window::SurfaceId; #[derive(Debug)] pub(super) struct AppState { @@ -40,7 +40,7 @@ pub(super) struct AppState { waker: RefCell, start_time: Cell>, wait_timeout: Cell>, - pending_redraw: RefCell>, + pending_redraw: RefCell>, // NOTE: This is strongly referenced by our `NSWindowDelegate` and our `NSView` subclass, and // as such should be careful to not add fields that, in turn, strongly reference those. } @@ -240,12 +240,12 @@ impl AppState { self.control_flow.get() } - pub fn handle_redraw(self: &Rc, window_id: WindowId) { + pub fn handle_redraw(self: &Rc, window_id: SurfaceId) { // Redraw request might come out of order from the OS. // -> Don't go back into the event handler when our callstack originates from there if !self.event_handler.in_use() { self.with_handler(|app, event_loop| { - app.window_event(event_loop, window_id, WindowEvent::RedrawRequested); + app.window_event(event_loop, window_id, SurfaceEvent::RedrawRequested); }); // `pump_events` will request to stop immediately _after_ dispatching RedrawRequested @@ -258,7 +258,7 @@ impl AppState { } } - pub fn queue_redraw(&self, window_id: WindowId) { + pub fn queue_redraw(&self, window_id: SurfaceId) { let mut pending_redraw = self.pending_redraw.borrow_mut(); if !pending_redraw.contains(&window_id) { pending_redraw.push(window_id); @@ -357,7 +357,7 @@ impl AppState { let redraw = mem::take(&mut *self.pending_redraw.borrow_mut()); for window_id in redraw { self.with_handler(|app, event_loop| { - app.window_event(event_loop, window_id, WindowEvent::RedrawRequested); + app.window_event(event_loop, window_id, SurfaceEvent::RedrawRequested); }); } self.with_handler(|app, event_loop| { diff --git a/src/platform_impl/apple/appkit/view.rs b/src/platform_impl/apple/appkit/view.rs index 357e1cd648..faa15e20d0 100644 --- a/src/platform_impl/apple/appkit/view.rs +++ b/src/platform_impl/apple/appkit/view.rs @@ -27,7 +27,7 @@ use super::window::WinitWindow; use crate::dpi::{LogicalPosition, LogicalSize}; use crate::event::{ DeviceEvent, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, PointerKind, - PointerSource, TouchPhase, WindowEvent, + PointerSource, TouchPhase, SurfaceEvent, }; use crate::keyboard::{Key, KeyCode, KeyLocation, ModifiersState, NamedKey}; use crate::platform::macos::OptionAsAlt; @@ -196,7 +196,7 @@ declare_class!( // 2. Even when a window resize does occur on a new tabbed window, it contains the wrong size (includes tab height). let logical_size = LogicalSize::new(rect.size.width as f64, rect.size.height as f64); let size = logical_size.to_physical::(self.scale_factor()); - self.queue_event(WindowEvent::SurfaceResized(size)); + self.queue_event(SurfaceEvent::SurfaceResized(size)); } #[method(drawRect:)] @@ -301,7 +301,7 @@ declare_class!( // Notify IME is active if application still doesn't know it. if self.ivars().ime_state.get() == ImeState::Disabled { *self.ivars().input_source.borrow_mut() = self.current_input_source(); - self.queue_event(WindowEvent::Ime(Ime::Enabled)); + self.queue_event(SurfaceEvent::Ime(Ime::Enabled)); } if unsafe { self.hasMarkedText() } { @@ -324,8 +324,8 @@ declare_class!( Some((lowerbound_utf8, upperbound_utf8)) }; - // Send WindowEvent for updating marked text - self.queue_event(WindowEvent::Ime(Ime::Preedit(string.to_string(), cursor_range))); + // Send SurfaceEvent for updating marked text + self.queue_event(SurfaceEvent::Ime(Ime::Preedit(string.to_string(), cursor_range))); } #[method(unmarkText)] @@ -336,7 +336,7 @@ declare_class!( let input_context = self.inputContext().expect("input context"); input_context.discardMarkedText(); - self.queue_event(WindowEvent::Ime(Ime::Preedit(String::new(), None))); + self.queue_event(SurfaceEvent::Ime(Ime::Preedit(String::new(), None))); if self.is_ime_enabled() { // Leave the Preedit self.ivars() self.ivars().ime_state.set(ImeState::Ground); @@ -403,8 +403,8 @@ declare_class!( // Commit only if we have marked text. if unsafe { self.hasMarkedText() } && self.is_ime_enabled() && !is_control { - self.queue_event(WindowEvent::Ime(Ime::Preedit(String::new(), None))); - self.queue_event(WindowEvent::Ime(Ime::Commit(string))); + self.queue_event(SurfaceEvent::Ime(Ime::Preedit(String::new(), None))); + self.queue_event(SurfaceEvent::Ime(Ime::Commit(string))); self.ivars().ime_state.set(ImeState::Committed); } } @@ -442,7 +442,7 @@ declare_class!( *prev_input_source = current_input_source; drop(prev_input_source); self.ivars().ime_state.set(ImeState::Disabled); - self.queue_event(WindowEvent::Ime(Ime::Disabled)); + self.queue_event(SurfaceEvent::Ime(Ime::Disabled)); } } @@ -483,7 +483,7 @@ declare_class!( if !had_ime_input || self.ivars().forward_key_to_app.get() { let key_event = create_key_event(&event, true, unsafe { event.isARepeat() }, None); - self.queue_event(WindowEvent::KeyboardInput { + self.queue_event(SurfaceEvent::KeyboardInput { device_id: None, event: key_event, is_synthetic: false, @@ -503,7 +503,7 @@ declare_class!( self.ivars().ime_state.get(), ImeState::Ground | ImeState::Disabled ) { - self.queue_event(WindowEvent::KeyboardInput { + self.queue_event(SurfaceEvent::KeyboardInput { device_id: None, event: create_key_event(&event, false, false, None), is_synthetic: false, @@ -554,7 +554,7 @@ declare_class!( self.update_modifiers(&event, false); let event = create_key_event(&event, true, unsafe { event.isARepeat() }, None); - self.queue_event(WindowEvent::KeyboardInput { + self.queue_event(SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false, @@ -642,7 +642,7 @@ declare_class!( let position = self.mouse_view_point(event).to_physical(self.scale_factor()); - self.queue_event(WindowEvent::PointerEntered { + self.queue_event(SurfaceEvent::PointerEntered { device_id: None, position, kind: PointerKind::Mouse, @@ -655,7 +655,7 @@ declare_class!( let position = self.mouse_view_point(event).to_physical(self.scale_factor()); - self.queue_event(WindowEvent::PointerLeft { + self.queue_event(SurfaceEvent::PointerLeft { device_id: None, position: Some(position), kind: PointerKind::Mouse, @@ -698,7 +698,7 @@ declare_class!( self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| app.device_event(event_loop, None, DeviceEvent::MouseWheel { delta }) ); - self.queue_event(WindowEvent::MouseWheel { + self.queue_event(SurfaceEvent::MouseWheel { device_id: None, delta, phase, @@ -720,7 +720,7 @@ declare_class!( _ => return, }; - self.queue_event(WindowEvent::PinchGesture { + self.queue_event(SurfaceEvent::PinchGesture { device_id: None, delta: unsafe { event.magnification() }, phase, @@ -733,7 +733,7 @@ declare_class!( self.mouse_motion(event); - self.queue_event(WindowEvent::DoubleTapGesture { + self.queue_event(SurfaceEvent::DoubleTapGesture { device_id: None, }); } @@ -753,7 +753,7 @@ declare_class!( _ => return, }; - self.queue_event(WindowEvent::RotationGesture { + self.queue_event(SurfaceEvent::RotationGesture { device_id: None, delta: unsafe { event.rotation() }, phase, @@ -764,7 +764,7 @@ declare_class!( fn pressure_change_with_event(&self, event: &NSEvent) { trace_scope!("pressureChangeWithEvent:"); - self.queue_event(WindowEvent::TouchpadPressure { + self.queue_event(SurfaceEvent::TouchpadPressure { device_id: None, pressure: unsafe { event.pressure() }, stage: unsafe { event.stage() } as i64, @@ -840,7 +840,7 @@ impl WinitView { self.ivars()._ns_window.load().expect("view to have a window") } - fn queue_event(&self, event: WindowEvent) { + fn queue_event(&self, event: SurfaceEvent) { let window_id = self.window().id(); self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| { app.window_event(event_loop, window_id, event); @@ -899,7 +899,7 @@ impl WinitView { if self.ivars().ime_state.get() != ImeState::Disabled { self.ivars().ime_state.set(ImeState::Disabled); - self.queue_event(WindowEvent::Ime(Ime::Disabled)); + self.queue_event(SurfaceEvent::Ime(Ime::Disabled)); } } @@ -914,7 +914,7 @@ impl WinitView { pub(super) fn reset_modifiers(&self) { if !self.ivars().modifiers.get().state().is_empty() { self.ivars().modifiers.set(Modifiers::default()); - self.queue_event(WindowEvent::ModifiersChanged(self.ivars().modifiers.get())); + self.queue_event(SurfaceEvent::ModifiersChanged(self.ivars().modifiers.get())); } } @@ -978,7 +978,7 @@ impl WinitView { let mut event = event.clone(); event.location = KeyLocation::Left; event.physical_key = get_left_modifier_code(&event.logical_key).into(); - events.push_back(WindowEvent::KeyboardInput { + events.push_back(SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false, @@ -987,7 +987,7 @@ impl WinitView { if phys_mod.contains(ModLocationMask::RIGHT) { event.location = KeyLocation::Right; event.physical_key = get_right_modifier_code(&event.logical_key).into(); - events.push_back(WindowEvent::KeyboardInput { + events.push_back(SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false, @@ -1018,7 +1018,7 @@ impl WinitView { event.state = if is_pressed { Pressed } else { Released }; } - events.push_back(WindowEvent::KeyboardInput { + events.push_back(SurfaceEvent::KeyboardInput { device_id: None, event, is_synthetic: false, @@ -1037,7 +1037,7 @@ impl WinitView { return; } - self.queue_event(WindowEvent::ModifiersChanged(self.ivars().modifiers.get())); + self.queue_event(SurfaceEvent::ModifiersChanged(self.ivars().modifiers.get())); } fn mouse_click(&self, event: &NSEvent, button_state: ElementState) { @@ -1046,7 +1046,7 @@ impl WinitView { self.update_modifiers(event, false); - self.queue_event(WindowEvent::PointerButton { + self.queue_event(SurfaceEvent::PointerButton { device_id: None, state: button_state, position, @@ -1072,7 +1072,7 @@ impl WinitView { self.update_modifiers(event, false); - self.queue_event(WindowEvent::PointerMoved { + self.queue_event(SurfaceEvent::PointerMoved { device_id: None, position: view_point.to_physical(self.scale_factor()), source: PointerSource::Mouse, diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index be59dbed99..84eeb33b8c 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -12,7 +12,7 @@ use crate::error::RequestError; use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::window::{ Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow, - WindowAttributes, WindowButtons, WindowId, WindowLevel, + WindowAttributes, WindowButtons, SurfaceId, WindowLevel, }; pub(crate) struct Window { @@ -91,7 +91,7 @@ impl rwh_06::HasWindowHandle for Window { } impl CoreWindow for Window { - fn id(&self) -> crate::window::WindowId { + fn id(&self) -> crate::window::SurfaceId { self.maybe_wait_on_main(|delegate| delegate.id()) } @@ -363,7 +363,7 @@ declare_class!( ); impl WinitWindow { - pub(super) fn id(&self) -> WindowId { - WindowId::from_raw(self as *const Self as usize) + pub(super) fn id(&self) -> SurfaceId { + SurfaceId::from_raw(self as *const Self as usize) } } diff --git a/src/platform_impl/apple/appkit/window_delegate.rs b/src/platform_impl/apple/appkit/window_delegate.rs index e5652ba2f8..e50807dae7 100644 --- a/src/platform_impl/apple/appkit/window_delegate.rs +++ b/src/platform_impl/apple/appkit/window_delegate.rs @@ -36,11 +36,11 @@ use super::window::WinitWindow; use super::{ffi, Fullscreen, MonitorHandle}; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{SurfaceSizeWriter, WindowEvent}; +use crate::event::{SurfaceSizeWriter, SurfaceEvent}; use crate::platform::macos::{OptionAsAlt, WindowExtMacOS}; use crate::window::{ Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType, - WindowAttributes, WindowButtons, WindowId, WindowLevel, + WindowAttributes, WindowButtons, SurfaceId, WindowLevel, }; #[derive(Clone, Debug, PartialEq)] @@ -145,7 +145,7 @@ declare_class!( #[method(windowShouldClose:)] fn window_should_close(&self, _: Option<&AnyObject>) -> bool { trace_scope!("windowShouldClose:"); - self.queue_event(WindowEvent::CloseRequested); + self.queue_event(SurfaceEvent::CloseRequested); false } @@ -158,13 +158,13 @@ declare_class!( // be called after the window closes. self.window().setDelegate(None); }); - self.queue_event(WindowEvent::Destroyed); + self.queue_event(SurfaceEvent::Destroyed); } #[method(windowDidResize:)] fn window_did_resize(&self, _: Option<&AnyObject>) { trace_scope!("windowDidResize:"); - // NOTE: WindowEvent::SurfaceResized is reported in frameDidChange. + // NOTE: SurfaceEvent::SurfaceResized is reported in frameDidChange. self.emit_move_event(); } @@ -210,7 +210,7 @@ declare_class!( trace_scope!("windowDidBecomeKey:"); // TODO: center the cursor if the window had mouse grab when it // lost focus - self.queue_event(WindowEvent::Focused(true)); + self.queue_event(SurfaceEvent::Focused(true)); } #[method(windowDidResignKey:)] @@ -225,7 +225,7 @@ declare_class!( // a synthetic ModifiersChanged event when we lose focus. self.view().reset_modifiers(); - self.queue_event(WindowEvent::Focused(false)); + self.queue_event(SurfaceEvent::Focused(false)); } /// Invoked when before enter fullscreen @@ -350,7 +350,7 @@ declare_class!( fn window_did_change_occlusion_state(&self, _: Option<&AnyObject>) { trace_scope!("windowDidChangeOcclusionState:"); let visible = self.window().occlusionState().contains(NSWindowOcclusionState::Visible); - self.queue_event(WindowEvent::Occluded(!visible)); + self.queue_event(SurfaceEvent::Occluded(!visible)); } #[method(windowDidChangeScreen:)] @@ -379,7 +379,7 @@ declare_class!( filenames.into_iter().for_each(|file| { let path = PathBuf::from(file.to_string()); - self.queue_event(WindowEvent::HoveredFile(path)); + self.queue_event(SurfaceEvent::HoveredFile(path)); }); true @@ -405,7 +405,7 @@ declare_class!( filenames.into_iter().for_each(|file| { let path = PathBuf::from(file.to_string()); - self.queue_event(WindowEvent::DroppedFile(path)); + self.queue_event(SurfaceEvent::DroppedFile(path)); }); true @@ -421,7 +421,7 @@ declare_class!( #[method(draggingExited:)] fn dragging_exited(&self, _sender: Option<&NSObject>) { trace_scope!("draggingExited:"); - self.queue_event(WindowEvent::HoveredFileCancelled); + self.queue_event(SurfaceEvent::HoveredFileCancelled); } } @@ -469,7 +469,7 @@ declare_class!( return; } - self.queue_event(WindowEvent::ThemeChanged(new)); + self.queue_event(SurfaceEvent::ThemeChanged(new)); } else { panic!("unknown observed keypath {key_path:?}"); } @@ -778,7 +778,7 @@ impl WindowDelegate { // XXX Send `Focused(false)` right after creating the window delegate, so we won't // obscure the real focused events on the startup. - delegate.queue_event(WindowEvent::Focused(false)); + delegate.queue_event(SurfaceEvent::Focused(false)); // Set fullscreen mode after we setup everything delegate.set_fullscreen(attrs.fullscreen.map(Into::into)); @@ -814,11 +814,11 @@ impl WindowDelegate { } #[track_caller] - pub(crate) fn id(&self) -> WindowId { + pub(crate) fn id(&self) -> SurfaceId { self.window().id() } - pub(crate) fn queue_event(&self, event: WindowEvent) { + pub(crate) fn queue_event(&self, event: SurfaceEvent) { let window_id = self.window().id(); self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| { app.window_event(event_loop, window_id, event); @@ -833,7 +833,7 @@ impl WindowDelegate { let suggested_size = content_size.to_physical(scale_factor); let new_surface_size = Arc::new(Mutex::new(suggested_size)); - self.queue_event(WindowEvent::ScaleFactorChanged { + self.queue_event(SurfaceEvent::ScaleFactorChanged { scale_factor, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)), }); @@ -845,7 +845,7 @@ impl WindowDelegate { let size = NSSize::new(logical_size.width, logical_size.height); window.setContentSize(size); } - self.queue_event(WindowEvent::SurfaceResized(physical_size)); + self.queue_event(SurfaceEvent::SurfaceResized(physical_size)); } fn emit_move_event(&self) { @@ -857,7 +857,7 @@ impl WindowDelegate { let position = LogicalPosition::new(position.x, position.y).to_physical(self.scale_factor()); - self.queue_event(WindowEvent::Moved(position)); + self.queue_event(SurfaceEvent::Moved(position)); } fn set_style_mask(&self, mask: NSWindowStyleMask) { diff --git a/src/platform_impl/apple/uikit/app_state.rs b/src/platform_impl/apple/uikit/app_state.rs index 4b5880d170..5776c1f0dc 100644 --- a/src/platform_impl/apple/uikit/app_state.rs +++ b/src/platform_impl/apple/uikit/app_state.rs @@ -27,7 +27,7 @@ use super::window::WinitUIWindow; use super::ActiveEventLoop; use crate::application::ApplicationHandler; use crate::dpi::PhysicalSize; -use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent}; +use crate::event::{Event, StartCause, SurfaceSizeWriter, SurfaceEvent}; use crate::event_loop::ControlFlow; macro_rules! bug { @@ -71,7 +71,7 @@ fn handle_event(mtm: MainThreadMarker, event: Event) { let event_loop = &ActiveEventLoop { mtm }; get_handler(mtm).handle(|app| match event { Event::NewEvents(cause) => app.new_events(event_loop, cause), - Event::WindowEvent { window_id, event } => app.window_event(event_loop, window_id, event), + Event::SurfaceEvent { window_id, event } => app.window_event(event_loop, window_id, event), Event::DeviceEvent { device_id, event } => app.device_event(event_loop, device_id, event), Event::UserWakeUp => app.proxy_wake_up(event_loop), Event::Suspended => app.suspended(event_loop), @@ -103,7 +103,7 @@ enum UserCallbackTransitionResult<'a> { impl Event { fn is_redraw(&self) -> bool { - matches!(self, Event::WindowEvent { event: WindowEvent::RedrawRequested, .. }) + matches!(self, Event::SurfaceEvent { event: SurfaceEvent::RedrawRequested, .. }) } } @@ -597,9 +597,9 @@ pub(crate) fn send_occluded_event_for_all_windows(application: &UIApplication, o let ptr: *const WinitUIWindow = ptr.cast(); &*ptr }; - events.push(EventWrapper::StaticEvent(Event::WindowEvent { + events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::Occluded(occluded), + event: SurfaceEvent::Occluded(occluded), })); } } @@ -624,9 +624,9 @@ pub fn handle_main_events_cleared(mtm: MainThreadMarker) { .main_events_cleared_transition() .into_iter() .map(|window| { - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::RedrawRequested, + event: SurfaceEvent::RedrawRequested, }) }) .collect(); @@ -653,9 +653,9 @@ pub(crate) fn terminated(application: &UIApplication) { let ptr: *const WinitUIWindow = ptr.cast(); &*ptr }; - events.push(EventWrapper::StaticEvent(Event::WindowEvent { + events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::Destroyed, + event: SurfaceEvent::Destroyed, })); } } @@ -671,9 +671,9 @@ pub(crate) fn terminated(application: &UIApplication) { fn handle_hidpi_proxy(mtm: MainThreadMarker, event: ScaleFactorChanged) { let ScaleFactorChanged { suggested_size, scale_factor, window } = event; let new_surface_size = Arc::new(Mutex::new(suggested_size)); - let event = Event::WindowEvent { + let event = Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::ScaleFactorChanged { + event: SurfaceEvent::ScaleFactorChanged { scale_factor, surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&new_surface_size)), }, diff --git a/src/platform_impl/apple/uikit/view.rs b/src/platform_impl/apple/uikit/view.rs index e4c1844006..377fea562d 100644 --- a/src/platform_impl/apple/uikit/view.rs +++ b/src/platform_impl/apple/uikit/view.rs @@ -18,7 +18,7 @@ use super::FingerId; use crate::dpi::PhysicalPosition; use crate::event::{ ButtonSource, ElementState, Event, FingerId as RootFingerId, Force, KeyEvent, PointerKind, - PointerSource, TouchPhase, WindowEvent, + PointerSource, TouchPhase, SurfaceEvent, }; use crate::keyboard::{Key, KeyCode, KeyLocation, NamedKey, NativeKeyCode, PhysicalKey}; use crate::platform_impl::KeyEventExtra; @@ -57,9 +57,9 @@ declare_class!( let window = self.window().unwrap(); app_state::handle_nonuser_event( mtm, - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::RedrawRequested, + event: SurfaceEvent::RedrawRequested, }), ); let _: () = unsafe { msg_send![super(self), drawRect: rect] }; @@ -92,9 +92,9 @@ declare_class!( app_state::handle_nonuser_event( mtm, - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::SurfaceResized(size), + event: SurfaceEvent::SurfaceResized(size), }), ); } @@ -143,9 +143,9 @@ declare_class!( }, )) .chain(std::iter::once(EventWrapper::StaticEvent( - Event::WindowEvent { + Event::SurfaceEvent { window_id, - event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)), + event: SurfaceEvent::SurfaceResized(size.to_physical(scale_factor)), }, ))), ); @@ -196,9 +196,9 @@ declare_class!( state => panic!("unexpected recognizer state: {:?}", state), }; - let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { + let gesture_event = EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::PinchGesture { + event: SurfaceEvent::PinchGesture { device_id: None, delta: delta as f64, phase, @@ -214,9 +214,9 @@ declare_class!( let window = self.window().unwrap(); if recognizer.state() == UIGestureRecognizerState::Ended { - let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { + let gesture_event = EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::DoubleTapGesture { + event: SurfaceEvent::DoubleTapGesture { device_id: None, }, }); @@ -256,9 +256,9 @@ declare_class!( }; // Make delta negative to match macos, convert to degrees - let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { + let gesture_event = EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::RotationGesture { + event: SurfaceEvent::RotationGesture { device_id: None, delta: -delta.to_degrees() as _, phase, @@ -307,9 +307,9 @@ declare_class!( }; - let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { + let gesture_event = EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::PanGesture { + event: SurfaceEvent::PanGesture { device_id: None, delta: PhysicalPosition::new(dx as _, dy as _), phase, @@ -517,9 +517,9 @@ impl WinitView { match phase { UITouchPhase::Began => { - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerEntered { + event: SurfaceEvent::PointerEntered { device_id: None, position, kind: if let UITouchType::Pencil = touch_type { @@ -529,9 +529,9 @@ impl WinitView { }, }, })); - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id: None, state: ElementState::Pressed, position, @@ -544,9 +544,9 @@ impl WinitView { })); }, UITouchPhase::Moved => { - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerMoved { + event: SurfaceEvent::PointerMoved { device_id: None, position, source: if let UITouchType::Pencil = touch_type { @@ -560,9 +560,9 @@ impl WinitView { // 2 is UITouchPhase::Stationary and is not expected here UITouchPhase::Ended | UITouchPhase::Cancelled => { if let UITouchPhase::Ended = phase { - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerButton { + event: SurfaceEvent::PointerButton { device_id: None, state: ElementState::Released, position, @@ -575,9 +575,9 @@ impl WinitView { })); } - touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent { + touch_events.push(EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::PointerLeft { + event: SurfaceEvent::PointerLeft { device_id: None, position: Some(position), kind: if let UITouchType::Pencil = touch_type { @@ -606,9 +606,9 @@ impl WinitView { let text = smol_str::SmolStr::from_iter([c]); // Emit both press and release events [ElementState::Pressed, ElementState::Released].map(|state| { - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::KeyboardInput { + event: SurfaceEvent::KeyboardInput { event: KeyEvent { text: if state == ElementState::Pressed { Some(text.clone()) @@ -640,9 +640,9 @@ impl WinitView { app_state::handle_nonuser_events( mtm, [ElementState::Pressed, ElementState::Released].map(|state| { - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id, - event: WindowEvent::KeyboardInput { + event: SurfaceEvent::KeyboardInput { device_id: None, event: KeyEvent { state, diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index e5d1f9d2a5..9e7ac42b8e 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -20,13 +20,13 @@ use super::{app_state, monitor, ActiveEventLoop, Fullscreen, MonitorHandle}; use crate::cursor::Cursor; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{Event, WindowEvent}; +use crate::event::{Event, SurfaceEvent}; use crate::icon::Icon; use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations}; use crate::window::{ CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow, - WindowAttributes, WindowButtons, WindowId, WindowLevel, + WindowAttributes, WindowButtons, SurfaceId, WindowLevel, }; declare_class!( @@ -48,9 +48,9 @@ declare_class!( let mtm = MainThreadMarker::new().unwrap(); app_state::handle_nonuser_event( mtm, - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: self.id(), - event: WindowEvent::Focused(true), + event: SurfaceEvent::Focused(true), }), ); let _: () = unsafe { msg_send![super(self), becomeKeyWindow] }; @@ -61,9 +61,9 @@ declare_class!( let mtm = MainThreadMarker::new().unwrap(); app_state::handle_nonuser_event( mtm, - EventWrapper::StaticEvent(Event::WindowEvent { + EventWrapper::StaticEvent(Event::SurfaceEvent { window_id: self.id(), - event: WindowEvent::Focused(false), + event: SurfaceEvent::Focused(false), }), ); let _: () = unsafe { msg_send![super(self), resignKeyWindow] }; @@ -104,8 +104,8 @@ impl WinitUIWindow { this } - pub(crate) fn id(&self) -> WindowId { - WindowId::from_raw(self as *const Self as usize) + pub(crate) fn id(&self) -> SurfaceId { + SurfaceId::from_raw(self as *const Self as usize) } } @@ -416,7 +416,7 @@ impl Inner { Some(MonitorHandle::new(UIScreen::mainScreen(MainThreadMarker::new().unwrap()))) } - pub fn id(&self) -> WindowId { + pub fn id(&self) -> SurfaceId { self.window.id() } @@ -530,9 +530,9 @@ impl Window { suggested_size: size.to_physical(scale_factor), })) .chain(std::iter::once(EventWrapper::StaticEvent( - Event::WindowEvent { + Event::SurfaceEvent { window_id: window.id(), - event: WindowEvent::SurfaceResized(size.to_physical(scale_factor)), + event: SurfaceEvent::SurfaceResized(size.to_physical(scale_factor)), }, ))), ); @@ -584,7 +584,7 @@ impl rwh_06::HasWindowHandle for Window { } impl CoreWindow for Window { - fn id(&self) -> crate::window::WindowId { + fn id(&self) -> crate::window::SurfaceId { self.maybe_wait_on_main(|delegate| delegate.id()) } diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 2ab9e5b9e3..7ebb27c706 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -25,7 +25,7 @@ use crate::keyboard::{ }; use crate::platform_impl::Window; use crate::window::{ - CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, WindowId, + CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, SurfaceId, }; fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { @@ -314,7 +314,7 @@ impl EventLoop { } fn process_event( - window_id: WindowId, + window_id: SurfaceId, event_option: EventOption, event_state: &mut EventState, window_target: &ActiveEventLoop, @@ -505,7 +505,7 @@ impl EventLoop { let mut creates = self.window_target.creates.lock().unwrap(); creates.pop_front() } { - let window_id = WindowId::from_raw(window.fd); + let window_id = SurfaceId::from_raw(window.fd); let mut buf: [u8; 4096] = [0; 4096]; let path = window.fpath(&mut buf).expect("failed to read properties"); @@ -529,14 +529,14 @@ impl EventLoop { } { app.window_event(&self.window_target, destroy_id, event::SurfaceEvent::Destroyed); self.windows - .retain(|(window, _event_state)| WindowId::from_raw(window.fd) != destroy_id); + .retain(|(window, _event_state)| SurfaceId::from_raw(window.fd) != destroy_id); } // Handle window events. let mut i = 0; // While loop is used here because the same window may be processed more than once. while let Some((window, event_state)) = self.windows.get_mut(i) { - let window_id = WindowId::from_raw(window.fd); + let window_id = SurfaceId::from_raw(window.fd); let mut event_buf = [0u8; 16 * mem::size_of::()]; let count = @@ -702,8 +702,8 @@ pub struct ActiveEventLoop { control_flow: Cell, exit: Cell, pub(super) creates: Mutex>>, - pub(super) redraws: Arc>>, - pub(super) destroys: Arc>>, + pub(super) redraws: Arc>>, + pub(super) destroys: Arc>>, pub(super) event_socket: Arc, pub(super) wake_socket: Arc, user_events_sender: mpsc::SyncSender<()>, diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 0446a4ecca..7644a6771d 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -6,7 +6,7 @@ use crate::cursor::Cursor; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; use crate::monitor::MonitorHandle as CoreMonitorHandle; -use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, WindowId}; +use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, SurfaceId}; // These values match the values uses in the `window_new` function in orbital: // https://gitlab.redox-os.org/redox-os/orbital/-/blob/master/src/scheme.rs @@ -21,8 +21,8 @@ const ORBITAL_FLAG_TRANSPARENT: char = 't'; pub struct Window { window_socket: Arc, - redraws: Arc>>, - destroys: Arc>>, + redraws: Arc>>, + destroys: Arc>>, wake_socket: Arc, } @@ -155,8 +155,8 @@ impl Window { } impl CoreWindow for Window { - fn id(&self) -> WindowId { - WindowId::from_raw(self.window_socket.fd) + fn id(&self) -> SurfaceId { + SurfaceId::from_raw(self.window_socket.fd) } #[inline] From ae1d413ac5c5e17f99b2f5ed5c34dab06d3ad554 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Tue, 22 Oct 2024 16:40:41 -0400 Subject: [PATCH 20/29] do impl split for apple and orbital --- src/platform_impl/apple/appkit/window.rs | 92 ++++++++++++----------- src/platform_impl/apple/uikit/window.rs | 91 ++++++++++++----------- src/platform_impl/orbital/window.rs | 95 ++++++++++++------------ 3 files changed, 143 insertions(+), 135 deletions(-) diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index 84eeb33b8c..8ce8e9f338 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -12,7 +12,7 @@ use crate::error::RequestError; use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::window::{ Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow, - WindowAttributes, WindowButtons, SurfaceId, WindowLevel, + WindowAttributes, WindowButtons, SurfaceId, WindowLevel, Surface as CoreSurface, }; pub(crate) struct Window { @@ -90,7 +90,7 @@ impl rwh_06::HasWindowHandle for Window { } } -impl CoreWindow for Window { +impl CoreSurface for Window { fn id(&self) -> crate::window::SurfaceId { self.maybe_wait_on_main(|delegate| delegate.id()) } @@ -107,6 +107,51 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.pre_present_notify()); } + fn surface_size(&self) -> dpi::PhysicalSize { + self.maybe_wait_on_main(|delegate| delegate.surface_size()) + } + + fn request_surface_size(&self, size: Size) -> Option> { + self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size)) + } + + fn set_transparent(&self, transparent: bool) { + self.maybe_wait_on_main(|delegate| delegate.set_transparent(transparent)); + } + + fn set_cursor(&self, cursor: Cursor) { + self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor)); + } + + fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { + self.maybe_wait_on_main(|delegate| delegate.set_cursor_position(position)) + } + + fn set_cursor_grab(&self, mode: crate::window::CursorGrabMode) -> Result<(), RequestError> { + self.maybe_wait_on_main(|delegate| delegate.set_cursor_grab(mode)) + } + + fn set_cursor_visible(&self, visible: bool) { + self.maybe_wait_on_main(|delegate| delegate.set_cursor_visible(visible)) + } + + fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { + self.maybe_wait_on_main(|delegate| delegate.set_cursor_hittest(hittest)); + Ok(()) + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + self + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + self + } +} + +impl CoreWindow for Window { fn reset_dead_keys(&self) { self.maybe_wait_on_main(|delegate| delegate.reset_dead_keys()); } @@ -123,14 +168,6 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.set_outer_position(position)); } - fn surface_size(&self) -> dpi::PhysicalSize { - self.maybe_wait_on_main(|delegate| delegate.surface_size()) - } - - fn request_surface_size(&self, size: Size) -> Option> { - self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size)) - } - fn outer_size(&self) -> dpi::PhysicalSize { self.maybe_wait_on_main(|delegate| delegate.outer_size()) } @@ -155,10 +192,6 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.set_title(title)); } - fn set_transparent(&self, transparent: bool) { - self.maybe_wait_on_main(|delegate| delegate.set_transparent(transparent)); - } - fn set_blur(&self, blur: bool) { self.maybe_wait_on_main(|delegate| delegate.set_blur(blur)); } @@ -267,22 +300,6 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.title()) } - fn set_cursor(&self, cursor: Cursor) { - self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor)); - } - - fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { - self.maybe_wait_on_main(|delegate| delegate.set_cursor_position(position)) - } - - fn set_cursor_grab(&self, mode: crate::window::CursorGrabMode) -> Result<(), RequestError> { - self.maybe_wait_on_main(|delegate| delegate.set_cursor_grab(mode)) - } - - fn set_cursor_visible(&self, visible: bool) { - self.maybe_wait_on_main(|delegate| delegate.set_cursor_visible(visible)) - } - fn drag_window(&self) -> Result<(), RequestError> { self.maybe_wait_on_main(|delegate| delegate.drag_window()) } @@ -298,11 +315,6 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.show_window_menu(position)) } - fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { - self.maybe_wait_on_main(|delegate| delegate.set_cursor_hittest(hittest)); - Ok(()) - } - fn current_monitor(&self) -> Option { self.maybe_wait_on_main(|delegate| { delegate.current_monitor().map(|inner| CoreMonitorHandle { inner }) @@ -322,16 +334,6 @@ impl CoreWindow for Window { delegate.primary_monitor().map(|inner| CoreMonitorHandle { inner }) }) } - - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { - self - } - - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { - self - } } declare_class!( diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index 9e7ac42b8e..49c3206a12 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -26,7 +26,7 @@ use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations}; use crate::window::{ CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow, - WindowAttributes, WindowButtons, SurfaceId, WindowLevel, + WindowAttributes, WindowButtons, SurfaceId, WindowLevel, Surface as CoreSurface }; declare_class!( @@ -583,7 +583,7 @@ impl rwh_06::HasWindowHandle for Window { } } -impl CoreWindow for Window { +impl CoreSurface for Window { fn id(&self) -> crate::window::SurfaceId { self.maybe_wait_on_main(|delegate| delegate.id()) } @@ -600,6 +600,51 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.pre_present_notify()); } + fn surface_size(&self) -> PhysicalSize { + self.maybe_wait_on_main(|delegate| delegate.surface_size()) + } + + fn request_surface_size(&self, size: Size) -> Option> { + self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size)) + } + + fn set_transparent(&self, transparent: bool) { + self.maybe_wait_on_main(|delegate| delegate.set_transparent(transparent)); + } + + fn set_cursor(&self, cursor: Cursor) { + self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor)); + } + + fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { + Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_position(position))?) + } + + fn set_cursor_grab(&self, mode: crate::window::CursorGrabMode) -> Result<(), RequestError> { + Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_grab(mode))?) + } + + fn set_cursor_visible(&self, visible: bool) { + self.maybe_wait_on_main(|delegate| delegate.set_cursor_visible(visible)) + } + + fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { + Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_hittest(hittest))?) + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + self + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + self + } +} + +impl CoreWindow for Window { + fn reset_dead_keys(&self) { self.maybe_wait_on_main(|delegate| delegate.reset_dead_keys()); } @@ -616,14 +661,6 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.set_outer_position(position)); } - fn surface_size(&self) -> PhysicalSize { - self.maybe_wait_on_main(|delegate| delegate.surface_size()) - } - - fn request_surface_size(&self, size: Size) -> Option> { - self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size)) - } - fn outer_size(&self) -> PhysicalSize { self.maybe_wait_on_main(|delegate| delegate.outer_size()) } @@ -648,10 +685,6 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.set_title(title)); } - fn set_transparent(&self, transparent: bool) { - self.maybe_wait_on_main(|delegate| delegate.set_transparent(transparent)); - } - fn set_blur(&self, blur: bool) { self.maybe_wait_on_main(|delegate| delegate.set_blur(blur)); } @@ -760,22 +793,6 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.title()) } - fn set_cursor(&self, cursor: Cursor) { - self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor)); - } - - fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> { - Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_position(position))?) - } - - fn set_cursor_grab(&self, mode: crate::window::CursorGrabMode) -> Result<(), RequestError> { - Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_grab(mode))?) - } - - fn set_cursor_visible(&self, visible: bool) { - self.maybe_wait_on_main(|delegate| delegate.set_cursor_visible(visible)) - } - fn drag_window(&self) -> Result<(), RequestError> { Ok(self.maybe_wait_on_main(|delegate| delegate.drag_window())?) } @@ -791,10 +808,6 @@ impl CoreWindow for Window { self.maybe_wait_on_main(|delegate| delegate.show_window_menu(position)) } - fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { - Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_hittest(hittest))?) - } - fn current_monitor(&self) -> Option { self.maybe_wait_on_main(|delegate| { delegate.current_monitor().map(|inner| CoreMonitorHandle { inner }) @@ -814,16 +827,6 @@ impl CoreWindow for Window { delegate.primary_monitor().map(|inner| CoreMonitorHandle { inner }) }) } - - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { - self - } - - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { - self - } } // WindowExtIOS diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 7644a6771d..f586de366b 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -154,26 +154,11 @@ impl Window { } } -impl CoreWindow for Window { +impl CoreSurface for Window { fn id(&self) -> SurfaceId { SurfaceId::from_raw(self.window_socket.fd) } - #[inline] - fn primary_monitor(&self) -> Option { - Some(CoreMonitorHandle { inner: MonitorHandle }) - } - - #[inline] - fn available_monitors(&self) -> Box> { - Box::new(vec![CoreMonitorHandle { inner: MonitorHandle }].into_iter()) - } - - #[inline] - fn current_monitor(&self) -> Option { - Some(CoreMonitorHandle { inner: MonitorHandle }) - } - #[inline] fn scale_factor(&self) -> f64 { MonitorHandle.scale_factor() @@ -193,6 +178,54 @@ impl CoreWindow for Window { #[inline] fn pre_present_notify(&self) {} + #[inline] + fn surface_size(&self) -> PhysicalSize { + let mut buf: [u8; 4096] = [0; 4096]; + let path = self.window_socket.fpath(&mut buf).expect("failed to read properties"); + let properties = WindowProperties::new(path); + (properties.w, properties.h).into() + } + + #[inline] + fn request_surface_size(&self, size: Size) -> Option> { + let (w, h): (u32, u32) = size.to_physical::(self.scale_factor()).into(); + self.window_socket.write(format!("S,{w},{h}").as_bytes()).expect("failed to set size"); + None + } + + #[inline] + fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), RequestError> { + Err(NotSupportedError::new("set_cursor_hittest is not supported").into()) + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + self + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + self + } +} + +impl CoreWindow for Window { + + #[inline] + fn primary_monitor(&self) -> Option { + Some(CoreMonitorHandle { inner: MonitorHandle }) + } + + #[inline] + fn available_monitors(&self) -> Box> { + Box::new(vec![CoreMonitorHandle { inner: MonitorHandle }].into_iter()) + } + + #[inline] + fn current_monitor(&self) -> Option { + Some(CoreMonitorHandle { inner: MonitorHandle }) + } + #[inline] fn reset_dead_keys(&self) { // TODO? @@ -219,21 +252,6 @@ impl CoreWindow for Window { self.window_socket.write(format!("P,{x},{y}").as_bytes()).expect("failed to set position"); } - #[inline] - fn surface_size(&self) -> PhysicalSize { - let mut buf: [u8; 4096] = [0; 4096]; - let path = self.window_socket.fpath(&mut buf).expect("failed to read properties"); - let properties = WindowProperties::new(path); - (properties.w, properties.h).into() - } - - #[inline] - fn request_surface_size(&self, size: Size) -> Option> { - let (w, h): (u32, u32) = size.to_physical::(self.scale_factor()).into(); - self.window_socket.write(format!("S,{w},{h}").as_bytes()).expect("failed to set size"); - None - } - #[inline] fn outer_size(&self) -> PhysicalSize { // TODO: adjust for window decorations @@ -419,11 +437,6 @@ impl CoreWindow for Window { #[inline] fn show_window_menu(&self, _position: Position) {} - #[inline] - fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), RequestError> { - Err(NotSupportedError::new("set_cursor_hittest is not supported").into()) - } - #[inline] fn set_enabled_buttons(&self, _buttons: window::WindowButtons) {} @@ -446,16 +459,6 @@ impl CoreWindow for Window { fn set_theme(&self, _theme: Option) {} fn set_content_protected(&self, _protected: bool) {} - - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { - self - } - - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { - self - } } #[cfg(feature = "rwh_06")] From de71fd5697f73730c5b0cda6344dbe6f8b8b04de Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Tue, 22 Oct 2024 16:43:48 -0400 Subject: [PATCH 21/29] try to fix impl split for apple and orbital --- src/platform_impl/apple/appkit/window.rs | 44 ++++++------- src/platform_impl/apple/uikit/window.rs | 40 ++++++------ src/platform_impl/orbital/window.rs | 80 ++++++++++++------------ 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index 8ce8e9f338..3a557d1323 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -141,12 +141,32 @@ impl CoreSurface for Window { } #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { self } + fn current_monitor(&self) -> Option { + self.maybe_wait_on_main(|delegate| { + delegate.current_monitor().map(|inner| CoreMonitorHandle { inner }) + }) + } + + fn available_monitors(&self) -> Box> { + self.maybe_wait_on_main(|delegate| { + Box::new( + delegate.available_monitors().into_iter().map(|inner| CoreMonitorHandle { inner }), + ) + }) + } + + fn primary_monitor(&self) -> Option { + self.maybe_wait_on_main(|delegate| { + delegate.primary_monitor().map(|inner| CoreMonitorHandle { inner }) + }) + } + #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { self } } @@ -314,26 +334,6 @@ impl CoreWindow for Window { fn show_window_menu(&self, position: Position) { self.maybe_wait_on_main(|delegate| delegate.show_window_menu(position)) } - - fn current_monitor(&self) -> Option { - self.maybe_wait_on_main(|delegate| { - delegate.current_monitor().map(|inner| CoreMonitorHandle { inner }) - }) - } - - fn available_monitors(&self) -> Box> { - self.maybe_wait_on_main(|delegate| { - Box::new( - delegate.available_monitors().into_iter().map(|inner| CoreMonitorHandle { inner }), - ) - }) - } - - fn primary_monitor(&self) -> Option { - self.maybe_wait_on_main(|delegate| { - delegate.primary_monitor().map(|inner| CoreMonitorHandle { inner }) - }) - } } declare_class!( diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index 49c3206a12..daaa7c8374 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -632,6 +632,26 @@ impl CoreSurface for Window { Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_hittest(hittest))?) } + fn current_monitor(&self) -> Option { + self.maybe_wait_on_main(|delegate| { + delegate.current_monitor().map(|inner| CoreMonitorHandle { inner }) + }) + } + + fn available_monitors(&self) -> Box> { + self.maybe_wait_on_main(|delegate| { + Box::new( + delegate.available_monitors().into_iter().map(|inner| CoreMonitorHandle { inner }), + ) + }) + } + + fn primary_monitor(&self) -> Option { + self.maybe_wait_on_main(|delegate| { + delegate.primary_monitor().map(|inner| CoreMonitorHandle { inner }) + }) + } + #[cfg(feature = "rwh_06")] fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { self @@ -807,26 +827,6 @@ impl CoreWindow for Window { fn show_window_menu(&self, position: Position) { self.maybe_wait_on_main(|delegate| delegate.show_window_menu(position)) } - - fn current_monitor(&self) -> Option { - self.maybe_wait_on_main(|delegate| { - delegate.current_monitor().map(|inner| CoreMonitorHandle { inner }) - }) - } - - fn available_monitors(&self) -> Box> { - self.maybe_wait_on_main(|delegate| { - Box::new( - delegate.available_monitors().into_iter().map(|inner| CoreMonitorHandle { inner }), - ) - }) - } - - fn primary_monitor(&self) -> Option { - self.maybe_wait_on_main(|delegate| { - delegate.primary_monitor().map(|inner| CoreMonitorHandle { inner }) - }) - } } // WindowExtIOS diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index f586de366b..9db5370108 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -194,22 +194,38 @@ impl CoreSurface for Window { } #[inline] - fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), RequestError> { - Err(NotSupportedError::new("set_cursor_hittest is not supported").into()) + fn set_cursor(&self, _: Cursor) {} + + #[inline] + fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> { + Err(NotSupportedError::new("set_cursor_position is not supported").into()) } - - #[cfg(feature = "rwh_06")] - fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { - self + + #[inline] + fn set_cursor_grab(&self, mode: window::CursorGrabMode) -> Result<(), RequestError> { + let (grab, relative) = match mode { + window::CursorGrabMode::None => (false, false), + window::CursorGrabMode::Confined => (true, false), + window::CursorGrabMode::Locked => (true, true), + }; + self.window_socket + .write(format!("M,G,{}", if grab { 1 } else { 0 }).as_bytes()) + .map_err(|err| os_error!(format!("{err}")))?; + self.window_socket + .write(format!("M,R,{}", if relative { 1 } else { 0 }).as_bytes()) + .map_err(|err| os_error!(format!("{err}")))?; + Ok(()) } - #[cfg(feature = "rwh_06")] - fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { - self + #[inline] + fn set_cursor_visible(&self, visible: bool) { + let _ = self.window_socket.write(format!("M,C,{}", if visible { 1 } else { 0 }).as_bytes()); } -} -impl CoreWindow for Window { + #[inline] + fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), RequestError> { + Err(NotSupportedError::new("set_cursor_hittest is not supported").into()) + } #[inline] fn primary_monitor(&self) -> Option { @@ -225,6 +241,19 @@ impl CoreWindow for Window { fn current_monitor(&self) -> Option { Some(CoreMonitorHandle { inner: MonitorHandle }) } + + #[cfg(feature = "rwh_06")] + fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { + self + } + + #[cfg(feature = "rwh_06")] + fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { + self + } +} + +impl CoreWindow for Window { #[inline] fn reset_dead_keys(&self) { @@ -381,35 +410,6 @@ impl CoreWindow for Window { #[inline] fn request_user_attention(&self, _request_type: Option) {} - #[inline] - fn set_cursor(&self, _: Cursor) {} - - #[inline] - fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> { - Err(NotSupportedError::new("set_cursor_position is not supported").into()) - } - - #[inline] - fn set_cursor_grab(&self, mode: window::CursorGrabMode) -> Result<(), RequestError> { - let (grab, relative) = match mode { - window::CursorGrabMode::None => (false, false), - window::CursorGrabMode::Confined => (true, false), - window::CursorGrabMode::Locked => (true, true), - }; - self.window_socket - .write(format!("M,G,{}", if grab { 1 } else { 0 }).as_bytes()) - .map_err(|err| os_error!(format!("{err}")))?; - self.window_socket - .write(format!("M,R,{}", if relative { 1 } else { 0 }).as_bytes()) - .map_err(|err| os_error!(format!("{err}")))?; - Ok(()) - } - - #[inline] - fn set_cursor_visible(&self, visible: bool) { - let _ = self.window_socket.write(format!("M,C,{}", if visible { 1 } else { 0 }).as_bytes()); - } - #[inline] fn drag_window(&self) -> Result<(), RequestError> { self.window_socket.write(b"D").map_err(|err| os_error!(format!("{err}")))?; From 970f05d060e35ccc275f94c7305efc529ba37029 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Tue, 22 Oct 2024 16:48:12 -0400 Subject: [PATCH 22/29] small fixes to get everything to pass CI --- src/platform_impl/apple/appkit/window.rs | 4 ++++ src/platform_impl/apple/uikit/window.rs | 4 ++++ src/platform_impl/orbital/window.rs | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index 3a557d1323..72a06b5a40 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -169,6 +169,10 @@ impl CoreSurface for Window { fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { self } + + fn as_window(&self) -> Option<&dyn CoreWindow> { + Some(self) + } } impl CoreWindow for Window { diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index daaa7c8374..e01647269c 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -661,6 +661,10 @@ impl CoreSurface for Window { fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { self } + + fn as_window(&self) -> Option<&dyn CoreWindow> { + Some(self) + } } impl CoreWindow for Window { diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 9db5370108..4c5b922331 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -6,7 +6,7 @@ use crate::cursor::Cursor; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; use crate::monitor::MonitorHandle as CoreMonitorHandle; -use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, SurfaceId}; +use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, Surface as CoreSurface, SurfaceId}; // These values match the values uses in the `window_new` function in orbital: // https://gitlab.redox-os.org/redox-os/orbital/-/blob/master/src/scheme.rs @@ -251,6 +251,10 @@ impl CoreSurface for Window { fn rwh_06_display_handle(&self) -> &dyn rwh_06::HasDisplayHandle { self } + + fn as_window(&self) -> Option<&dyn CoreWindow> { + Some(self) + } } impl CoreWindow for Window { From 1301ea1cb3bf40f4efa499a4382f7d3981578ff6 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 23 Oct 2024 10:31:37 -0400 Subject: [PATCH 23/29] even more fixes to pass CI --- src/platform_impl/orbital/window.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 4c5b922331..bd96427764 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -193,6 +193,11 @@ impl CoreSurface for Window { None } + #[inline] + fn set_transparent(&self, transparent: bool) { + let _ = self.set_flag(ORBITAL_FLAG_TRANSPARENT, transparent); + } + #[inline] fn set_cursor(&self, _: Cursor) {} @@ -310,11 +315,6 @@ impl CoreWindow for Window { self.window_socket.write(format!("T,{title}").as_bytes()).expect("failed to set title"); } - #[inline] - fn set_transparent(&self, transparent: bool) { - let _ = self.set_flag(ORBITAL_FLAG_TRANSPARENT, transparent); - } - #[inline] fn set_blur(&self, _blur: bool) {} From f704c6866b5e18413770218909d58eba967725aa Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 23 Oct 2024 10:37:29 -0400 Subject: [PATCH 24/29] post-merge fixes --- src/platform/macos.rs | 6 +++--- src/platform_impl/linux/wayland/mod.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 977327d5e4..f90d8ced6f 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -78,7 +78,7 @@ use serde::{Deserialize, Serialize}; use crate::application::ApplicationHandler; use crate::event_loop::{ActiveEventLoop, EventLoopBuilder}; use crate::monitor::MonitorHandle; -use crate::window::{Window, WindowAttributes, WindowId}; +use crate::window::{Window, WindowAttributes, SurfaceId}; /// Additional methods on [`Window`] that are specific to MacOS. pub trait WindowExtMacOS { @@ -572,7 +572,7 @@ pub trait ApplicationHandlerExtMacOS: ApplicationHandler { /// fn standard_key_binding( /// &mut self, /// event_loop: &dyn ActiveEventLoop, - /// window_id: WindowId, + /// window_id: SurfaceId, /// action: &str, /// ) { /// match action { @@ -590,7 +590,7 @@ pub trait ApplicationHandlerExtMacOS: ApplicationHandler { fn standard_key_binding( &mut self, event_loop: &dyn ActiveEventLoop, - window_id: WindowId, + window_id: SurfaceId, action: &str, ) { let _ = event_loop; diff --git a/src/platform_impl/linux/wayland/mod.rs b/src/platform_impl/linux/wayland/mod.rs index 5aa0b4561a..b4fa0989f4 100644 --- a/src/platform_impl/linux/wayland/mod.rs +++ b/src/platform_impl/linux/wayland/mod.rs @@ -27,7 +27,7 @@ impl FingerId { } } -/// Get the WindowId out of the surface. +/// Get the SurfaceId out of the surface. #[inline] fn make_wid(surface: &WlSurface) -> SurfaceId { SurfaceId::from_raw(surface.id().as_ptr() as usize) From ac97e65aaea09d8111fb77fed40b92e80c211a0f Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 23 Oct 2024 14:35:55 -0400 Subject: [PATCH 25/29] remove a few remaining instances of WindowId --- examples/window.rs | 2 +- src/platform/macos.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/window.rs b/examples/window.rs index af1a059742..09e2e6d87a 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -566,7 +566,7 @@ impl ApplicationHandlerExtMacOS for Application { fn standard_key_binding( &mut self, _event_loop: &dyn ActiveEventLoop, - window_id: WindowId, + window_id: SurfaceId, action: &str, ) { info!(?window_id, ?action, "macOS standard key binding"); diff --git a/src/platform/macos.rs b/src/platform/macos.rs index f90d8ced6f..976cbf7a17 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -127,7 +127,7 @@ pub trait WindowExtMacOS { /// # Examples /// /// ```ignore - /// WindowEvent::CloseRequested => { + /// SurfaceEvent::CloseRequested => { /// if window.is_document_edited() { /// // Show the user a save pop-up or similar /// } else { From 918ddf689c9db71beb8d0c0307e649ab70d12605 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 23 Oct 2024 14:48:19 -0400 Subject: [PATCH 26/29] cargo fmt --- examples/child_window.rs | 2 +- examples/control_flow.rs | 2 +- examples/pump_events.rs | 2 +- examples/run_on_demand.rs | 2 +- examples/util/fill.rs | 2 +- examples/window.rs | 2 +- examples/x11_embed.rs | 2 +- src/event.rs | 2 +- src/platform/macos.rs | 2 +- src/platform_impl/android/mod.rs | 5 ++--- src/platform_impl/apple/appkit/view.rs | 2 +- src/platform_impl/apple/appkit/window.rs | 6 +++--- src/platform_impl/apple/appkit/window_delegate.rs | 6 +++--- src/platform_impl/apple/uikit/app_state.rs | 2 +- src/platform_impl/apple/uikit/view.rs | 2 +- src/platform_impl/apple/uikit/window.rs | 5 ++--- src/platform_impl/linux/wayland/event_loop/mod.rs | 2 +- src/platform_impl/linux/wayland/seat/pointer/mod.rs | 4 ++-- src/platform_impl/linux/wayland/window/mod.rs | 6 +++--- src/platform_impl/linux/wayland/window/state.rs | 2 +- src/platform_impl/linux/x11/event_processor.rs | 13 ++++++++----- src/platform_impl/linux/x11/mod.rs | 7 ++++--- src/platform_impl/linux/x11/window.rs | 12 +++++------- src/platform_impl/orbital/event_loop.rs | 5 +++-- src/platform_impl/orbital/window.rs | 7 ++++--- src/platform_impl/web/event_loop/window_target.rs | 11 +++++------ src/platform_impl/web/web_sys/canvas.rs | 2 +- src/platform_impl/web/window.rs | 2 -- src/platform_impl/windows/event_loop.rs | 8 ++++---- src/platform_impl/windows/event_loop/runner.rs | 2 +- src/platform_impl/windows/window.rs | 6 +++--- 31 files changed, 67 insertions(+), 68 deletions(-) diff --git a/examples/child_window.rs b/examples/child_window.rs index cffadea43e..0f20332680 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -8,7 +8,7 @@ fn main() -> Result<(), impl std::error::Error> { use winit::event::{ElementState, KeyEvent, SurfaceEvent}; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::raw_window_handle::HasRawWindowHandle; - use winit::window::{Window, WindowAttributes, SurfaceId}; + use winit::window::{SurfaceId, Window, WindowAttributes}; #[path = "util/fill.rs"] mod fill; diff --git a/examples/control_flow.rs b/examples/control_flow.rs index 6b8781f552..935efab1ce 100644 --- a/examples/control_flow.rs +++ b/examples/control_flow.rs @@ -11,7 +11,7 @@ use winit::application::ApplicationHandler; use winit::event::{ElementState, KeyEvent, StartCause, SurfaceEvent}; use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; use winit::keyboard::{Key, NamedKey}; -use winit::window::{Window, WindowAttributes, SurfaceId}; +use winit::window::{SurfaceId, Window, WindowAttributes}; #[path = "util/fill.rs"] mod fill; diff --git a/examples/pump_events.rs b/examples/pump_events.rs index ec18bdbe46..2a570bcc28 100644 --- a/examples/pump_events.rs +++ b/examples/pump_events.rs @@ -11,7 +11,7 @@ fn main() -> std::process::ExitCode { use winit::event::SurfaceEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::platform::pump_events::{EventLoopExtPumpEvents, PumpStatus}; - use winit::window::{Window, WindowAttributes, SurfaceId}; + use winit::window::{SurfaceId, Window, WindowAttributes}; #[path = "util/fill.rs"] mod fill; diff --git a/examples/run_on_demand.rs b/examples/run_on_demand.rs index d17e1672a7..97e31fd9bd 100644 --- a/examples/run_on_demand.rs +++ b/examples/run_on_demand.rs @@ -9,7 +9,7 @@ fn main() -> Result<(), Box> { use winit::event::SurfaceEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::platform::run_on_demand::EventLoopExtRunOnDemand; - use winit::window::{Window, WindowAttributes, SurfaceId}; + use winit::window::{SurfaceId, Window, WindowAttributes}; #[path = "util/fill.rs"] mod fill; diff --git a/examples/util/fill.rs b/examples/util/fill.rs index 6c8d8da0c6..8235aa807e 100644 --- a/examples/util/fill.rs +++ b/examples/util/fill.rs @@ -20,7 +20,7 @@ mod platform { use std::num::NonZeroU32; use softbuffer::{Context, Surface}; - use winit::window::{Window, SurfaceId}; + use winit::window::{SurfaceId, Window}; thread_local! { // NOTE: You should never do things like that, create context and drop it before diff --git a/examples/window.rs b/examples/window.rs index 09e2e6d87a..a7fb3bbc97 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -33,7 +33,7 @@ use winit::platform::startup_notify::{ use winit::platform::web::{ActiveEventLoopExtWeb, CustomCursorExtWeb, WindowAttributesExtWeb}; use winit::window::{ Cursor, CursorGrabMode, CustomCursor, CustomCursorSource, Fullscreen, Icon, ResizeDirection, - Theme, Window, WindowAttributes, SurfaceId, + SurfaceId, Theme, Window, WindowAttributes, }; #[path = "util/tracing.rs"] diff --git a/examples/x11_embed.rs b/examples/x11_embed.rs index bcf00a110d..7120b4c7ef 100644 --- a/examples/x11_embed.rs +++ b/examples/x11_embed.rs @@ -7,7 +7,7 @@ fn main() -> Result<(), Box> { use winit::event::SurfaceEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::platform::x11::WindowAttributesExtX11; - use winit::window::{Window, WindowAttributes, SurfaceId}; + use winit::window::{SurfaceId, Window, WindowAttributes}; #[path = "util/fill.rs"] mod fill; diff --git a/src/event.rs b/src/event.rs index f673e46f16..94dfae0768 100644 --- a/src/event.rs +++ b/src/event.rs @@ -50,9 +50,9 @@ use crate::error::RequestError; use crate::event_loop::AsyncRequestSerial; use crate::keyboard::{self, ModifiersKeyState, ModifiersKeys, ModifiersState}; use crate::platform_impl; +use crate::window::{ActivationToken, SurfaceId, Theme}; #[cfg(doc)] use crate::window::{Surface, Window}; -use crate::window::{ActivationToken, Theme, SurfaceId}; // TODO: Remove once the backends can call `ApplicationHandler` methods directly. For now backends // like Windows and Web require `Event` to wire user events, otherwise each backend will have to diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 976cbf7a17..3f18f56235 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -78,7 +78,7 @@ use serde::{Deserialize, Serialize}; use crate::application::ApplicationHandler; use crate::event_loop::{ActiveEventLoop, EventLoopBuilder}; use crate::monitor::MonitorHandle; -use crate::window::{Window, WindowAttributes, SurfaceId}; +use crate::window::{SurfaceId, Window, WindowAttributes}; /// Additional methods on [`Window`] that are specific to MacOS. pub trait WindowExtMacOS { diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index f60f74cfff..df61ddffe8 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -24,8 +24,8 @@ use crate::monitor::MonitorHandle as RootMonitorHandle; use crate::platform::pump_events::PumpStatus; use crate::window::{ self, CursorGrabMode, CustomCursor, CustomCursorSource, Fullscreen, ImePurpose, - ResizeDirection, Theme, Window as CoreWindow, WindowAttributes, WindowButtons, SurfaceId, - WindowLevel, Surface as CoreSurface + ResizeDirection, Surface as CoreSurface, SurfaceId, Theme, Window as CoreWindow, + WindowAttributes, WindowButtons, WindowLevel, }; mod keycodes; @@ -869,7 +869,6 @@ impl CoreSurface for Window { } impl CoreWindow for Window { - fn inner_position(&self) -> Result, RequestError> { Err(NotSupportedError::new("inner_position is not supported").into()) } diff --git a/src/platform_impl/apple/appkit/view.rs b/src/platform_impl/apple/appkit/view.rs index e1a0300692..f9a10a957b 100644 --- a/src/platform_impl/apple/appkit/view.rs +++ b/src/platform_impl/apple/appkit/view.rs @@ -27,7 +27,7 @@ use super::window::WinitWindow; use crate::dpi::{LogicalPosition, LogicalSize}; use crate::event::{ DeviceEvent, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, PointerKind, - PointerSource, TouchPhase, SurfaceEvent, + PointerSource, SurfaceEvent, TouchPhase, }; use crate::keyboard::{Key, KeyCode, KeyLocation, ModifiersState, NamedKey}; use crate::platform::macos::OptionAsAlt; diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index 72a06b5a40..64bea2cbdd 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -11,8 +11,8 @@ use super::window_delegate::WindowDelegate; use crate::error::RequestError; use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::window::{ - Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow, - WindowAttributes, WindowButtons, SurfaceId, WindowLevel, Surface as CoreSurface, + Cursor, Fullscreen, Icon, ImePurpose, Surface as CoreSurface, SurfaceId, Theme, + UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, WindowLevel, }; pub(crate) struct Window { @@ -118,7 +118,7 @@ impl CoreSurface for Window { fn set_transparent(&self, transparent: bool) { self.maybe_wait_on_main(|delegate| delegate.set_transparent(transparent)); } - + fn set_cursor(&self, cursor: Cursor) { self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor)); } diff --git a/src/platform_impl/apple/appkit/window_delegate.rs b/src/platform_impl/apple/appkit/window_delegate.rs index e50807dae7..d82b3932bd 100644 --- a/src/platform_impl/apple/appkit/window_delegate.rs +++ b/src/platform_impl/apple/appkit/window_delegate.rs @@ -36,11 +36,11 @@ use super::window::WinitWindow; use super::{ffi, Fullscreen, MonitorHandle}; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{SurfaceSizeWriter, SurfaceEvent}; +use crate::event::{SurfaceEvent, SurfaceSizeWriter}; use crate::platform::macos::{OptionAsAlt, WindowExtMacOS}; use crate::window::{ - Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, Theme, UserAttentionType, - WindowAttributes, WindowButtons, SurfaceId, WindowLevel, + Cursor, CursorGrabMode, Icon, ImePurpose, ResizeDirection, SurfaceId, Theme, UserAttentionType, + WindowAttributes, WindowButtons, WindowLevel, }; #[derive(Clone, Debug, PartialEq)] diff --git a/src/platform_impl/apple/uikit/app_state.rs b/src/platform_impl/apple/uikit/app_state.rs index 5776c1f0dc..a2b38c2752 100644 --- a/src/platform_impl/apple/uikit/app_state.rs +++ b/src/platform_impl/apple/uikit/app_state.rs @@ -27,7 +27,7 @@ use super::window::WinitUIWindow; use super::ActiveEventLoop; use crate::application::ApplicationHandler; use crate::dpi::PhysicalSize; -use crate::event::{Event, StartCause, SurfaceSizeWriter, SurfaceEvent}; +use crate::event::{Event, StartCause, SurfaceEvent, SurfaceSizeWriter}; use crate::event_loop::ControlFlow; macro_rules! bug { diff --git a/src/platform_impl/apple/uikit/view.rs b/src/platform_impl/apple/uikit/view.rs index 377fea562d..489c4eb1db 100644 --- a/src/platform_impl/apple/uikit/view.rs +++ b/src/platform_impl/apple/uikit/view.rs @@ -18,7 +18,7 @@ use super::FingerId; use crate::dpi::PhysicalPosition; use crate::event::{ ButtonSource, ElementState, Event, FingerId as RootFingerId, Force, KeyEvent, PointerKind, - PointerSource, TouchPhase, SurfaceEvent, + PointerSource, SurfaceEvent, TouchPhase, }; use crate::keyboard::{Key, KeyCode, KeyLocation, NamedKey, NativeKeyCode, PhysicalKey}; use crate::platform_impl::KeyEventExtra; diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index e01647269c..1db4bd500a 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -25,8 +25,8 @@ use crate::icon::Icon; use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations}; use crate::window::{ - CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow, - WindowAttributes, WindowButtons, SurfaceId, WindowLevel, Surface as CoreSurface + CursorGrabMode, ImePurpose, ResizeDirection, Surface as CoreSurface, SurfaceId, Theme, + UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, WindowLevel, }; declare_class!( @@ -668,7 +668,6 @@ impl CoreSurface for Window { } impl CoreWindow for Window { - fn reset_dead_keys(&self) { self.maybe_wait_on_main(|delegate| delegate.reset_dead_keys()); } diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index e153d02726..c76581558e 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -15,7 +15,7 @@ use crate::application::ApplicationHandler; use crate::cursor::OnlyCursorImage; use crate::dpi::LogicalSize; use crate::error::{EventLoopError, OsError, RequestError}; -use crate::event::{Event, StartCause, SurfaceSizeWriter, SurfaceEvent}; +use crate::event::{Event, StartCause, SurfaceEvent, SurfaceSizeWriter}; use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents}; use crate::platform::pump_events::PumpStatus; use crate::platform_impl::platform::min_timeout; diff --git a/src/platform_impl/linux/wayland/seat/pointer/mod.rs b/src/platform_impl/linux/wayland/seat/pointer/mod.rs index 661781feea..07bd8b0640 100644 --- a/src/platform_impl/linux/wayland/seat/pointer/mod.rs +++ b/src/platform_impl/linux/wayland/seat/pointer/mod.rs @@ -28,8 +28,8 @@ use sctk::seat::SeatState; use crate::dpi::{LogicalPosition, PhysicalPosition}; use crate::event::{ - ElementState, MouseButton, MouseScrollDelta, PointerKind, PointerSource, TouchPhase, - SurfaceEvent, + ElementState, MouseButton, MouseScrollDelta, PointerKind, PointerSource, SurfaceEvent, + TouchPhase, }; use crate::platform_impl::wayland::state::WinitState; diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 421c39f3b9..39ceadca24 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -25,8 +25,8 @@ use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::platform_impl::{Fullscreen, MonitorHandle as PlatformMonitorHandle}; use crate::window::{ Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, - Surface as CoreSurface, Theme, UserAttentionType, Window as CoreWindow, WindowAttributes, - WindowButtons, SurfaceId, WindowLevel, + Surface as CoreSurface, SurfaceId, Theme, UserAttentionType, Window as CoreWindow, + WindowAttributes, WindowButtons, WindowLevel, }; pub(crate) mod state; @@ -398,7 +398,7 @@ impl CoreSurface for Window { fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { self } - + fn as_window(&self) -> Option<&dyn CoreWindow> { Some(self) } diff --git a/src/platform_impl/linux/wayland/window/state.rs b/src/platform_impl/linux/wayland/window/state.rs index 303333f4ef..b81fa42bd8 100644 --- a/src/platform_impl/linux/wayland/window/state.rs +++ b/src/platform_impl/linux/wayland/window/state.rs @@ -39,7 +39,7 @@ use crate::platform_impl::wayland::state::{WindowCompositorUpdate, WinitState}; use crate::platform_impl::wayland::types::cursor::{CustomCursor, SelectedCursor}; use crate::platform_impl::wayland::types::kwin_blur::KWinBlurManager; use crate::platform_impl::PlatformCustomCursor; -use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, SurfaceId}; +use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, SurfaceId, Theme}; #[cfg(feature = "sctk-adwaita")] pub type WinitFrame = sctk_adwaita::AdwaitaFrame; diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index fc1d557378..28f511be53 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -23,7 +23,7 @@ use xkbcommon_dl::xkb_mod_mask_t; use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::event::{ ButtonSource, DeviceEvent, DeviceId, ElementState, Event, Ime, MouseButton, MouseScrollDelta, - PointerKind, PointerSource, RawKeyEvent, SurfaceSizeWriter, TouchPhase, SurfaceEvent, + PointerKind, PointerSource, RawKeyEvent, SurfaceEvent, SurfaceSizeWriter, TouchPhase, }; use crate::keyboard::ModifiersState; use crate::platform_impl::common::xkb::{self, XkbState}; @@ -34,7 +34,7 @@ use crate::platform_impl::x11::atoms::*; use crate::platform_impl::x11::util::cookie::GenericEventCookie; use crate::platform_impl::x11::{ mkdid, mkfid, mkwid, util, CookieResultExt, Device, DeviceInfo, Dnd, DndState, ImeReceiver, - ScrollOrientation, UnownedWindow, SurfaceId, + ScrollOrientation, SurfaceId, UnownedWindow, }; /// The maximum amount of X modifiers to replay. @@ -548,7 +548,8 @@ impl EventProcessor { if xev.message_type == atoms[XdndLeave] as c_ulong { self.dnd.reset(); - let event = Event::SurfaceEvent { window_id, event: SurfaceEvent::HoveredFileCancelled }; + let event = + Event::SurfaceEvent { window_id, event: SurfaceEvent::HoveredFileCancelled }; callback(&self.target, event); } } @@ -981,8 +982,10 @@ impl EventProcessor { }; callback(&self.target, event); - let event = - Event::SurfaceEvent { window_id, event: SurfaceEvent::Ime(Ime::Commit(written)) }; + let event = Event::SurfaceEvent { + window_id, + event: SurfaceEvent::Ime(Ime::Commit(written)), + }; self.is_composing = false; callback(&self.target, event); diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 61609eb0e0..8b2639a0d9 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -35,8 +35,8 @@ use crate::platform_impl::platform::min_timeout; use crate::platform_impl::x11::window::Window; use crate::platform_impl::{OwnedDisplayHandle, PlatformCustomCursor}; use crate::window::{ - CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, - WindowAttributes, SurfaceId, + CustomCursor as RootCustomCursor, CustomCursorSource, SurfaceId, Theme, Window as CoreWindow, + WindowAttributes, }; mod activation; @@ -574,7 +574,8 @@ impl EventLoop { while unsafe { self.event_processor.poll_one_event(xev.as_mut_ptr()) } { let mut xev = unsafe { xev.assume_init() }; self.event_processor.process_event(&mut xev, |window_target, event: Event| { - if let Event::SurfaceEvent { window_id, event: SurfaceEvent::RedrawRequested } = event + if let Event::SurfaceEvent { window_id, event: SurfaceEvent::RedrawRequested } = + event { window_target.redraw_sender.send(window_id); } else { diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index d5bb7ca213..e8fdec9648 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -23,7 +23,7 @@ use super::{ use crate::cursor::{Cursor, CustomCursor as RootCustomCursor}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{Event, SurfaceSizeWriter, SurfaceEvent}; +use crate::event::{Event, SurfaceEvent, SurfaceSizeWriter}; use crate::event_loop::AsyncRequestSerial; use crate::platform::x11::WindowType; use crate::platform_impl::x11::atoms::*; @@ -35,8 +35,8 @@ use crate::platform_impl::{ VideoModeHandle as PlatformVideoModeHandle, }; use crate::window::{ - CursorGrabMode, ImePurpose, ResizeDirection, Surface as CoreSurface, Theme, UserAttentionType, - Window as CoreWindow, WindowAttributes, WindowButtons, SurfaceId, WindowLevel, + CursorGrabMode, ImePurpose, ResizeDirection, Surface as CoreSurface, SurfaceId, Theme, + UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, WindowLevel, }; pub(crate) struct Window(Arc); @@ -109,7 +109,7 @@ impl CoreSurface for Window { fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> { self.0.set_cursor_hittest(hittest) } - + fn current_monitor(&self) -> Option { self.0 .current_monitor() @@ -143,7 +143,7 @@ impl CoreSurface for Window { fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { self } - + fn as_window(&self) -> Option<&dyn CoreWindow> { Some(self) } @@ -309,8 +309,6 @@ impl CoreWindow for Window { fn show_window_menu(&self, position: Position) { self.0.show_window_menu(position); } - - } #[cfg(feature = "rwh_06")] diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 7ebb27c706..fef6b1a38a 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -25,7 +25,7 @@ use crate::keyboard::{ }; use crate::platform_impl::Window; use crate::window::{ - CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, SurfaceId, + CustomCursor as RootCustomCursor, CustomCursorSource, SurfaceId, Theme, Window as CoreWindow, }; fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { @@ -514,7 +514,8 @@ impl EventLoop { self.windows.push((window, EventState::default())); // Send resize event on create to indicate first size. - let event = event::SurfaceEvent::SurfaceResized((properties.w, properties.h).into()); + let event = + event::SurfaceEvent::SurfaceResized((properties.w, properties.h).into()); app.window_event(&self.window_target, window_id, event); // Send moved event on create to indicate first position. diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index bd96427764..45533740a2 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -6,7 +6,9 @@ use crate::cursor::Cursor; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::error::{NotSupportedError, RequestError}; use crate::monitor::MonitorHandle as CoreMonitorHandle; -use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, Surface as CoreSurface, SurfaceId}; +use crate::window::{ + self, Fullscreen, ImePurpose, Surface as CoreSurface, SurfaceId, Window as CoreWindow, +}; // These values match the values uses in the `window_new` function in orbital: // https://gitlab.redox-os.org/redox-os/orbital/-/blob/master/src/scheme.rs @@ -246,7 +248,7 @@ impl CoreSurface for Window { fn current_monitor(&self) -> Option { Some(CoreMonitorHandle { inner: MonitorHandle }) } - + #[cfg(feature = "rwh_06")] fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle { self @@ -263,7 +265,6 @@ impl CoreSurface for Window { } impl CoreWindow for Window { - #[inline] fn reset_dead_keys(&self) { // TODO? diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index c799e9d13c..8b72905ef3 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -10,7 +10,7 @@ use super::super::{lock, KeyEventExtra}; use super::runner::{EventWrapper, WeakShared}; use super::{backend, runner, EventLoopProxy}; use crate::error::{NotSupportedError, RequestError}; -use crate::event::{ElementState, Event, KeyEvent, TouchPhase, SurfaceEvent}; +use crate::event::{ElementState, Event, KeyEvent, SurfaceEvent, TouchPhase}; use crate::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopProxy as RootEventLoopProxy, OwnedDisplayHandle as RootOwnedDisplayHandle, @@ -21,7 +21,7 @@ use crate::platform::web::{CustomCursorFuture, PollStrategy, WaitUntilStrategy}; use crate::platform_impl::platform::cursor::CustomCursor; use crate::platform_impl::platform::r#async::Waker; use crate::platform_impl::Window; -use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, Theme, SurfaceId}; +use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, SurfaceId, Theme}; #[derive(Default)] struct ModifiersShared(Rc>); @@ -89,10 +89,9 @@ impl ActiveEventLoop { } }); - runner.send_events(clear_modifiers.into_iter().chain(iter::once(Event::SurfaceEvent { - window_id, - event: SurfaceEvent::Focused(false), - }))); + runner.send_events(clear_modifiers.into_iter().chain(iter::once( + Event::SurfaceEvent { window_id, event: SurfaceEvent::Focused(false) }, + ))); }); let runner = self.runner.clone(); diff --git a/src/platform_impl/web/web_sys/canvas.rs b/src/platform_impl/web/web_sys/canvas.rs index 80c36bfccf..7d8e151058 100644 --- a/src/platform_impl/web/web_sys/canvas.rs +++ b/src/platform_impl/web/web_sys/canvas.rs @@ -27,7 +27,7 @@ use crate::event::{ }; use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey}; use crate::platform_impl::Fullscreen; -use crate::window::{WindowAttributes, SurfaceId}; +use crate::window::{SurfaceId, WindowAttributes}; #[allow(dead_code)] pub struct Canvas { diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index ac6884a2af..d4c5fb628d 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -191,8 +191,6 @@ impl RootSurface for Window { } impl RootWindow for Window { - - fn reset_dead_keys(&self) { // Not supported } diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 2e88a1e364..bc7231a01c 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -58,8 +58,8 @@ use crate::application::ApplicationHandler; use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::error::{EventLoopError, RequestError}; use crate::event::{ - Event, FingerId as RootFingerId, Force, Ime, RawKeyEvent, SurfaceSizeWriter, TouchPhase, - SurfaceEvent, + Event, FingerId as RootFingerId, Force, Ime, RawKeyEvent, SurfaceEvent, SurfaceSizeWriter, + TouchPhase, }; use crate::event_loop::{ ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, @@ -84,8 +84,8 @@ use crate::platform_impl::platform::{raw_input, util, wrap_device_id, FingerId, use crate::platform_impl::Window; use crate::utils::Lazy; use crate::window::{ - CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, - WindowAttributes, SurfaceId, + CustomCursor as RootCustomCursor, CustomCursorSource, SurfaceId, Theme, Window as CoreWindow, + WindowAttributes, }; pub(crate) struct WindowData { diff --git a/src/platform_impl/windows/event_loop/runner.rs b/src/platform_impl/windows/event_loop/runner.rs index dbe142b2c7..eff74cf612 100644 --- a/src/platform_impl/windows/event_loop/runner.rs +++ b/src/platform_impl/windows/event_loop/runner.rs @@ -9,7 +9,7 @@ use windows_sys::Win32::Foundation::HWND; use super::ControlFlow; use crate::dpi::PhysicalSize; -use crate::event::{Event, StartCause, SurfaceSizeWriter, SurfaceEvent}; +use crate::event::{Event, StartCause, SurfaceEvent, SurfaceSizeWriter}; use crate::platform_impl::platform::event_loop::{WindowData, GWL_USERDATA}; use crate::platform_impl::platform::get_window_long; use crate::window::SurfaceId; diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index bb896ba747..0bd750edd9 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -68,9 +68,9 @@ use crate::platform_impl::platform::window_state::{ }; use crate::platform_impl::platform::{monitor, util, Fullscreen, SelectedCursor}; use crate::window::{ - CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme, - UserAttentionType, Window as CoreWindow, Surface as CoreSurface, WindowAttributes, WindowButtons, SurfaceId, - WindowLevel, + CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, + Surface as CoreSurface, SurfaceId, Theme, UserAttentionType, Window as CoreWindow, + WindowAttributes, WindowButtons, WindowLevel, }; /// The Win32 implementation of the main `Window` object. From a88dac30ad534746e7413a8b3670f42f5429d095 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 23 Oct 2024 17:42:12 -0400 Subject: [PATCH 27/29] improve changelog entry --- src/changelog/unreleased.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 4e4c85645f..e348a67a26 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -68,7 +68,7 @@ changelog entry. - Add `PointerKind`, `PointerSource`, `ButtonSource`, `FingerId` and `position` to all pointer events as part of the pointer event overhaul. - Add `DeviceId::into_raw()` and `from_raw()`. -- Add the `Surface` trait to represent a generic drawable area. +- Add the `Surface` trait to represent a generic window. ### Changed @@ -153,10 +153,11 @@ changelog entry. the primary finger in a multi-touch interaction. - In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`. - Remove `Force::Calibrated::altitude_angle`. -- Various window-related things are renamed to account for the fact they work with all surfaces. - - Rename `WindowId` to `SurfaceId`. - - Rename `WindowEvent` to `SurfaceEvent`. - - Rename `Event::WindowEvent` to `Event::SurfaceEvent`. +- Changed `Window` to be a subtrait of `Surface`; it now contains methods specific to toplevel windows. +- Renamed structs previously associated with `Window`s, since they now apply to all `Surface`s: + - `WindowId` to `SurfaceId` + - `WindowEvent` to `SurfaceEvent` + - `Event::WindowEvent` to `Event::SurfaceEvent` ### Removed From ddde87007b73ff960725a7c7f3832b4ef9a40245 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Wed, 23 Oct 2024 20:59:54 -0400 Subject: [PATCH 28/29] cargo +nightly fmt --- src/application.rs | 3 +- src/platform_impl/apple/appkit/app.rs | 26 +++++----- src/platform_impl/linux/x11/dnd.rs | 28 +++++------ .../linux/x11/event_processor.rs | 47 +++++++------------ src/platform_impl/linux/x11/mod.rs | 19 ++++---- src/platform_impl/linux/x11/util/input.rs | 8 ++-- src/platform_impl/orbital/event_loop.rs | 36 +++++--------- src/platform_impl/windows/window_state.rs | 22 ++++----- src/window.rs | 7 +-- 9 files changed, 81 insertions(+), 115 deletions(-) diff --git a/src/application.rs b/src/application.rs index 77424b077f..f8b781cbbf 100644 --- a/src/application.rs +++ b/src/application.rs @@ -2,10 +2,9 @@ use crate::event::{DeviceEvent, DeviceId, StartCause, SurfaceEvent}; use crate::event_loop::ActiveEventLoop; -use crate::window::SurfaceId; - #[cfg(any(docsrs, macos_platform))] use crate::platform::macos::ApplicationHandlerExtMacOS; +use crate::window::SurfaceId; /// The handler of the application events. pub trait ApplicationHandler { diff --git a/src/platform_impl/apple/appkit/app.rs b/src/platform_impl/apple/appkit/app.rs index f214ee191e..747a17b4c5 100644 --- a/src/platform_impl/apple/appkit/app.rs +++ b/src/platform_impl/apple/appkit/app.rs @@ -60,32 +60,28 @@ fn maybe_dispatch_device_event(app_state: &Rc, event: &NSEvent) { if delta_x != 0.0 || delta_y != 0.0 { app_state.maybe_queue_with_handler(move |app, event_loop| { - app.device_event( - event_loop, - None, - DeviceEvent::PointerMotion { delta: (delta_x, delta_y) }, - ); + app.device_event(event_loop, None, DeviceEvent::PointerMotion { + delta: (delta_x, delta_y), + }); }); } }, NSEventType::LeftMouseDown | NSEventType::RightMouseDown | NSEventType::OtherMouseDown => { let button = unsafe { event.buttonNumber() } as u32; app_state.maybe_queue_with_handler(move |app, event_loop| { - app.device_event( - event_loop, - None, - DeviceEvent::Button { button, state: ElementState::Pressed }, - ); + app.device_event(event_loop, None, DeviceEvent::Button { + button, + state: ElementState::Pressed, + }); }); }, NSEventType::LeftMouseUp | NSEventType::RightMouseUp | NSEventType::OtherMouseUp => { let button = unsafe { event.buttonNumber() } as u32; app_state.maybe_queue_with_handler(move |app, event_loop| { - app.device_event( - event_loop, - None, - DeviceEvent::Button { button, state: ElementState::Released }, - ); + app.device_event(event_loop, None, DeviceEvent::Button { + button, + state: ElementState::Released, + }); }); }, _ => (), diff --git a/src/platform_impl/linux/x11/dnd.rs b/src/platform_impl/linux/x11/dnd.rs index ac79b5be5f..691e40af9b 100644 --- a/src/platform_impl/linux/x11/dnd.rs +++ b/src/platform_impl/linux/x11/dnd.rs @@ -73,13 +73,13 @@ impl Dnd { DndState::Rejected => (0, atoms[DndNone]), }; self.xconn - .send_client_msg( - target_window, - target_window, - atoms[XdndStatus] as _, - None, - [this_window, accepted, 0, 0, action as _], - )? + .send_client_msg(target_window, target_window, atoms[XdndStatus] as _, None, [ + this_window, + accepted, + 0, + 0, + action as _, + ])? .ignore_error(); Ok(()) @@ -97,13 +97,13 @@ impl Dnd { DndState::Rejected => (0, atoms[DndNone]), }; self.xconn - .send_client_msg( - target_window, - target_window, - atoms[XdndFinished] as _, - None, - [this_window, accepted, action as _, 0, 0], - )? + .send_client_msg(target_window, target_window, atoms[XdndFinished] as _, None, [ + this_window, + accepted, + action as _, + 0, + 0, + ])? .ignore_error(); Ok(()) diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 28f511be53..48e8149235 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -658,10 +658,10 @@ impl EventProcessor { drop(shared_state_lock); if moved { - callback( - &self.target, - Event::SurfaceEvent { window_id, event: SurfaceEvent::Moved(outer.into()) }, - ); + callback(&self.target, Event::SurfaceEvent { + window_id, + event: SurfaceEvent::Moved(outer.into()), + }); } outer }; @@ -707,18 +707,13 @@ impl EventProcessor { drop(shared_state_lock); let surface_size = Arc::new(Mutex::new(new_surface_size)); - callback( - &self.target, - Event::SurfaceEvent { - window_id, - event: SurfaceEvent::ScaleFactorChanged { - scale_factor: new_scale_factor, - surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade( - &surface_size, - )), - }, + callback(&self.target, Event::SurfaceEvent { + window_id, + event: SurfaceEvent::ScaleFactorChanged { + scale_factor: new_scale_factor, + surface_size_writer: SurfaceSizeWriter::new(Arc::downgrade(&surface_size)), }, - ); + }); let new_surface_size = *surface_size.lock().unwrap(); drop(surface_size); @@ -768,13 +763,10 @@ impl EventProcessor { } if resized { - callback( - &self.target, - Event::SurfaceEvent { - window_id, - event: SurfaceEvent::SurfaceResized(new_surface_size.into()), - }, - ); + callback(&self.target, Event::SurfaceEvent { + window_id, + event: SurfaceEvent::SurfaceResized(new_surface_size.into()), + }); } } @@ -1527,13 +1519,10 @@ impl EventProcessor { } let physical_key = xkb::raw_keycode_to_physicalkey(keycode); - callback( - &self.target, - Event::DeviceEvent { - device_id, - event: DeviceEvent::Key(RawKeyEvent { physical_key, state }), - }, - ); + callback(&self.target, Event::DeviceEvent { + device_id, + event: DeviceEvent::Key(RawKeyEvent { physical_key, state }), + }); } fn xinput2_hierarchy_changed(&mut self, xev: &XIHierarchyEvent) { diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 8b2639a0d9..e48c8c4aeb 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -1032,18 +1032,15 @@ impl Device { let ty = unsafe { (*class_ptr)._type }; if ty == ffi::XIScrollClass { let info = unsafe { &*(class_ptr as *const ffi::XIScrollClassInfo) }; - scroll_axes.push(( - info.number, - ScrollAxis { - increment: info.increment, - orientation: match info.scroll_type { - ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal, - ffi::XIScrollTypeVertical => ScrollOrientation::Vertical, - _ => unreachable!(), - }, - position: 0.0, + scroll_axes.push((info.number, ScrollAxis { + increment: info.increment, + orientation: match info.scroll_type { + ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal, + ffi::XIScrollTypeVertical => ScrollOrientation::Vertical, + _ => unreachable!(), }, - )); + position: 0.0, + })); } } } diff --git a/src/platform_impl/linux/x11/util/input.rs b/src/platform_impl/linux/x11/util/input.rs index b4f441436b..12a69bd0c7 100644 --- a/src/platform_impl/linux/x11/util/input.rs +++ b/src/platform_impl/linux/x11/util/input.rs @@ -20,10 +20,10 @@ impl XConnection { mask: xinput::XIEventMask, ) -> Result, X11Error> { self.xcb_connection() - .xinput_xi_select_events( - window, - &[xinput::EventMask { deviceid: device_id, mask: vec![mask] }], - ) + .xinput_xi_select_events(window, &[xinput::EventMask { + deviceid: device_id, + mask: vec![mask], + }]) .map_err(Into::into) } diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index fef6b1a38a..1e5f67b827 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -402,22 +402,16 @@ impl EventLoop { ); }, EventOption::Mouse(MouseEvent { x, y }) => { - app.window_event( - window_target, - window_id, - event::SurfaceEvent::PointerMoved { - device_id: None, - position: (x, y).into(), - source: event::PointerSource::Mouse, - }, - ); + app.window_event(window_target, window_id, event::SurfaceEvent::PointerMoved { + device_id: None, + position: (x, y).into(), + source: event::PointerSource::Mouse, + }); }, EventOption::MouseRelative(MouseRelativeEvent { dx, dy }) => { - app.device_event( - window_target, - None, - event::DeviceEvent::PointerMotion { delta: (dx as f64, dy as f64) }, - ); + app.device_event(window_target, None, event::DeviceEvent::PointerMotion { + delta: (dx as f64, dy as f64), + }); }, EventOption::Button(ButtonEvent { left, middle, right }) => { while let Some((button, state)) = event_state.mouse(left, middle, right) { @@ -434,15 +428,11 @@ impl EventLoop { } }, EventOption::Scroll(ScrollEvent { x, y }) => { - app.window_event( - window_target, - window_id, - event::SurfaceEvent::MouseWheel { - device_id: None, - delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32), - phase: event::TouchPhase::Moved, - }, - ); + app.window_event(window_target, window_id, event::SurfaceEvent::MouseWheel { + device_id: None, + delta: event::MouseScrollDelta::LineDelta(x as f32, y as f32), + phase: event::TouchPhase::Moved, + }); }, EventOption::Quit(QuitEvent {}) => { app.window_event(window_target, window_id, event::SurfaceEvent::CloseRequested); diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index f197a1b239..f84dd2cfdb 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -362,26 +362,20 @@ impl WindowFlags { if diff.contains(WindowFlags::MAXIMIZED) || new.contains(WindowFlags::MAXIMIZED) { unsafe { - ShowWindow( - window, - match new.contains(WindowFlags::MAXIMIZED) { - true => SW_MAXIMIZE, - false => SW_RESTORE, - }, - ); + ShowWindow(window, match new.contains(WindowFlags::MAXIMIZED) { + true => SW_MAXIMIZE, + false => SW_RESTORE, + }); } } // Minimize operations should execute after maximize for proper window animations if diff.contains(WindowFlags::MINIMIZED) { unsafe { - ShowWindow( - window, - match new.contains(WindowFlags::MINIMIZED) { - true => SW_MINIMIZE, - false => SW_RESTORE, - }, - ); + ShowWindow(window, match new.contains(WindowFlags::MINIMIZED) { + true => SW_MINIMIZE, + false => SW_RESTORE, + }); } diff.remove(WindowFlags::MINIMIZED); diff --git a/src/window.rs b/src/window.rs index 12fbf29270..09776a724b 100644 --- a/src/window.rs +++ b/src/window.rs @@ -505,8 +505,8 @@ pub trait Surface: AsAny + Send + Sync { /// [`contentScaleFactor`]: https://developer.apple.com/documentation/uikit/uiview/1622657-contentscalefactor?language=objc fn scale_factor(&self) -> f64; - /// Queues a [`SurfaceEvent::RedrawRequested`] event to be emitted that aligns with the windowing - /// system drawing loop. + /// Queues a [`SurfaceEvent::RedrawRequested`] event to be emitted that aligns with the + /// windowing system drawing loop. /// /// This is the **strongly encouraged** method of redrawing windows, as it can integrate with /// OS-requested redraws (e.g. when a window gets resized). To improve the event delivery @@ -758,7 +758,8 @@ pub trait Surface: AsAny + Send + Sync { #[cfg(feature = "rwh_06")] fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle; - /// Tries to downcast this surface to a [`Window`]. Returns `None` if the surface is not a window. + /// Tries to downcast this surface to a [`Window`]. Returns `None` if the surface is not a + /// window. fn as_window(&self) -> Option<&dyn Window> { None } From be6b958a6208c3e8f6db631d0a7b78d0935910f9 Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Thu, 24 Oct 2024 11:08:38 -0400 Subject: [PATCH 29/29] mark the renaming types stuff as breaking in the changelog --- src/changelog/unreleased.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index e348a67a26..fd87901f0a 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -154,7 +154,7 @@ changelog entry. - In the same spirit rename `DeviceEvent::MouseMotion` to `PointerMotion`. - Remove `Force::Calibrated::altitude_angle`. - Changed `Window` to be a subtrait of `Surface`; it now contains methods specific to toplevel windows. -- Renamed structs previously associated with `Window`s, since they now apply to all `Surface`s: +- **Breaking:** Renamed structs previously associated with `Window`s, since they now apply to all `Surface`s: - `WindowId` to `SurfaceId` - `WindowEvent` to `SurfaceEvent` - `Event::WindowEvent` to `Event::SurfaceEvent`