Skip to content

Commit

Permalink
On macOS, send a Resized event after ScaleFactorChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpulvis authored and kchibisov committed Nov 24, 2023
1 parent 5d8a9c9 commit bf2a9f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Unreleased` header.

- On X11, check common alternative cursor names when loading cursor.
- On Windows, fix so `drag_window` and `drag_resize_window` can be called from another thread.
- On macOS, send a `Resized` event after each `ScaleFactorChanged` event.

# 0.29.3

Expand Down
10 changes: 8 additions & 2 deletions src/platform_impl/macos/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,21 +329,27 @@ impl Handler {
) {
if let Some(ref mut callback) = *self.callback.lock().unwrap() {
let new_inner_size = Arc::new(Mutex::new(suggested_size));
let event = Event::WindowEvent {
let scale_factor_changed_event = Event::WindowEvent {
window_id: WindowId(window.id()),
event: WindowEvent::ScaleFactorChanged {
scale_factor,
inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_inner_size)),
},
};

callback.handle_nonuser_event(event);
callback.handle_nonuser_event(scale_factor_changed_event);

let physical_size = *new_inner_size.lock().unwrap();
drop(new_inner_size);
let logical_size = physical_size.to_logical(scale_factor);
let size = NSSize::new(logical_size.width, logical_size.height);
window.setContentSize(size);

let resized_event = Event::WindowEvent {
window_id: WindowId(window.id()),
event: WindowEvent::Resized(physical_size),
};
callback.handle_nonuser_event(resized_event);
}
}
}
Expand Down

0 comments on commit bf2a9f6

Please sign in to comment.