Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions winit-android/src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be resized = true? That'd better match what we (somewhat) guarantee on macOS (that changes to the safe area trigger a resize event).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely could do a resize event. I want to react to "safe area" changes very differently to surface resizes (notably, I don't want to resize the underlying texture, because at least on Android I still want to render a background color into the safe area). But I could implement this using an equality check on the "surface size" and "safe area" in the resize handler.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll want #4507, but for now the behavior we have on iOS and macOS is to emit a resize event so let's match that on Android too.

(To be clear, the resize will still contain the surface size as before, it's just a signal to the app to update other things that depend on the safe area, I know Alacritty relies on it).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait nvmd, iOS only requests a redraw. So I'm fine with only doing that here too.

MainEvent::GainedFocus => {
HAS_FOCUS.store(true, Ordering::Relaxed);
let event = event::WindowEvent::Focused(true);
Expand Down Expand Up @@ -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<rwh_06::RawWindowHandle, rwh_06::HandleError> {
Expand Down Expand Up @@ -852,7 +844,7 @@ impl CoreWindow for Window {
fn pre_present_notify(&self) {}

fn surface_position(&self) -> PhysicalPosition<i32> {
(0, 0).into()
(0.0, 0.0).into()
}

fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
Expand All @@ -876,7 +868,14 @@ impl CoreWindow for Window {
}

fn safe_area(&self) -> PhysicalInsets<u32> {
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<Size>) {}
Expand Down
9 changes: 1 addition & 8 deletions winit-android/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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::<Window>().unwrap();
window.content_rect()
}

fn config(&self) -> ConfigurationRef {
let window = self.cast_ref::<Window>().unwrap();
window.config()
Expand Down
2 changes: 1 addition & 1 deletion winit-core/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
1 change: 1 addition & 0 deletions winit/src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading