Backends: GLFW: improve multi-viewport behavior in tiling WMs (X11) (#8884, #8474, #8289)

- Implement _NET_WM_WINDOW_TYPE_DIALOG for viewports
- Fix override_redirect for proper WM control
- Tested on i3wm and xfce4
This commit is contained in:
ikos3k
2025-08-13 17:18:58 +02:00
committed by ocornut
parent 3dcd17f402
commit 6b2cdf29bc
2 changed files with 39 additions and 2 deletions

View File

@@ -127,6 +127,16 @@
#define GLFW_EXPOSE_NATIVE_COCOA
#endif
#include <GLFW/glfw3native.h> // for glfwGetCocoaWindow()
#elif !defined(__EMSCRIPTEN__)
// Freedesktop(Linux, BSD, etc)
#ifndef GLFW_EXPOSE_NATIVE_X11
#define GLFW_EXPOSE_NATIVE_X11
#include <X11/Xatom.h>
#endif
#ifndef GLFW_EXPOSE_NATIVE_WAYLAND
#define GLFW_EXPOSE_NATIVE_WAYLAND
#endif
#include <GLFW/glfw3native.h> // for getting the X11/Wayland window
#endif
#ifndef _WIN32
#include <unistd.h> // for usleep()
@@ -1190,6 +1200,30 @@ static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
}
}
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(__EMSCRIPTEN__) && (GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4))
static void ImGui_ImplGlfw_SetWindowFloating(GLFWwindow* window)
{
#ifdef GLFW_EXPOSE_NATIVE_X11
if (glfwGetPlatform() == GLFW_PLATFORM_X11)
{
Display* display = glfwGetX11Display();
Window xwindow = glfwGetX11Window(window);
Atom wm_type = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
Atom wm_type_dialog = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
XChangeProperty(display, xwindow, wm_type, XA_ATOM, 32,
PropModeReplace, (unsigned char*)&wm_type_dialog, 1);
XSetWindowAttributes attrs;
attrs.override_redirect = False;
XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &attrs);
XFlush(display);
}
#endif
}
#endif
static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
{
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
@@ -1217,6 +1251,9 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
vd->WindowOwned = true;
ImGui_ImplGlfw_ContextMap_Add(vd->Window, bd->Context);
viewport->PlatformHandle = (void*)vd->Window;
#if !defined(__APPLE__) && !defined(_WIN31) && !defined(__EMSCRIPTEN__) && (GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4))
ImGui_ImplGlfw_SetWindowFloating(vd->Window);
#endif
#ifdef _WIN32
viewport->PlatformHandleRaw = glfwGetWin32Window(vd->Window);
::SetPropA((HWND)viewport->PlatformHandleRaw, "IMGUI_BACKEND_DATA", bd);

View File

@@ -41,7 +41,7 @@ LIBS =
ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
LIBS += $(LINUX_GL_LIBS) `pkg-config --static --libs glfw3`
LIBS += $(LINUX_GL_LIBS) -lX11 `pkg-config --static --libs glfw3`
CXXFLAGS += `pkg-config --cflags glfw3`
CFLAGS = $(CXXFLAGS)