mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
macOS: Fix move event sometimes being triggered on resize (#3914)
This commit is contained in:
committed by
Kirill Chibisov
parent
685090021b
commit
1bc405e526
@@ -47,5 +47,6 @@ changelog entry.
|
||||
|
||||
### Fixed
|
||||
|
||||
- On macOS, fix `WindowEvent::Moved` sometimes being triggered unnecessarily on resize.
|
||||
- On MacOS, package manifest definitions of `LSUIElement` will no longer be overridden with the
|
||||
default activation policy, unless explicitly provided during initialization.
|
||||
|
||||
@@ -87,8 +87,8 @@ pub(crate) struct State {
|
||||
|
||||
// During `windowDidResize`, we use this to only send Moved if the position changed.
|
||||
//
|
||||
// This is expressed in native screen coordinates.
|
||||
previous_position: Cell<Option<NSPoint>>,
|
||||
// This is expressed in desktop coordinates, and flipped to match Winit's coordinate system.
|
||||
previous_position: Cell<NSPoint>,
|
||||
|
||||
// Used to prevent redundant events.
|
||||
previous_scale_factor: Cell<f64>,
|
||||
@@ -714,7 +714,7 @@ impl WindowDelegate {
|
||||
let delegate = mtm.alloc().set_ivars(State {
|
||||
app_delegate: app_delegate.retain(),
|
||||
window: window.retain(),
|
||||
previous_position: Cell::new(None),
|
||||
previous_position: Cell::new(flip_window_screen_coordinates(window.frame())),
|
||||
previous_scale_factor: Cell::new(scale_factor),
|
||||
resize_increments: Cell::new(resize_increments),
|
||||
decorations: Cell::new(attrs.decorations),
|
||||
@@ -839,13 +839,12 @@ impl WindowDelegate {
|
||||
}
|
||||
|
||||
fn emit_move_event(&self) {
|
||||
let frame = self.window().frame();
|
||||
if self.ivars().previous_position.get() == Some(frame.origin) {
|
||||
let position = flip_window_screen_coordinates(self.window().frame());
|
||||
if self.ivars().previous_position.get() == position {
|
||||
return;
|
||||
}
|
||||
self.ivars().previous_position.set(Some(frame.origin));
|
||||
self.ivars().previous_position.set(position);
|
||||
|
||||
let position = flip_window_screen_coordinates(frame);
|
||||
let position =
|
||||
LogicalPosition::new(position.x, position.y).to_physical(self.scale_factor());
|
||||
self.queue_event(WindowEvent::Moved(position));
|
||||
|
||||
Reference in New Issue
Block a user