From d4c2e7ec2ef4e039539922aa43e64d95e731c0ab Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:49:38 +0300 Subject: [PATCH] [macOS, 3.x] Use occlusionState to determine when window is drawable. --- platform/osx/os_osx.h | 1 + platform/osx/os_osx.mm | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index d1ff0f3cb45..28cdaad3eb4 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -135,6 +135,7 @@ public: bool resizable; bool window_focused; bool on_top; + bool is_visible; Size2 window_size; Rect2 restore_rect; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index c540093bbe0..3b19600560e 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -463,6 +463,10 @@ static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) { OS_OSX::singleton->window_focused = true; }; +- (void)windowDidChangeOcclusionState:(NSNotification *)notification { + OS_OSX::singleton->is_visible = ([OS_OSX::singleton->window_object occlusionState] & NSWindowOcclusionStateVisible) && [OS_OSX::singleton->window_object isVisible]; +} + @end @interface GodotContentView : NSOpenGLView { @@ -2410,7 +2414,7 @@ String OS_OSX::get_system_dir(SystemDir p_dir, bool p_shared_storage) const { } bool OS_OSX::can_draw() const { - return true; + return is_visible; } void OS_OSX::set_clipboard(const String &p_text) { @@ -3568,6 +3572,7 @@ OS_OSX::OS_OSX() { im_position = Point2(); layered_window = false; autoreleasePool = [[NSAutoreleasePool alloc] init]; + is_visible = true; eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); ERR_FAIL_COND(!eventSource);