Skip to content

Commit ba704c4

Browse files
Mac: Redraw immediately to prevent shaking on window resize (#1901)
* Mac: Redraw immediately to prevent shaking on window resize * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: 李小鹏 <lixiaopeng.jetspark@bytedance.com> Co-authored-by: Markus Røyset <maroider@protonmail.com>
1 parent 0487876 commit ba704c4

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Added `WindowBuilder::with_position` to allow setting the position of a `Window` on creation. Supported on Windows, macOS and X11.
2020
- Added `Window::drag_window`. Implemented on Windows, macOS, X11 and Wayland.
2121
- On X11, bump `mio` to 0.7.
22+
- On macOS, emit `RedrawRequested` events immediately while the window is being resized.
2223

2324
# 0.24.0 (2020-12-09)
2425

src/platform_impl/macos/app_state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ impl AppState {
327327
}
328328
}
329329

330+
pub fn handle_redraw(window_id: WindowId) {
331+
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id)));
332+
}
333+
330334
pub fn queue_event(wrapper: EventWrapper) {
331335
if !unsafe { msg_send![class!(NSThread), isMainThread] } {
332336
panic!("Event queued from different thread: {:#?}", wrapper);

src/platform_impl/macos/view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ extern "C" fn draw_rect(this: &Object, _sel: Sel, rect: NSRect) {
346346
let state_ptr: *mut c_void = *this.get_ivar("winitState");
347347
let state = &mut *(state_ptr as *mut ViewState);
348348

349-
AppState::queue_redraw(WindowId(get_window_id(state.ns_window)));
349+
AppState::handle_redraw(WindowId(get_window_id(state.ns_window)));
350350

351351
let superclass = util::superclass(this);
352352
let () = msg_send![super(this, superclass), drawRect: rect];

0 commit comments

Comments
 (0)