Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS, 3.x] Redraw window during resize and modal popups. #54757

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions platform/osx/os_osx.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class OS_OSX : public OS_Unix {

void _update_global_menu();

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

protected:
virtual void initialize_core();
virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
Expand Down
33 changes: 20 additions & 13 deletions platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,6 @@ - (void)windowDidResize:(NSNotification *)notification {
CGLEnable((CGLContextObj)[OS_OSX::singleton->context CGLContextObj], kCGLCESurfaceBackingSize);
}

if (OS_OSX::singleton->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();
}
}

/*
_GodotInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
_GodotInputWindowSize(window, contentRect.size.width, contentRect.size.height);
Expand Down Expand Up @@ -3295,11 +3287,25 @@ void _update_keyboard_layouts() {
joypad_osx->process_joypads();
}

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->init();

Expand All @@ -3308,10 +3314,8 @@ void _update_keyboard_layouts() {
set_window_fullscreen(true);
}

//uint64_t last_ticks=get_ticks_usec();

//int frames=0;
//uint64_t frame=0;
CFRunLoopObserverRef pre_wait_observer = CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, true, 0, &pre_wait_observer_cb, nullptr);
CFRunLoopAddObserver(CFRunLoopGetCurrent(), pre_wait_observer, kCFRunLoopCommonModes);

bool quit = false;

Expand All @@ -3328,6 +3332,9 @@ void _update_keyboard_layouts() {
}
};

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

main_loop->finish();
}

Expand Down