diff --git a/src/Window_Carbon.c b/src/Window_Carbon.c index 47f5bf93e..2f1dbc439 100644 --- a/src/Window_Carbon.c +++ b/src/Window_Carbon.c @@ -543,7 +543,11 @@ cc_result Window_ExitFullscreen(void) { 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) { ShowWindow(win_handle); diff --git a/src/interop_cocoa.m b/src/interop_cocoa.m index 6e24efd73..1895c9594 100644 --- a/src/interop_cocoa.m +++ b/src/interop_cocoa.m @@ -10,6 +10,7 @@ static int windowX, windowY; static NSApplication* appHandle; static NSWindow* winHandle; static NSView* viewHandle; +static cc_bool canCheckOcclusion; /*########################################################################################################################* *---------------------------------------------------Shared with Carbon----------------------------------------------------* @@ -287,6 +288,8 @@ static void DoCreateWindow(int width, int height) { RefreshWindowBounds(); MakeContentView(); ApplyIcon(); + + canCheckOcclusion = [winHandle respondsToSelector:@selector(occlusionState)]; } void Window_Create2D(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; } -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) { [winHandle makeKeyAndOrderFront:appHandle];