Implement Window_IsObscured for macOS

This commit is contained in:
UnknownShadow200 2021-11-28 23:03:19 +11:00
parent db9ee23a86
commit e9a6edf9cd
2 changed files with 18 additions and 2 deletions

View File

@ -543,7 +543,11 @@ cc_result Window_ExitFullscreen(void) {
return res; return res;
} }
int Window_IsObscured(void) { return 0; } int Window_IsObscured(void) {
/* TODO: This isn't a complete fix because it doesn't check for occlusion - */
/* so you'll still get 100% CPU usage when window is hidden in background */
return IsWindowCollapsed(win_handle);
}
void Window_Show(void) { void Window_Show(void) {
ShowWindow(win_handle); ShowWindow(win_handle);

View File

@ -10,6 +10,7 @@ static int windowX, windowY;
static NSApplication* appHandle; static NSApplication* appHandle;
static NSWindow* winHandle; static NSWindow* winHandle;
static NSView* viewHandle; static NSView* viewHandle;
static cc_bool canCheckOcclusion;
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------Shared with Carbon----------------------------------------------------* *---------------------------------------------------Shared with Carbon----------------------------------------------------*
@ -287,6 +288,8 @@ static void DoCreateWindow(int width, int height) {
RefreshWindowBounds(); RefreshWindowBounds();
MakeContentView(); MakeContentView();
ApplyIcon(); ApplyIcon();
canCheckOcclusion = [winHandle respondsToSelector:@selector(occlusionState)];
} }
void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } void Window_Create2D(int width, int height) { DoCreateWindow(width, height); }
void Window_Create3D(int width, int height) { DoCreateWindow(width, height); } void Window_Create3D(int width, int height) { DoCreateWindow(width, height); }
@ -323,7 +326,16 @@ cc_result Window_ExitFullscreen(void) {
return 0; return 0;
} }
int Window_IsObscured(void) { return 0; } // NOTE: Only defined since macOS 10.9 SDK
#define _NSWindowOcclusionStateVisible (1 << 1)
int Window_IsObscured(void) {
if (!canCheckOcclusion)
return [winHandle isMiniaturized];
// covers both minimised and hidden behind another window
int flags = [winHandle occlusionState];
return !(flags & _NSWindowOcclusionStateVisible);
}
void Window_Show(void) { void Window_Show(void) {
[winHandle makeKeyAndOrderFront:appHandle]; [winHandle makeKeyAndOrderFront:appHandle];