Keep the window frame usable without a window manager

frame_has_native_operations() trusted the X11 accessors of GLFW alone, but a
window manager that does not advertise _NET_WM_MOVERESIZE drops the request
silently: on a plain X11 session the frame asked it to move and resize the
window and nothing happened at all. The root window is checked for the atom
now, and the frame falls back to moving and resizing the window itself.

The resize edges also win over the bar instead of the bar swallowing its top
strip, which made the top edge and the top corners impossible to grab.

Both backends log the active path as
"engine window frame: on, window manager operations are on|off".
This commit is contained in:
alexei-zebra 2026-10-10 15:51:32 +03:00
parent 56a225fe15
commit 7126158d68
No known key found for this signature in database
GPG key ID: D19D450AC3D9A80E
2 changed files with 64 additions and 13 deletions

View file

@ -1,6 +1,7 @@
#include "window/detail/FrameOperations.hpp"
#if defined(VOXEL_X11_FRAME)
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <dlfcn.h>
@ -38,6 +39,50 @@ namespace {
return api;
}
/// @brief Whether the window manager advertises _NET_WM_MOVERESIZE
///
/// Without it the request would be silently dropped, and the frame has to
/// move and resize the window itself. The answer is cached.
bool x11_supports_moveresize(Display* display) {
static int cached = -1;
if (cached >= 0) {
return cached == 1;
}
cached = 0;
const Atom supported = XInternAtom(display, "_NET_SUPPORTED", False);
const Atom moveresize =
XInternAtom(display, "_NET_WM_MOVERESIZE", False);
Atom type = 0;
int format = 0;
unsigned long count = 0, after = 0;
unsigned char* data = nullptr;
if (XGetWindowProperty(
display,
DefaultRootWindow(display),
supported,
0,
8192,
False,
XA_ATOM,
&type,
&format,
&count,
&after,
&data
) == Success &&
data != nullptr) {
const Atom* atoms = reinterpret_cast<const Atom*>(data);
for (unsigned long i = 0; i < count; i++) {
if (atoms[i] == moveresize) {
cached = 1;
break;
}
}
XFree(data);
}
return cached == 1;
}
/// @brief Edge mask to the _NET_WM_MOVERESIZE direction
int x11_direction(int edges) {
switch (edges) {
@ -70,7 +115,8 @@ namespace {
}
Display* display = api.display();
const Window window = api.window(glfwWindow);
if (display == nullptr || window == 0) {
if (display == nullptr || window == 0 ||
!x11_supports_moveresize(display)) {
return false;
}
const Window root = DefaultRootWindow(display);
@ -184,7 +230,8 @@ namespace {
bool frame_has_native_operations() {
#if defined(VOXEL_X11_FRAME)
return x11_api().available();
X11Api& api = x11_api();
return api.available() && x11_supports_moveresize(api.display());
#else
return false;
#endif

View file

@ -378,18 +378,18 @@ public:
) >= 0) {
return frame::Hit {};
}
if (y < height) {
return frame::Hit {true, 0};
// the resize edges win over the bar, its top strip resizes too
const int edges = frame::edgesAt(
getSize().x,
getSize().y,
height,
static_cast<float>(x),
static_cast<float>(y)
);
if (edges != 0) {
return frame::Hit {false, edges};
}
return frame::Hit {
false,
frame::edgesAt(
getSize().x,
getSize().y,
height,
static_cast<float>(x),
static_cast<float>(y)
)};
return frame::Hit {y < height, 0};
}
/// @brief Turns a pointer move into hovering, dragging or resizing
@ -919,6 +919,10 @@ std::tuple<
logger.info() << "windowing platform: " << get_platform_name();
const bool engineFrame = use_engine_frame();
logger.info() << "engine window frame: " << (engineFrame ? "on" : "off")
<< (engineFrame && frame_has_native_operations()
? ", window manager operations are on"
: "");
if (engineFrame) {
// the engine draws the window bar, the system frame must be gone
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);