From 932a161d44386987ab8af7fa92173044246da872 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 3 May 2016 11:58:25 +0200 Subject: [PATCH] Unconditionally use some EWMH atoms These window properties do no harm if they're declared even if the WM doesn't support them. This makes GLFW slightly more tolerant of WM changes as well as things like Ubuntu Unity reading _NET_WM_ICON without declaring support for it. --- src/x11_init.c | 30 +++++++++++++++------------ src/x11_window.c | 53 ++++++++++++++++-------------------------------- 2 files changed, 35 insertions(+), 48 deletions(-) diff --git a/src/x11_init.c b/src/x11_init.c index 2e7f7a72..522bf663 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -445,16 +445,6 @@ static void detectEWMH(void) getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_MAXIMIZED_HORZ"); _glfw.x11.NET_WM_FULLSCREEN_MONITORS = getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_FULLSCREEN_MONITORS"); - _glfw.x11.NET_WM_NAME = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_NAME"); - _glfw.x11.NET_WM_ICON_NAME = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON_NAME"); - _glfw.x11.NET_WM_ICON = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON"); - _glfw.x11.NET_WM_PID = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PID"); - _glfw.x11.NET_WM_PING = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING"); _glfw.x11.NET_WM_WINDOW_TYPE = getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_WINDOW_TYPE"); _glfw.x11.NET_WM_WINDOW_TYPE_NORMAL = @@ -465,8 +455,6 @@ static void detectEWMH(void) getSupportedAtom(supportedAtoms, atomCount, "_NET_FRAME_EXTENTS"); _glfw.x11.NET_REQUEST_FRAME_EXTENTS = getSupportedAtom(supportedAtoms, atomCount, "_NET_REQUEST_FRAME_EXTENTS"); - _glfw.x11.NET_WM_BYPASS_COMPOSITOR = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_BYPASS_COMPOSITOR"); XFree(supportedAtoms); } @@ -475,7 +463,8 @@ static void detectEWMH(void) // static GLFWbool initExtensions(void) { - // Find or create window manager atoms + // ICCCM window property and protocol atoms + // Always intern these as they can be set safely even without WM support _glfw.x11.WM_PROTOCOLS = XInternAtom(_glfw.x11.display, "WM_PROTOCOLS", False); @@ -487,6 +476,21 @@ static GLFWbool initExtensions(void) "_MOTIF_WM_HINTS", False); + // EWMH window property and protocol atoms + // Always intern these as they can be set safely even without WM support + _glfw.x11.NET_WM_ICON = + XInternAtom(_glfw.x11.display, "_NET_WM_ICON", False); + _glfw.x11.NET_WM_PING = + XInternAtom(_glfw.x11.display, "_NET_WM_PING", False); + _glfw.x11.NET_WM_PID = + XInternAtom(_glfw.x11.display, "_NET_WM_PID", False); + _glfw.x11.NET_WM_NAME = + XInternAtom(_glfw.x11.display, "_NET_WM_NAME", False); + _glfw.x11.NET_WM_ICON_NAME = + XInternAtom(_glfw.x11.display, "_NET_WM_ICON_NAME", False); + _glfw.x11.NET_WM_BYPASS_COMPOSITOR = + XInternAtom(_glfw.x11.display, "_NET_WM_BYPASS_COMPOSITOR", False); + #if defined(_GLFW_HAS_XF86VM) // Check for XF86VidMode extension _glfw.x11.vidmode.available = diff --git a/src/x11_window.c b/src/x11_window.c index dfa7af30..fbe36f1d 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -295,7 +295,7 @@ static void updateWindowMode(_GLFWwindow* window) window->x11.overrideRedirect = GLFW_TRUE; } - if (_glfw.x11.NET_WM_BYPASS_COMPOSITOR) + // Enable compositor bypass { const unsigned long value = 1; @@ -333,7 +333,7 @@ static void updateWindowMode(_GLFWwindow* window) window->x11.overrideRedirect = GLFW_FALSE; } - if (_glfw.x11.NET_WM_BYPASS_COMPOSITOR) + // Disable compositor bypass { XDeleteProperty(_glfw.x11.display, window->x11.handle, _glfw.x11.NET_WM_BYPASS_COMPOSITOR); @@ -495,28 +495,17 @@ static GLFWbool createWindow(_GLFWwindow* window, // Declare the WM protocols supported by GLFW { - int count = 0; - Atom protocols[2]; - - // The WM_DELETE_WINDOW ICCCM protocol - // Basic window close notification protocol - if (_glfw.x11.WM_DELETE_WINDOW) - protocols[count++] = _glfw.x11.WM_DELETE_WINDOW; - - // The _NET_WM_PING EWMH protocol - // Tells the WM to ping the GLFW window and flag the application as - // unresponsive if the WM doesn't get a reply within a few seconds - if (_glfw.x11.NET_WM_PING) - protocols[count++] = _glfw.x11.NET_WM_PING; - - if (count > 0) + Atom protocols[] = { - XSetWMProtocols(_glfw.x11.display, window->x11.handle, - protocols, count); - } + _glfw.x11.WM_DELETE_WINDOW, + _glfw.x11.NET_WM_PING + }; + + XSetWMProtocols(_glfw.x11.display, window->x11.handle, + protocols, sizeof(protocols) / sizeof(Atom)); } - if (_glfw.x11.NET_WM_PID) + // Declare our PID { const pid_t pid = getpid(); @@ -1591,21 +1580,15 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) NULL, NULL, NULL); #endif - if (_glfw.x11.NET_WM_NAME) - { - XChangeProperty(_glfw.x11.display, window->x11.handle, - _glfw.x11.NET_WM_NAME, _glfw.x11.UTF8_STRING, 8, - PropModeReplace, - (unsigned char*) title, strlen(title)); - } + XChangeProperty(_glfw.x11.display, window->x11.handle, + _glfw.x11.NET_WM_NAME, _glfw.x11.UTF8_STRING, 8, + PropModeReplace, + (unsigned char*) title, strlen(title)); - if (_glfw.x11.NET_WM_ICON_NAME) - { - XChangeProperty(_glfw.x11.display, window->x11.handle, - _glfw.x11.NET_WM_ICON_NAME, _glfw.x11.UTF8_STRING, 8, - PropModeReplace, - (unsigned char*) title, strlen(title)); - } + XChangeProperty(_glfw.x11.display, window->x11.handle, + _glfw.x11.NET_WM_ICON_NAME, _glfw.x11.UTF8_STRING, 8, + PropModeReplace, + (unsigned char*) title, strlen(title)); XFlush(_glfw.x11.display); }