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

[3.x] [macOS] Use occlusionState to determine when window is drawable. #83136

Merged
merged 1 commit into from
Nov 14, 2023
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
1 change: 1 addition & 0 deletions platform/osx/os_osx.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class OS_OSX : public OS_Unix {
bool resizable;
bool window_focused;
bool on_top;
bool is_visible;

Size2 window_size;
Rect2 restore_rect;
Expand Down
7 changes: 6 additions & 1 deletion platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ - (void)windowDidDeminiaturize:(NSNotification *)notification {
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 <NSTextInputClient> {
Expand Down Expand Up @@ -2410,7 +2414,7 @@ virtual void log_error(const char *p_function, const char *p_file, int p_line, c
}

bool OS_OSX::can_draw() const {
return true;
return is_visible;
}

void OS_OSX::set_clipboard(const String &p_text) {
Expand Down Expand Up @@ -3568,6 +3572,7 @@ void _update_keyboard_layouts() {
im_position = Point2();
layered_window = false;
autoreleasePool = [[NSAutoreleasePool alloc] init];
is_visible = true;

eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
ERR_FAIL_COND(!eventSource);
Expand Down