Skip to content

Add WindowEvent::SafeAreaChanged event#4507

Draft
nicoburns wants to merge 2 commits intorust-windowing:masterfrom
nicoburns:safe-area-event
Draft

Add WindowEvent::SafeAreaChanged event#4507
nicoburns wants to merge 2 commits intorust-windowing:masterfrom
nicoburns:safe-area-event

Conversation

@nicoburns
Copy link
Copy Markdown
Contributor

@nicoburns nicoburns commented Mar 8, 2026

Implements a SafeAreaChanged event on Android and iOS. Currently a draft because not yet tested.

Signed-off-by: Nico Burns <nico@nicoburns.com>
@nicoburns nicoburns changed the title Safe area event Add WindowEvent::SafeAreaChanged event Mar 8, 2026
@nicoburns
Copy link
Copy Markdown
Contributor Author

@madsmtm I wasn't sure how to listen for changes on macOS (what does the safe area even correspond to on macOS?). Do you know how to do that?

Signed-off-by: Nico Burns <nico@nicoburns.com>
@madsmtm
Copy link
Copy Markdown
Member

madsmtm commented Mar 17, 2026

The safe area on macOS is the notch in fullscreen applications, and when you use NSWindowStyleMask::FullSizeContentView to make the view extend beneath the window's title bar. I think the most robust way to handle it would be an observer on NSView.safeAreaInsets.

@madsmtm madsmtm added DS - appkit Affects the AppKit/macOS backend DS - android Affects the Android backend S - api Design and usability DS - uikit Affects the UIKit backend (iOS, tvOS, watchOS, visionOS) labels Mar 17, 2026
/// [`Window::safe_area`]).
///
/// This event will not necessarily be emitted upon window creation, query
/// [`Window::safe_area`] if you need to determine the initial safe area.
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.

Should discuss the relationship with SurfaceResized (and specifically that either may be emitted independently).

Unless we don't want that, and think it makes sense to also emit a SurfaceResized? But if so, what is the point of SafeAreaChanged?

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.

Yes, probably. I guess if you get SurfaceResized, then you probably need to re-resolve the safe area (as it's insets relative to the surface size), but the other way round is not true. You can process the safe area events assuming that the surface size is unchanged.

@@ -127,6 +127,15 @@ define_class!(
debug!("safeAreaInsetsDidChange was called, requesting redraw");
// When the safe area changes we want to make sure to emit a redraw event
self.setNeedsDisplay();
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.

Should be updated depending on what we decide the semantics should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DS - android Affects the Android backend DS - appkit Affects the AppKit/macOS backend DS - uikit Affects the UIKit backend (iOS, tvOS, watchOS, visionOS) S - api Design and usability

Development

Successfully merging this pull request may close these issues.

Add event for changes to the safe area

2 participants