cabana: remove custom focus-loss handling (#38884)

* cabana: fix focus handling across docked and floating windows

* cabana: remove custom focus-loss handling
This commit is contained in:
Trey Moen
2026-09-12 22:45:32 -07:00
committed by GitHub
parent 4c0799eb8e
commit 44914a7cf4
-32
View File
@@ -28,36 +28,6 @@ void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods
ImGui_ImplGlfw_KeyCallback(window, key, scancode, action, mods);
if (action == GLFW_PRESS) g_key_events.push_back({key, mods});
}
// imgui releases every mouse button when the window loses focus, which aborts a panel tear-off drag and
// docks the panel back. X11 keeps delivering the drag through the implicit grab, so hold a focus loss back
// while a button is down and deliver it after the release (see deliverPendingFocusLoss).
GLFWwindow *g_focus_lost_window = nullptr;
// macOS drops the button on its own when the focus moves, and holding the loss back there swallowed the
// first click in a popup: the click makes the popup's window key, the main window's loss lands on the
// release and imgui clears its mouse state before it sees that release
void windowFocusCallback(GLFWwindow *w, int f) {
#ifdef __APPLE__
ImGui_ImplGlfw_WindowFocusCallback(w, f);
#else
if (f) {
g_focus_lost_window = nullptr;
ImGui_ImplGlfw_WindowFocusCallback(w, f);
} else {
g_focus_lost_window = w;
}
#endif
}
bool anyMouseButtonDown(GLFWwindow *w) {
for (int b = GLFW_MOUSE_BUTTON_1; b <= GLFW_MOUSE_BUTTON_LAST; ++b) {
if (glfwGetMouseButton(w, b) == GLFW_PRESS) return true;
}
return false;
}
void deliverPendingFocusLoss() {
if (g_focus_lost_window == nullptr || anyMouseButtonDown(g_focus_lost_window)) return;
ImGui_ImplGlfw_WindowFocusCallback(g_focus_lost_window, GLFW_FALSE);
g_focus_lost_window = nullptr;
}
void hookViewportCallbacks() {
for (ImGuiViewport *viewport : ImGui::GetPlatformIO().Viewports) {
@@ -89,7 +59,6 @@ void paceFrame() {
void renderFrame(GLFWwindow *window, MainWindow *win) {
glfwPollEvents();
deliverPendingFocusLoss();
utils::drainMainThreadQueue();
int fb_w = 0, fb_h = 0;
@@ -175,7 +144,6 @@ public:
throw std::runtime_error("ImGui_ImplGlfw_InitForOpenGL failed");
}
glfwSetKeyCallback(window, keyCallback);
glfwSetWindowFocusCallback(window, windowFocusCallback);
if (!ImGui_ImplOpenGL3_Init("#version 330")) {
ImGui_ImplGlfw_Shutdown();
ImPlot::DestroyContext();