From ba704c4eb49638da7516250d26adee35ee0bc9a4 Mon Sep 17 00:00:00 2001 From: Xiaopeng Li Date: Tue, 6 Apr 2021 15:22:38 +0800 Subject: [PATCH] Mac: Redraw immediately to prevent shaking on window resize (#1901) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Mac: Redraw immediately to prevent shaking on window resize * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: 李小鹏 Co-authored-by: Markus Røyset --- CHANGELOG.md | 1 + src/platform_impl/macos/app_state.rs | 4 ++++ src/platform_impl/macos/view.rs | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13a8b4c0..662a58f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Added `WindowBuilder::with_position` to allow setting the position of a `Window` on creation. Supported on Windows, macOS and X11. - Added `Window::drag_window`. Implemented on Windows, macOS, X11 and Wayland. - On X11, bump `mio` to 0.7. +- On macOS, emit `RedrawRequested` events immediately while the window is being resized. # 0.24.0 (2020-12-09) diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index fb67b4d6..59cf0f2a 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -327,6 +327,10 @@ impl AppState { } } + pub fn handle_redraw(window_id: WindowId) { + HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id))); + } + pub fn queue_event(wrapper: EventWrapper) { if !unsafe { msg_send![class!(NSThread), isMainThread] } { panic!("Event queued from different thread: {:#?}", wrapper); diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 523cb665..aa7109f8 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -346,7 +346,7 @@ extern "C" fn draw_rect(this: &Object, _sel: Sel, rect: NSRect) { let state_ptr: *mut c_void = *this.get_ivar("winitState"); let state = &mut *(state_ptr as *mut ViewState); - AppState::queue_redraw(WindowId(get_window_id(state.ns_window))); + AppState::handle_redraw(WindowId(get_window_id(state.ns_window))); let superclass = util::superclass(this); let () = msg_send![super(this, superclass), drawRect: rect];