From 0487876826819936f52f26d192627bd552867886 Mon Sep 17 00:00:00 2001 From: Aleksandr Ovchinnikov Date: Tue, 6 Apr 2021 10:19:25 +0300 Subject: [PATCH] On macOS, wake up the event loop immediately when a redraw is requested. (#1812) We allow to have RunLoop running only on the main thread. Which means if we call Window::request_redraw() from other the thread then we have to wait until some other event arrives on the main thread. That situation is even worse when we have ControlFlow set to the `Wait` mode then user will not ever render anything. --- CHANGELOG.md | 1 + src/platform_impl/macos/app_state.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e972bed..13a8b4c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added `is_maximized` method to `Window`. - On Windows, fix bug where clicking the decoration bar would make the cursor blink. - On Windows, fix bug causing newly created windows to erroneously display the "wait" (spinning) cursor. +- On macOS, wake up the event loop immediately when a redraw is requested. - On Windows, change the default window size (1024x768) to match the default on other desktop platforms (800x600). - On Windows, fix bug causing mouse capture to not be released. - On Windows, fix fullscreen not preserving minimized/maximized state. diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index b72cc57b..fb67b4d6 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -25,7 +25,7 @@ use crate::{ platform_impl::platform::{ event::{EventProxy, EventWrapper}, event_loop::{post_dummy_event, PanicInfo}, - observer::EventLoopWaker, + observer::{CFRunLoopGetMain, CFRunLoopWakeUp, EventLoopWaker}, util::{IdRef, Never}, window::get_window_id, }, @@ -321,6 +321,10 @@ impl AppState { if !pending_redraw.contains(&window_id) { pending_redraw.push(window_id); } + unsafe { + let rl = CFRunLoopGetMain(); + CFRunLoopWakeUp(rl); + } } pub fn queue_event(wrapper: EventWrapper) {