From 301a84c4f5c644697ebc36b27812ba3d972a778f Mon Sep 17 00:00:00 2001 From: Felipe Ferreira da Silva Date: Tue, 21 Mar 2017 10:02:57 -0300 Subject: [PATCH] Initial implementation of window attention for X11 --- include/GLFW/glfw3.h | 2 ++ src/internal.h | 1 + src/window.c | 10 ++++++++++ src/x11_window.c | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 8b2efcec2..73a139df4 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -2698,6 +2698,8 @@ GLFWAPI void glfwMaximizeWindow(GLFWwindow* window); */ GLFWAPI void glfwShowWindow(GLFWwindow* window); +GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window); + /*! @brief Hides the specified window. * * This function hides the specified window if it was previously visible. If diff --git a/src/internal.h b/src/internal.h index be9ced898..00b362544 100644 --- a/src/internal.h +++ b/src/internal.h @@ -629,6 +629,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window); void _glfwPlatformRestoreWindow(_GLFWwindow* window); void _glfwPlatformMaximizeWindow(_GLFWwindow* window); void _glfwPlatformShowWindow(_GLFWwindow* window); +void _glfwPlatformRequestWindowAttention(_GLFWwindow* window); void _glfwPlatformHideWindow(_GLFWwindow* window); void _glfwPlatformFocusWindow(_GLFWwindow* window); void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); diff --git a/src/window.c b/src/window.c index bf98723ea..546d233d8 100644 --- a/src/window.c +++ b/src/window.c @@ -675,6 +675,16 @@ GLFWAPI void glfwShowWindow(GLFWwindow* handle) _glfwPlatformFocusWindow(window); } +GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window != NULL); + + _GLFW_REQUIRE_INIT(); + + _glfwPlatformRequestWindowAttention(window); +} + GLFWAPI void glfwHideWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; diff --git a/src/x11_window.c b/src/x11_window.c index 907fa7946..48c30edb3 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2072,6 +2072,24 @@ void _glfwPlatformShowWindow(_GLFWwindow* window) waitForVisibilityNotify(window); } +void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) +{ + XEvent xev; + + Atom wm_state = XInternAtom(_glfw.x11.display, "_NET_WM_STATE", False); + Atom wm_attention = XInternAtom(_glfw.x11.display, "_NET_WM_STATE_DEMANDS_ATTENTION", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = window->x11.handle; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = 1; /* _NET_WM_STATE_ADD */ + xev.xclient.data.l[1] = wm_attention; + + XSendEvent(_glfw.x11.display, DefaultRootWindow(_glfw.x11.display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); +} + void _glfwPlatformHideWindow(_GLFWwindow* window) { XUnmapWindow(_glfw.x11.display, window->x11.handle);