mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
On macOS, emit resize event on frame_did_change
When the window switches mode from normal to tabbed one, it doesn't get resized, however the frame gets resized. This commit makes winit to track resizes when frame changes instead of window. Fixes #2191.
This commit is contained in:
parent
4dd2b66aaa
commit
bcd76d4718
|
@ -50,6 +50,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
- **Breaking:** Added new `WindowEvent::Ime` supported on desktop platforms.
|
- **Breaking:** Added new `WindowEvent::Ime` supported on desktop platforms.
|
||||||
- Added `Window::set_ime_allowed` supported on desktop platforms.
|
- Added `Window::set_ime_allowed` supported on desktop platforms.
|
||||||
- **Breaking:** IME input on desktop platforms won't be received unless it's explicitly allowed via `Window::set_ime_allowed` and new `WindowEvent::Ime` events are handled.
|
- **Breaking:** IME input on desktop platforms won't be received unless it's explicitly allowed via `Window::set_ime_allowed` and new `WindowEvent::Ime` events are handled.
|
||||||
|
- On macOS, `WindowEvent::Resized` is now emitted in `frameDidChange` instead of `windowDidResize`.
|
||||||
|
|
||||||
# 0.26.1 (2022-01-05)
|
# 0.26.1 (2022-01-05)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ use objc::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dpi::LogicalPosition,
|
dpi::{LogicalPosition, LogicalSize},
|
||||||
event::{
|
event::{
|
||||||
DeviceEvent, ElementState, Event, Ime, KeyboardInput, ModifiersState, MouseButton,
|
DeviceEvent, ElementState, Event, Ime, KeyboardInput, ModifiersState, MouseButton,
|
||||||
MouseScrollDelta, TouchPhase, VirtualKeyCode, WindowEvent,
|
MouseScrollDelta, TouchPhase, VirtualKeyCode, WindowEvent,
|
||||||
|
@ -400,8 +400,17 @@ extern "C" fn frame_did_change(this: &Object, _sel: Sel, _event: id) {
|
||||||
userData:ptr::null_mut::<c_void>()
|
userData:ptr::null_mut::<c_void>()
|
||||||
assumeInside:NO
|
assumeInside:NO
|
||||||
];
|
];
|
||||||
|
|
||||||
state.tracking_rect = Some(tracking_rect);
|
state.tracking_rect = Some(tracking_rect);
|
||||||
|
|
||||||
|
// Emit resize event here rather than from windowDidResize because:
|
||||||
|
// 1. When a new window is created as a tab, the frame size may change without a window resize occurring.
|
||||||
|
// 2. Even when a window resize does occur on a new tabbed window, it contains the wrong size (includes tab height).
|
||||||
|
let logical_size = LogicalSize::new(rect.size.width as f64, rect.size.height as f64);
|
||||||
|
let size = logical_size.to_physical::<u32>(state.get_scale_factor());
|
||||||
|
AppState::queue_event(EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
|
window_id: WindowId(get_window_id(state.ns_window)),
|
||||||
|
event: WindowEvent::Resized(size),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,14 +98,6 @@ impl WindowDelegateState {
|
||||||
AppState::queue_event(wrapper);
|
AppState::queue_event(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn emit_resize_event(&mut self) {
|
|
||||||
let rect = unsafe { NSView::frame(*self.ns_view) };
|
|
||||||
let scale_factor = self.get_scale_factor();
|
|
||||||
let logical_size = LogicalSize::new(rect.size.width as f64, rect.size.height as f64);
|
|
||||||
let size = logical_size.to_physical(scale_factor);
|
|
||||||
self.emit_event(WindowEvent::Resized(size));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn emit_move_event(&mut self) {
|
fn emit_move_event(&mut self) {
|
||||||
let rect = unsafe { NSWindow::frame(*self.ns_window) };
|
let rect = unsafe { NSWindow::frame(*self.ns_window) };
|
||||||
let x = rect.origin.x as f64;
|
let x = rect.origin.x as f64;
|
||||||
|
@ -286,7 +278,7 @@ extern "C" fn window_will_close(this: &Object, _: Sel, _: id) {
|
||||||
extern "C" fn window_did_resize(this: &Object, _: Sel, _: id) {
|
extern "C" fn window_did_resize(this: &Object, _: Sel, _: id) {
|
||||||
trace_scope!("windowDidResize:");
|
trace_scope!("windowDidResize:");
|
||||||
with_state(this, |state| {
|
with_state(this, |state| {
|
||||||
state.emit_resize_event();
|
// NOTE: WindowEvent::Resized is reported in frameDidChange.
|
||||||
state.emit_move_event();
|
state.emit_move_event();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue