1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-09 23:54:20 +00:00

Backends: GLFW: avoid repeated glfwSetCursor()/glfwSetInputMode() calls when unnecessary.

This commit is contained in:
ocornut 2025-12-10 18:35:22 +01:00
parent cf64b7fa72
commit 9a4fd69f6d
2 changed files with 16 additions and 3 deletions

View file

@ -29,6 +29,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2025-12-10: Avoid repeated glfwSetCursor()/glfwSetInputMode() calls when unnecessary. Lowers overhead for very high framerates (e.g. 10k+ FPS).
// 2025-11-06: Lower minimum requirement to GLFW 3.0. Though a recent version e.g GLFW 3.4 is highly recommended.
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
// 2025-09-15: Content Scales are always reported as 1.0 on Wayland. FramebufferScale are always reported as 1.0 on X11. (#8920, #8921)
@ -188,6 +189,7 @@ struct ImGui_ImplGlfw_Data
GLFWwindow* MouseWindow;
#if GLFW_HAS_CREATECURSOR
GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
GLFWcursor* LastMouseCursor;
#endif
ImVec2 LastValidMousePos;
bool IsWayland;
@ -849,15 +851,24 @@ static void ImGui_ImplGlfw_UpdateMouseCursor()
GLFWwindow* window = bd->Window;
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
{
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
if (bd->LastMouseCursor != nullptr)
{
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
bd->LastMouseCursor = nullptr;
}
}
else
{
// Show OS mouse cursor
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
#if GLFW_HAS_CREATECURSOR
glfwSetCursor(window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
GLFWcursor* cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
if (bd->LastMouseCursor != cursor)
{
glfwSetCursor(window, cursor);
bd->LastMouseCursor = cursor;
}
#endif
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}