X11: Clean up EWMH feature detection

The EWMH feature detection atoms are now named and loaded the same way
as other X11 atoms.  Detection is now performed after all
non-conditional atoms have been loaded.  The EWMH detection now has
hopefully more readable comments.

(cherry picked from commit fad9896d38)
This commit is contained in:
Camilla Löwy 2019-06-04 16:52:40 +02:00
parent 66e06b0609
commit e276f6731e
2 changed files with 30 additions and 27 deletions

View File

@ -371,18 +371,11 @@ static Atom getSupportedAtom(Atom* supportedAtoms,
// //
static void detectEWMH(void) static void detectEWMH(void)
{ {
// First we read the _NET_SUPPORTING_WM_CHECK property on the root window
Window* windowFromRoot = NULL; Window* windowFromRoot = NULL;
Window* windowFromChild = NULL;
// First we need a couple of atoms
const Atom supportingWmCheck =
XInternAtom(_glfw.x11.display, "_NET_SUPPORTING_WM_CHECK", False);
const Atom wmSupported =
XInternAtom(_glfw.x11.display, "_NET_SUPPORTED", False);
// Then we look for the _NET_SUPPORTING_WM_CHECK property of the root window
if (!_glfwGetWindowPropertyX11(_glfw.x11.root, if (!_glfwGetWindowPropertyX11(_glfw.x11.root,
supportingWmCheck, _glfw.x11.NET_SUPPORTING_WM_CHECK,
XA_WINDOW, XA_WINDOW,
(unsigned char**) &windowFromRoot)) (unsigned char**) &windowFromRoot))
{ {
@ -391,10 +384,12 @@ static void detectEWMH(void)
_glfwGrabErrorHandlerX11(); _glfwGrabErrorHandlerX11();
// It should be the ID of a child window (of the root) // If it exists, it should be the XID of a top-level window
// Then we look for the same property on the child window // Then we look for the same property on that window
Window* windowFromChild = NULL;
if (!_glfwGetWindowPropertyX11(*windowFromRoot, if (!_glfwGetWindowPropertyX11(*windowFromRoot,
supportingWmCheck, _glfw.x11.NET_SUPPORTING_WM_CHECK,
XA_WINDOW, XA_WINDOW,
(unsigned char**) &windowFromChild)) (unsigned char**) &windowFromChild))
{ {
@ -404,7 +399,8 @@ static void detectEWMH(void)
_glfwReleaseErrorHandlerX11(); _glfwReleaseErrorHandlerX11();
// It should be the ID of that same child window // If the property exists, it should contain the XID of the window
if (*windowFromRoot != *windowFromChild) if (*windowFromRoot != *windowFromChild)
{ {
XFree(windowFromRoot); XFree(windowFromRoot);
@ -415,19 +411,20 @@ static void detectEWMH(void)
XFree(windowFromRoot); XFree(windowFromRoot);
XFree(windowFromChild); XFree(windowFromChild);
// We are now fairly sure that an EWMH-compliant window manager is running // We are now fairly sure that an EWMH-compliant WM is currently running
// We can now start querying the WM about what features it supports by
// looking in the _NET_SUPPORTED property on the root window
// It should contain a list of supported EWMH protocol and state atoms
Atom* supportedAtoms; Atom* supportedAtoms = NULL;
unsigned long atomCount; const unsigned long atomCount =
_glfwGetWindowPropertyX11(_glfw.x11.root,
// Now we need to check the _NET_SUPPORTED property of the root window _glfw.x11.NET_SUPPORTED,
// It should be a list of supported WM protocol and state atoms
atomCount = _glfwGetWindowPropertyX11(_glfw.x11.root,
wmSupported,
XA_ATOM, XA_ATOM,
(unsigned char**) &supportedAtoms); (unsigned char**) &supportedAtoms);
// See which of the atoms we support that are supported by the WM // See which of the atoms we support that are supported by the WM
_glfw.x11.NET_WM_STATE = _glfw.x11.NET_WM_STATE =
getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE"); getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE");
_glfw.x11.NET_WM_STATE_ABOVE = _glfw.x11.NET_WM_STATE_ABOVE =
@ -707,9 +704,6 @@ static GLFWbool initExtensions(void)
// the keyboard mapping. // the keyboard mapping.
createKeyTables(); createKeyTables();
// Detect whether an EWMH-conformant window manager is running
detectEWMH();
// String format atoms // String format atoms
_glfw.x11.NULL_ = XInternAtom(_glfw.x11.display, "NULL", False); _glfw.x11.NULL_ = XInternAtom(_glfw.x11.display, "NULL", False);
_glfw.x11.UTF8_STRING = XInternAtom(_glfw.x11.display, "UTF8_STRING", False); _glfw.x11.UTF8_STRING = XInternAtom(_glfw.x11.display, "UTF8_STRING", False);
@ -753,6 +747,10 @@ static GLFWbool initExtensions(void)
XInternAtom(_glfw.x11.display, "WM_STATE", False); XInternAtom(_glfw.x11.display, "WM_STATE", False);
_glfw.x11.WM_DELETE_WINDOW = _glfw.x11.WM_DELETE_WINDOW =
XInternAtom(_glfw.x11.display, "WM_DELETE_WINDOW", False); XInternAtom(_glfw.x11.display, "WM_DELETE_WINDOW", False);
_glfw.x11.NET_SUPPORTED =
XInternAtom(_glfw.x11.display, "_NET_SUPPORTED", False);
_glfw.x11.NET_SUPPORTING_WM_CHECK =
XInternAtom(_glfw.x11.display, "_NET_SUPPORTING_WM_CHECK", False);
_glfw.x11.NET_WM_ICON = _glfw.x11.NET_WM_ICON =
XInternAtom(_glfw.x11.display, "_NET_WM_ICON", False); XInternAtom(_glfw.x11.display, "_NET_WM_ICON", False);
_glfw.x11.NET_WM_PING = _glfw.x11.NET_WM_PING =
@ -777,6 +775,9 @@ static GLFWbool initExtensions(void)
_glfw.x11.NET_WM_CM_Sx = XInternAtom(_glfw.x11.display, name, False); _glfw.x11.NET_WM_CM_Sx = XInternAtom(_glfw.x11.display, name, False);
} }
// Detect whether an EWMH-conformant window manager is running
detectEWMH();
return GLFW_TRUE; return GLFW_TRUE;
} }

View File

@ -239,6 +239,8 @@ typedef struct _GLFWlibraryX11
_GLFWwindow* disabledCursorWindow; _GLFWwindow* disabledCursorWindow;
// Window manager atoms // Window manager atoms
Atom NET_SUPPORTED;
Atom NET_SUPPORTING_WM_CHECK;
Atom WM_PROTOCOLS; Atom WM_PROTOCOLS;
Atom WM_STATE; Atom WM_STATE;
Atom WM_DELETE_WINDOW; Atom WM_DELETE_WINDOW;