Skip to content

Commit 37b18ac

Browse files
committed
Backends: GLFW: improve multi-viewport behavior in tiling WMs (X11). Amends. (#8884, #8474, #8289)
1 parent 6b2cdf2 commit 37b18ac

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

backends/imgui_impl_glfw.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// CHANGELOG
3333
// (minor and older changes stripped away, please see git history for details)
3434
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
35+
// 2025-09-10: [Docking] Improve multi-viewport behavior in tiling WMs on X11 via the ImGui_ImplGlfw_SetWindowFloating() function. Note: using GLFW backend on Linux/BSD etc. requires linking with -lX11. (#8884, #8474, #8289)
3536
// 2025-07-08: Made ImGui_ImplGlfw_GetContentScaleForWindow(), ImGui_ImplGlfw_GetContentScaleForMonitor() helpers return 1.0f on Emscripten and Android platforms, matching macOS logic. (#8742, #8733)
3637
// 2025-06-18: Added support for multiple Dear ImGui contexts. (#8676, #8239, #8069)
3738
// 2025-06-11: Added ImGui_ImplGlfw_GetContentScaleForWindow(GLFWwindow* window) and ImGui_ImplGlfw_GetContentScaleForMonitor(GLFWmonitor* monitor) helper to facilitate making DPI-aware apps.
@@ -121,14 +122,13 @@
121122
#define GLFW_EXPOSE_NATIVE_WIN32
122123
#endif
123124
#include <GLFW/glfw3native.h> // for glfwGetWin32Window()
124-
#endif
125-
#ifdef __APPLE__
125+
#elif defined(__APPLE__)
126126
#ifndef GLFW_EXPOSE_NATIVE_COCOA
127127
#define GLFW_EXPOSE_NATIVE_COCOA
128128
#endif
129129
#include <GLFW/glfw3native.h> // for glfwGetCocoaWindow()
130130
#elif !defined(__EMSCRIPTEN__)
131-
// Freedesktop(Linux, BSD, etc)
131+
// Freedesktop (Linux, BSD, etc)
132132
#ifndef GLFW_EXPOSE_NATIVE_X11
133133
#define GLFW_EXPOSE_NATIVE_X11
134134
#include <X11/Xatom.h>
@@ -183,7 +183,7 @@
183183
#define GLFW_HAS_GETERROR (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetError()
184184
#define GLFW_HAS_GETPLATFORM (GLFW_VERSION_COMBINED >= 3400) // 3.4+ glfwGetPlatform()
185185

186-
// Map GLFWWindow* to ImGuiContext*.
186+
// Map GLFWWindow* to ImGuiContext*.
187187
// - Would be simpler if we could use glfwSetWindowUserPointer()/glfwGetWindowUserPointer(), but this is a single and shared resource.
188188
// - Would be simpler if we could use e.g. std::map<> as well. But we don't.
189189
// - This is not particularly optimized as we expect size to be small and queries to be rare.
@@ -1200,29 +1200,29 @@ static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
12001200
}
12011201
}
12021202

1203-
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(__EMSCRIPTEN__) && (GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4))
1203+
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(__EMSCRIPTEN__) && GLFW_HAS_GETPLATFORM
1204+
#define IMGUI_GLFW_HAS_SETWINDOWFLOATING
12041205
static void ImGui_ImplGlfw_SetWindowFloating(GLFWwindow* window)
12051206
{
12061207
#ifdef GLFW_EXPOSE_NATIVE_X11
12071208
if (glfwGetPlatform() == GLFW_PLATFORM_X11)
12081209
{
12091210
Display* display = glfwGetX11Display();
12101211
Window xwindow = glfwGetX11Window(window);
1211-
12121212
Atom wm_type = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
12131213
Atom wm_type_dialog = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
1214-
XChangeProperty(display, xwindow, wm_type, XA_ATOM, 32,
1215-
PropModeReplace, (unsigned char*)&wm_type_dialog, 1);
1216-
1214+
XChangeProperty(display, xwindow, wm_type, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wm_type_dialog, 1);
12171215
XSetWindowAttributes attrs;
12181216
attrs.override_redirect = False;
12191217
XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &attrs);
1220-
12211218
XFlush(display);
12221219
}
1223-
#endif
1220+
#endif // GLFW_EXPOSE_NATIVE_X11
1221+
#ifdef GLFW_EXPOSE_NATIVE_WAYLAND
1222+
// FIXME: Help needed, see #8884, #8474 for discussions about this.
1223+
#endif // GLFW_EXPOSE_NATIVE_X11
12241224
}
1225-
#endif
1225+
#endif // IMGUI_GLFW_HAS_SETWINDOWFLOATING
12261226

12271227
static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
12281228
{
@@ -1251,7 +1251,7 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
12511251
vd->WindowOwned = true;
12521252
ImGui_ImplGlfw_ContextMap_Add(vd->Window, bd->Context);
12531253
viewport->PlatformHandle = (void*)vd->Window;
1254-
#if !defined(__APPLE__) && !defined(_WIN31) && !defined(__EMSCRIPTEN__) && (GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4))
1254+
#ifdef IMGUI_GLFW_HAS_SETWINDOWFLOATING
12551255
ImGui_ImplGlfw_SetWindowFloating(vd->Window);
12561256
#endif
12571257
#ifdef _WIN32

docs/CHANGELOG.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ Other Changes:
9494
- Backends: Vulkan: added ImGui_ImplVulkan_CreateMainPipeline() to recreate pipeline
9595
without reinitializing backend. (#8110, #8111) [@SuperRonan]
9696

97+
Docking+Viewports Branch:
98+
99+
- Backends: GLFW: improve multi-viewport behavior in tiling WMs on X11.
100+
Note: using GLFW backend on Linux/BSD etc. requires linking with `-lX11`.
101+
(#8884, #8474, #8289) [@Ikos3k, @Madman10K]
102+
97103

98104
-----------------------------------------------------------------------
99105
VERSION 1.92.2b (Released 2025-08-13)

examples/example_glfw_opengl2/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui
2121
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl2.cpp
2222
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
2323
UNAME_S := $(shell uname -s)
24+
LINUX_GL_LIBS = -lGL
2425

2526
CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
2627
CXXFLAGS += -g -Wall -Wformat
@@ -32,7 +33,7 @@ LIBS =
3233

3334
ifeq ($(UNAME_S), Linux) #LINUX
3435
ECHO_MESSAGE = "Linux"
35-
LIBS += -lGL `pkg-config --static --libs glfw3`
36+
LIBS += $(LINUX_GL_LIBS) -lX11 `pkg-config --static --libs glfw3`
3637

3738
CXXFLAGS += `pkg-config --cflags glfw3`
3839
CFLAGS = $(CXXFLAGS)

examples/example_glfw_vulkan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ find_package(Vulkan REQUIRED)
3636
#NAMES vulkan vulkan-1)
3737
#set(LIBRARIES "glfw;${VULKAN_LIBRARY}")
3838
set(LIBRARIES "glfw;Vulkan::Vulkan")
39+
# FIXME: Linux needs linking with "X11" as well?
3940

4041
# Use vulkan headers from glfw:
4142
include_directories(${GLFW_DIR}/deps)

examples/example_glfw_vulkan/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LIBS =
3333

3434
ifeq ($(UNAME_S), Linux) #LINUX
3535
ECHO_MESSAGE = "Linux"
36-
LIBS += $(LINUX_GL_LIBS) `pkg-config --static --libs glfw3 vulkan`
36+
LIBS += $(LINUX_GL_LIBS) -lX11 `pkg-config --static --libs glfw3 vulkan`
3737

3838
CXXFLAGS += `pkg-config --cflags glfw3 vulkan`
3939
CFLAGS = $(CXXFLAGS)

0 commit comments

Comments
 (0)