diff --git a/winit-android/src/event_loop.rs b/winit-android/src/event_loop.rs index 62895a34d2..571a111582 100644 --- a/winit-android/src/event_loop.rs +++ b/winit-android/src/event_loop.rs @@ -6,9 +6,7 @@ use std::sync::{Arc, Mutex}; use std::time::{Duration, Instant}; use android_activity::input::{InputEvent, KeyAction, Keycode, MotionAction}; -use android_activity::{ - AndroidApp, AndroidAppWaker, ConfigurationRef, InputStatus, MainEvent, Rect, -}; +use android_activity::{AndroidApp, AndroidAppWaker, ConfigurationRef, InputStatus, MainEvent}; use dpi::{PhysicalInsets, PhysicalPosition, PhysicalSize, Position, Size}; use tracing::{debug, trace, warn}; use winit_core::application::ApplicationHandler; @@ -193,9 +191,7 @@ impl EventLoop { }, MainEvent::WindowResized { .. } => resized = true, MainEvent::RedrawNeeded { .. } => pending_redraw = true, - MainEvent::ContentRectChanged { .. } => { - warn!("TODO: find a way to notify application of content rect change"); - }, + MainEvent::ContentRectChanged { .. } => pending_redraw = true, MainEvent::GainedFocus => { HAS_FOCUS.store(true, Ordering::Relaxed); let event = event::WindowEvent::Focused(true); @@ -784,10 +780,6 @@ impl Window { self.app.config() } - pub(crate) fn content_rect(&self) -> Rect { - self.app.content_rect() - } - // Allow the usage of HasRawWindowHandle inside this function #[allow(deprecated)] fn raw_window_handle_rwh_06(&self) -> Result { @@ -852,7 +844,7 @@ impl CoreWindow for Window { fn pre_present_notify(&self) {} fn surface_position(&self) -> PhysicalPosition { - (0, 0).into() + (0.0, 0.0).into() } fn outer_position(&self) -> Result, RequestError> { @@ -876,7 +868,14 @@ impl CoreWindow for Window { } fn safe_area(&self) -> PhysicalInsets { - PhysicalInsets::new(0, 0, 0, 0) + let insets = self.app.content_rect(); + let outer_size = self.outer_size(); + PhysicalInsets { + top: insets.top as u32, + left: insets.left as u32, + bottom: outer_size.height.saturating_sub(insets.bottom as u32), + right: outer_size.width.saturating_sub(insets.right as u32), + } } fn set_min_surface_size(&self, _: Option) {} diff --git a/winit-android/src/lib.rs b/winit-android/src/lib.rs index 989c9716df..90b24673d0 100644 --- a/winit-android/src/lib.rs +++ b/winit-android/src/lib.rs @@ -77,7 +77,7 @@ mod keycodes; use winit_core::event_loop::ActiveEventLoop as CoreActiveEventLoop; use winit_core::window::Window as CoreWindow; -use self::activity::{AndroidApp, ConfigurationRef, Rect}; +use self::activity::{AndroidApp, ConfigurationRef}; pub use crate::event_loop::{ ActiveEventLoop, EventLoop, EventLoopProxy, PlatformSpecificEventLoopAttributes, PlatformSpecificWindowAttributes, Window, @@ -97,17 +97,10 @@ pub trait ActiveEventLoopExtAndroid { /// Additional methods on [`Window`] that are specific to Android. pub trait WindowExtAndroid { - fn content_rect(&self) -> Rect; - fn config(&self) -> ConfigurationRef; } impl WindowExtAndroid for dyn CoreWindow + '_ { - fn content_rect(&self) -> Rect { - let window = self.cast_ref::().unwrap(); - window.content_rect() - } - fn config(&self) -> ConfigurationRef { let window = self.cast_ref::().unwrap(); window.config() diff --git a/winit-core/src/window.rs b/winit-core/src/window.rs index 6f564ba900..9e8ab971e3 100644 --- a/winit-core/src/window.rs +++ b/winit-core/src/window.rs @@ -768,7 +768,7 @@ pub trait Window: AsAny + Send + Sync + fmt::Debug { /// /// ## Platform-specific /// - /// - **Android / Orbital / Wayland / Windows / X11:** Unimplemented, returns `(0, 0, 0, 0)`. + /// - **Orbital / Wayland / Windows / X11:** Unimplemented, returns `(0, 0, 0, 0)`. /// /// ## Example /// diff --git a/winit/src/changelog/unreleased.md b/winit/src/changelog/unreleased.md index 1a41586444..76e4f27169 100644 --- a/winit/src/changelog/unreleased.md +++ b/winit/src/changelog/unreleased.md @@ -44,6 +44,7 @@ changelog entry. - Add `keyboard` support for OpenHarmony. - On iOS, add Apple Pencil support with force, altitude, and azimuth data. +- On Android, implement `Window::safe_area`. This replaces `WindowExtAndroid::content_rect` which has been removed. ### Changed