Skip to content
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

WindowEvent::Resized report outer size on iOS #2347

Closed
marysaka opened this issue Jun 26, 2022 · 1 comment · Fixed by #3890
Closed

WindowEvent::Resized report outer size on iOS #2347

marysaka opened this issue Jun 26, 2022 · 1 comment · Fixed by #3890
Labels
B - bug Dang, that shouldn't have happened DS - ios

Comments

@marysaka
Copy link

When starting any applications using winit on iOS, I'm receiving a WindowEvent::Resized coming from layout_subviews corresponding to the full size of the screen instead of the inner size.

I currently workaround this by using Window::inner_size when handling that event.

extern "C" fn layout_subviews(object: &Object, _: Sel) {
unsafe {
let superclass: &'static Class = msg_send![object, superclass];
let _: () = msg_send![super(object, superclass), layoutSubviews];
let window: id = msg_send![object, window];
assert!(!window.is_null());
let window_bounds: CGRect = msg_send![window, bounds];
let screen: id = msg_send![window, screen];
let screen_space: id = msg_send![screen, coordinateSpace];
let screen_frame: CGRect =
msg_send![object, convertRect:window_bounds toCoordinateSpace:screen_space];
let scale_factor: CGFloat = msg_send![screen, scale];
let size = crate::dpi::LogicalSize {
width: screen_frame.size.width as f64,
height: screen_frame.size.height as f64,
}
.to_physical(scale_factor as f64);
// If the app is started in landscape, the view frame and window bounds can be mismatched.
// The view frame will be in portrait and the window bounds in landscape. So apply the
// window bounds to the view frame to make it consistent.
let view_frame: CGRect = msg_send![object, frame];
if view_frame != window_bounds {
let _: () = msg_send![object, setFrame: window_bounds];
}
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.into()),
event: WindowEvent::Resized(size),
}));
}
}

@madsmtm madsmtm added B - bug Dang, that shouldn't have happened DS - ios labels Jun 26, 2022
@madsmtm
Copy link
Member

madsmtm commented Jun 26, 2022

Related: #2308

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened DS - ios
Development

Successfully merging a pull request may close this issue.

2 participants