From 11061d59e7e3271d8686e8f12ac34d314bb6729d Mon Sep 17 00:00:00 2001 From: Green Lightning Date: Thu, 9 Nov 2017 18:09:40 +0100 Subject: [PATCH] Add GLFW_OCCLUDED window attribute --- docs/window.dox | 10 ++++++++++ include/GLFW/glfw3.h | 5 +++++ src/cocoa_window.m | 5 +++++ src/internal.h | 1 + src/mir_window.c | 0 src/null_window.c | 5 +++++ src/win32_window.c | 5 +++++ src/window.c | 2 ++ src/wl_window.c | 5 +++++ src/x11_window.c | 5 +++++ 10 files changed, 43 insertions(+) create mode 100644 src/mir_window.c diff --git a/docs/window.dox b/docs/window.dox index f35ebc741..adc26be56 100644 --- a/docs/window.dox +++ b/docs/window.dox @@ -1150,6 +1150,12 @@ void window_occlusion_callback(GLFWwindow* window, int occluded) } @endcode +You can also get the current occlusion state with @ref glfwGetWindowAttrib. + +@code +int occluded = glfwGetWindowAttrib(window, GLFW_OCCLUDED); +@endcode + @note This is currently implemented on macOS only. @@ -1289,6 +1295,10 @@ for details. __GLFW_VISIBLE__ indicates whether the specified window is visible. See @ref window_hide for details. +@anchor GLFW_OCCLUDED_attrib +__GLFW_OCCLUDED__ indicates whether the specified window is occluded. +See @ref window_occlusion for details. + @anchor GLFW_RESIZABLE_attrib __GLFW_RESIZABLE__ indicates whether the specified window is resizable _by the user_. This can be set before creation with the diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index f9a1374a9..394244c89 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -825,6 +825,11 @@ extern "C" { * [window attribute](@ref GLFW_FOCUS_ON_SHOW_attrib). */ #define GLFW_FOCUS_ON_SHOW 0x0002000C +/*! @brief Occlusion window attribute + * + * Occlusion [window attribute](@ref GLFW_OCCLUDED_attrib). + */ +#define GLFW_OCCLUDED 0x0002000D /*! @brief Framebuffer bit depth hint. * diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 85713678c..7db1623b9 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1515,6 +1515,11 @@ int _glfwPlatformWindowFocused(_GLFWwindow* window) return [window->ns.object isKeyWindow]; } +int _glfwPlatformWindowOccluded(_GLFWwindow* window) +{ + return !([window->ns.object occlusionState] & NSWindowOcclusionStateVisible); +} + int _glfwPlatformWindowIconified(_GLFWwindow* window) { return [window->ns.object isMiniaturized]; diff --git a/src/internal.h b/src/internal.h index 13d46c779..e7a6ca619 100644 --- a/src/internal.h +++ b/src/internal.h @@ -657,6 +657,7 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); int _glfwPlatformWindowFocused(_GLFWwindow* window); +int _glfwPlatformWindowOccluded(_GLFWwindow* window); int _glfwPlatformWindowIconified(_GLFWwindow* window); int _glfwPlatformWindowVisible(_GLFWwindow* window); int _glfwPlatformWindowMaximized(_GLFWwindow* window); diff --git a/src/mir_window.c b/src/mir_window.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/null_window.c b/src/null_window.c index 6a54cfe56..32d7bae78 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -222,6 +222,11 @@ int _glfwPlatformWindowFocused(_GLFWwindow* window) return GLFW_FALSE; } +int _glfwPlatformWindowOccluded(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + int _glfwPlatformWindowIconified(_GLFWwindow* window) { return GLFW_FALSE; diff --git a/src/win32_window.c b/src/win32_window.c index 796ae150e..19ea097ff 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1760,6 +1760,11 @@ int _glfwPlatformWindowFocused(_GLFWwindow* window) return window->win32.handle == GetActiveWindow(); } +int _glfwPlatformWindowOccluded(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + int _glfwPlatformWindowIconified(_GLFWwindow* window) { return IsIconic(window->win32.handle); diff --git a/src/window.c b/src/window.c index 1ef160429..10c004f7e 100644 --- a/src/window.c +++ b/src/window.c @@ -832,6 +832,8 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib) return window->focusOnShow; case GLFW_TRANSPARENT_FRAMEBUFFER: return _glfwPlatformFramebufferTransparent(window); + case GLFW_OCCLUDED: + return _glfwPlatformWindowOccluded(window); case GLFW_RESIZABLE: return window->resizable; case GLFW_DECORATED: diff --git a/src/wl_window.c b/src/wl_window.c index 98a646590..4406de8c8 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1243,6 +1243,11 @@ int _glfwPlatformWindowFocused(_GLFWwindow* window) return _glfw.wl.keyboardFocus == window; } +int _glfwPlatformWindowOccluded(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + int _glfwPlatformWindowIconified(_GLFWwindow* window) { // wl_shell doesn't have any iconified concept, and xdg-shell doesn’t give diff --git a/src/x11_window.c b/src/x11_window.c index c01cf17ec..3bdc9bd6d 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2433,6 +2433,11 @@ int _glfwPlatformWindowFocused(_GLFWwindow* window) return window->x11.handle == focused; } +int _glfwPlatformWindowOccluded(_GLFWwindow* window) +{ + return GLFW_FALSE; +} + int _glfwPlatformWindowIconified(_GLFWwindow* window) { return getWindowState(window) == IconicState;