浏览代码

Added support for _NET_REQUEST_FRAME_EXTENTS.

Camilla Berglund 11 年之前
父节点
当前提交
0c58df06d5
共有 3 个文件被更改,包括 35 次插入0 次删除
  1. 2 0
      src/x11_init.c
  2. 1 0
      src/x11_platform.h
  3. 32 0
      src/x11_window.c

+ 2 - 0
src/x11_init.c

@@ -417,6 +417,8 @@ static void detectEWMH(void)
         getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW");
     _glfw.x11.NET_FRAME_EXTENTS =
         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");
 

+ 1 - 0
src/x11_platform.h

@@ -121,6 +121,7 @@ typedef struct _GLFWlibraryX11
     Atom            NET_WM_BYPASS_COMPOSITOR;
     Atom            NET_ACTIVE_WINDOW;
     Atom            NET_FRAME_EXTENTS;
+    Atom            NET_REQUEST_FRAME_EXTENTS;
     Atom            MOTIF_WM_HINTS;
 
     // Xdnd (drag and drop) atoms

+ 32 - 0
src/x11_window.c

@@ -55,6 +55,17 @@ typedef struct
 #define MWM_HINTS_DECORATIONS (1L << 1)
 
 
+// Returns whether the event is a selection event
+//
+static Bool isFrameExtentsEvent(Display* display, XEvent* event, XPointer pointer)
+{
+    _GLFWwindow* window = (_GLFWwindow*) pointer;
+    return event->type == PropertyNotify &&
+           event->xproperty.state == PropertyNewValue &&
+           event->xproperty.window == window->x11.handle &&
+           event->xproperty.atom == _glfw.x11.NET_FRAME_EXTENTS;
+}
+
 // Translates an X event modifier state mask
 //
 static int translateState(int state)
@@ -360,6 +371,27 @@ static GLboolean createWindow(_GLFWwindow* window,
                         PropModeReplace, (unsigned char*) &version, 1);
     }
 
+    if (_glfw.x11.NET_REQUEST_FRAME_EXTENTS)
+    {
+        // Ensure _NET_FRAME_EXTENTS is set, allowing glfwGetWindowFrameSize to
+        // function before the window is mapped
+
+        XEvent event;
+        memset(&event, 0, sizeof(event));
+
+        event.type = ClientMessage;
+        event.xclient.window = window->x11.handle;
+        event.xclient.format = 32; // Data is 32-bit longs
+        event.xclient.message_type = _glfw.x11.NET_REQUEST_FRAME_EXTENTS;
+
+        XSendEvent(_glfw.x11.display,
+                   _glfw.x11.root,
+                   False,
+                   SubstructureNotifyMask | SubstructureRedirectMask,
+                   &event);
+        XIfEvent(_glfw.x11.display, &event, isFrameExtentsEvent, (XPointer) window);
+    }
+
     _glfwPlatformSetWindowTitle(window, wndconfig->title);
 
     XRRSelectInput(_glfw.x11.display, window->x11.handle,