From 5867a43dc8ee16e4c87572fd86a4b8c12c7deae5 Mon Sep 17 00:00:00 2001 From: scorpion-26 <58082714+scorpion-26@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:44:50 +0200 Subject: [PATCH] Backends: GLFW: Honor GLFW_CURSOR_DISABLED by not setting mouse position. (#5625) --- backends/imgui_impl_glfw.cpp | 11 +++++++++++ docs/CHANGELOG.txt | 1 + 2 files changed, 12 insertions(+) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index 376b35ea..f52f7926 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -16,6 +16,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2022-09-01: Inputs: Honor GLFW_CURSOR_DISABLED by not setting mouse position. // 2022-04-30: Inputs: Fixed ImGui_ImplGlfw_TranslateUntranslatedKey() for lower case letters on OSX. // 2022-03-23: Inputs: Fixed a regression in 1.87 which resulted in keyboard modifiers events being reported incorrectly on Linux/X11. // 2022-02-07: Added ImGui_ImplGlfw_InstallCallbacks()/ImGui_ImplGlfw_RestoreCallbacks() helpers to facilitate user installing callbacks after initializing backend. @@ -356,6 +357,8 @@ void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y) ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); if (bd->PrevUserCallbackCursorPos != NULL && window == bd->Window) bd->PrevUserCallbackCursorPos(window, x, y); + if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) + return; ImGuiIO& io = ImGui::GetIO(); io.AddMousePosEvent((float)x, (float)y); @@ -369,6 +372,8 @@ void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered) ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); if (bd->PrevUserCallbackCursorEnter != NULL && window == bd->Window) bd->PrevUserCallbackCursorEnter(window, entered); + if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) + return; ImGuiIO& io = ImGui::GetIO(); if (entered) @@ -533,6 +538,12 @@ static void ImGui_ImplGlfw_UpdateMouseData() ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); ImGuiIO& io = ImGui::GetIO(); + if (glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) + { + io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); + return; + } + #ifdef __EMSCRIPTEN__ const bool is_app_focused = true; #else diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d8c92aee..3f9027a5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -96,6 +96,7 @@ Other Changes: to use the Item Picker in e.g. menus. (#2673) - Demo: Improved "Constrained-resizing window" example, more clearly showcase aspect-ratio. (#5627) - Demo: Added more explicit "Center window" mode to "Overlay example". (#5618) +- Backends: GLFW: Honor GLFW_CURSOR_DISABLED by not setting mouse position. (#5625) [@scorpion-26] - Backends: Metal: Use __bridge for ARC based systems. (#5403) [@stack] - Backends: Metal: Add dispatch synchronization. (#5447) [@luigifcruz] - Backends: Metal: Update deprecated property 'sampleCount'->'rasterSampleCount'. (#5603) [@dcvz]