Skip to content

Commit

Permalink
Merge pull request #54756 from bruvzg/pre_wait_observer_redraw4
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Nov 8, 2021
2 parents ce634e0 + 73a774d commit 18598a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
8 changes: 0 additions & 8 deletions platform/osx/display_server_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,6 @@ - (void)windowDidResize:(NSNotification *)notification {
Callable::CallError ce;
wd.rect_changed_callback.call((const Variant **)&sizep, 1, ret, ce);
}

if (OS_OSX::get_singleton()->get_main_loop()) {
Main::force_redraw();
//Event retrieval blocks until resize is over. Call Main::iteration() directly.
if (!Main::is_iterating()) { //avoid cyclic loop
Main::iteration();
}
}
}

- (void)windowDidMove:(NSNotification *)notification {
Expand Down
2 changes: 2 additions & 0 deletions platform/osx/os_osx.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class OS_OSX : public OS_Unix {

MainLoop *main_loop;

static void pre_wait_observer_cb(CFRunLoopObserverRef p_observer, CFRunLoopActivity p_activiy, void *p_context);

public:
String open_with_filename;

Expand Down
23 changes: 22 additions & 1 deletion platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,31 @@ _FORCE_INLINE_ String _get_framework_executable(const String p_path) {
}
}

void OS_OSX::pre_wait_observer_cb(CFRunLoopObserverRef p_observer, CFRunLoopActivity p_activiy, void *p_context) {
// Prevent main loop from sleeping and redraw window during resize / modal popups.

if (get_singleton()->get_main_loop()) {
Main::force_redraw();
if (!Main::is_iterating()) { // Avoid cyclic loop.
Main::iteration();
}
}

CFRunLoopWakeUp(CFRunLoopGetCurrent()); // Prevent main loop from sleeping.
}

void OS_OSX::run() {
force_quit = false;

if (!main_loop)
if (!main_loop) {
return;
}

main_loop->initialize();

CFRunLoopObserverRef pre_wait_observer = CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, true, 0, &pre_wait_observer_cb, nullptr);
CFRunLoopAddObserver(CFRunLoopGetCurrent(), pre_wait_observer, kCFRunLoopCommonModes);

bool quit = false;
while (!force_quit && !quit) {
@try {
Expand All @@ -572,6 +589,10 @@ _FORCE_INLINE_ String _get_framework_executable(const String p_path) {
ERR_PRINT("NSException: " + String([exception reason].UTF8String));
}
};

CFRunLoopRemoveObserver(CFRunLoopGetCurrent(), pre_wait_observer, kCFRunLoopCommonModes);
CFRelease(pre_wait_observer);

main_loop->finalize();
}

Expand Down

0 comments on commit 18598a4

Please sign in to comment.