|  | 
| 6 | 6 | // Implemented features: | 
| 7 | 7 | //  [X] Platform: Clipboard support. | 
| 8 | 8 | //  [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only). | 
| 9 |  | -//  [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] | 
|  | 9 | +//  [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values are obsolete since 1.87 and not supported since 1.91.5] | 
| 10 | 10 | //  [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. | 
| 11 | 11 | //  [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). | 
| 12 | 12 | //  [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. | 
|  | 
| 29 | 29 | // CHANGELOG | 
| 30 | 30 | // (minor and older changes stripped away, please see git history for details) | 
| 31 | 31 | //  2024-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. | 
|  | 32 | +//  2024-11-05: [Docking] Added Linux workaround for spurious mouse up events emitted while dragging and creating new viewport. (#3158, #7733, #7922) | 
| 32 | 33 | //  2024-08-22: moved some OS/backend related function pointers from ImGuiIO to ImGuiPlatformIO: | 
| 33 | 34 | //               - io.GetClipboardTextFn    -> platform_io.Platform_GetClipboardTextFn | 
| 34 | 35 | //               - io.SetClipboardTextFn    -> platform_io.Platform_SetClipboardTextFn | 
| @@ -172,6 +173,8 @@ struct ImGui_ImplGlfw_Data | 
| 172 | 173 |     double                  Time; | 
| 173 | 174 |     GLFWwindow*             MouseWindow; | 
| 174 | 175 |     GLFWcursor*             MouseCursors[ImGuiMouseCursor_COUNT]; | 
|  | 176 | +    bool                    MouseIgnoreButtonUpWaitForFocusLoss; | 
|  | 177 | +    bool                    MouseIgnoreButtonUp; | 
| 175 | 178 |     ImVec2                  LastValidMousePos; | 
| 176 | 179 |     GLFWwindow*             KeyOwnerWindows[GLFW_KEY_LAST]; | 
| 177 | 180 |     bool                    InstalledCallbacks; | 
| @@ -220,6 +223,7 @@ static void ImGui_ImplGlfw_ShutdownMultiViewportSupport(); | 
| 220 | 223 | ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int keycode, int scancode); | 
| 221 | 224 | 
 | 
| 222 | 225 | // Not static to allow third-party code to use that if they want to (but undocumented) | 
|  | 226 | +ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int keycode, int scancode); | 
| 223 | 227 | ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int keycode, int scancode) | 
| 224 | 228 | { | 
| 225 | 229 |     IM_UNUSED(scancode); | 
| @@ -369,6 +373,10 @@ void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int acti | 
| 369 | 373 |     if (bd->PrevUserCallbackMousebutton != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window)) | 
| 370 | 374 |         bd->PrevUserCallbackMousebutton(window, button, action, mods); | 
| 371 | 375 | 
 | 
|  | 376 | +    // Workaround for Linux: ignore mouse up events which are following an focus loss following a viewport creation | 
|  | 377 | +    if (bd->MouseIgnoreButtonUp && action == GLFW_RELEASE) | 
|  | 378 | +        return; | 
|  | 379 | + | 
| 372 | 380 |     ImGui_ImplGlfw_UpdateKeyModifiers(window); | 
| 373 | 381 | 
 | 
| 374 | 382 |     ImGuiIO& io = ImGui::GetIO(); | 
| @@ -453,6 +461,10 @@ void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused) | 
| 453 | 461 |     if (bd->PrevUserCallbackWindowFocus != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window)) | 
| 454 | 462 |         bd->PrevUserCallbackWindowFocus(window, focused); | 
| 455 | 463 | 
 | 
|  | 464 | +    // Workaround for Linux: when losing focus with MouseIgnoreButtonUpWaitForFocusLoss set, we will temporarily ignore subsequent Mouse Up events | 
|  | 465 | +    bd->MouseIgnoreButtonUp = (bd->MouseIgnoreButtonUpWaitForFocusLoss && focused == 0); | 
|  | 466 | +    bd->MouseIgnoreButtonUpWaitForFocusLoss = false; | 
|  | 467 | + | 
| 456 | 468 |     ImGuiIO& io = ImGui::GetIO(); | 
| 457 | 469 |     io.AddFocusEvent(focused != 0); | 
| 458 | 470 | } | 
| @@ -967,6 +979,7 @@ void ImGui_ImplGlfw_NewFrame() | 
| 967 | 979 |     io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f); | 
| 968 | 980 |     bd->Time = current_time; | 
| 969 | 981 | 
 | 
|  | 982 | +    bd->MouseIgnoreButtonUp = false; | 
| 970 | 983 |     ImGui_ImplGlfw_UpdateMouseData(); | 
| 971 | 984 |     ImGui_ImplGlfw_UpdateMouseCursor(); | 
| 972 | 985 | 
 | 
| @@ -1106,6 +1119,11 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport) | 
| 1106 | 1119 |     ImGui_ImplGlfw_ViewportData* vd = IM_NEW(ImGui_ImplGlfw_ViewportData)(); | 
| 1107 | 1120 |     viewport->PlatformUserData = vd; | 
| 1108 | 1121 | 
 | 
|  | 1122 | +    // Workaround for Linux: ignore mouse up events corresponding to losing focus of the previously focused window (#7733, #3158, #7922) | 
|  | 1123 | +#ifdef __linux__ | 
|  | 1124 | +    bd->MouseIgnoreButtonUpWaitForFocusLoss = true; | 
|  | 1125 | +#endif | 
|  | 1126 | + | 
| 1109 | 1127 |     // GLFW 3.2 unfortunately always set focus on glfwCreateWindow() if GLFW_VISIBLE is set, regardless of GLFW_FOCUSED | 
| 1110 | 1128 |     // With GLFW 3.3, the hint GLFW_FOCUS_ON_SHOW fixes this problem | 
| 1111 | 1129 |     glfwWindowHint(GLFW_VISIBLE, false); | 
|  | 
0 commit comments