-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add WindowEvent::SafeAreaChanged event
#4507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nicoburns
wants to merge
2
commits into
rust-windowing:master
Choose a base branch
from
nicoburns:safe-area-event
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| #![allow(clippy::unnecessary_cast)] | ||
| use std::cell::{Cell, RefCell}; | ||
|
|
||
| use dpi::PhysicalPosition; | ||
| use dpi::{LogicalInsets, PhysicalInsets, PhysicalPosition}; | ||
| use objc2::rc::Retained; | ||
| use objc2::runtime::{NSObjectProtocol, ProtocolObject}; | ||
| use objc2::{DefinedClass, MainThreadMarker, available, define_class, msg_send, sel}; | ||
| use objc2_core_foundation::{CGFloat, CGPoint, CGRect}; | ||
| use objc2_foundation::{NSObject, NSSet, NSString}; | ||
| use objc2_ui_kit::{ | ||
| UIEvent, UIForceTouchCapability, UIGestureRecognizer, UIGestureRecognizerDelegate, | ||
| UIGestureRecognizerState, UIKeyInput, UIPanGestureRecognizer, UIPinchGestureRecognizer, | ||
| UIResponder, UIRotationGestureRecognizer, UITapGestureRecognizer, UITextInputTraits, UITouch, | ||
| UITouchPhase, UITouchType, UITraitEnvironment, UIView, | ||
| UIApplication, UIEdgeInsets, UIEvent, UIForceTouchCapability, UIGestureRecognizer, | ||
| UIGestureRecognizerDelegate, UIGestureRecognizerState, UIKeyInput, UIPanGestureRecognizer, | ||
| UIPinchGestureRecognizer, UIResponder, UIRotationGestureRecognizer, UITapGestureRecognizer, | ||
| UITextInputTraits, UITouch, UITouchPhase, UITouchType, UITraitEnvironment, UIView, | ||
| }; | ||
| use tracing::debug; | ||
| use winit_core::event::{ | ||
|
|
@@ -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(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be updated depending on what we decide the semantics should be. |
||
|
|
||
| let window = self.window().unwrap(); | ||
| let event = EventWrapper::Window { | ||
| window_id: window.id(), | ||
| event: WindowEvent::SafeAreaChanged(self.safe_area()), | ||
| }; | ||
|
|
||
| let mtm = MainThreadMarker::new().unwrap(); | ||
| app_state::handle_nonuser_event(mtm, event); | ||
| } | ||
|
|
||
| #[unsafe(method(touchesBegan:withEvent:))] | ||
|
|
@@ -368,6 +377,20 @@ impl WinitView { | |
| (**self).window().map(|window| window.downcast().unwrap()) | ||
| } | ||
|
|
||
| pub(crate) fn safe_area(&self) -> PhysicalInsets<u32> { | ||
| let insets = if available!(ios = 11.0, tvos = 11.0, visionos = 1.0) { | ||
| self.safeAreaInsets() | ||
| } else { | ||
| // Assume the status bar frame is the only thing that obscures the view | ||
| let app = UIApplication::sharedApplication(MainThreadMarker::new().unwrap()); | ||
| #[allow(deprecated)] | ||
| let status_bar_frame = app.statusBarFrame(); | ||
| UIEdgeInsets { top: status_bar_frame.size.height, left: 0.0, bottom: 0.0, right: 0.0 } | ||
| }; | ||
| let insets = LogicalInsets::new(insets.top, insets.left, insets.bottom, insets.right); | ||
| insets.to_physical(self.contentScaleFactor() as f64) | ||
| } | ||
|
|
||
| pub(crate) fn recognize_pinch_gesture(&self, should_recognize: bool) { | ||
| let mtm = MainThreadMarker::from(self); | ||
| if should_recognize { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ofSafeAreaChanged?There was a problem hiding this comment.
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.