Skip to content

Commit 59db6ce

Browse files
Clownacyocornut
authored andcommitted
Backends: GLFW: lower minimum requirement from GLFW 3.1 to GLFW 3.0. (#9055)
1 parent a0bfbe4 commit 59db6ce

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

backends/imgui_impl_glfw.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// dear imgui: Platform Backend for GLFW
22
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
33
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
4-
// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ or GLFW 3.4+ for full feature support.)
4+
// (Requires: GLFW 3.0+. Prefer GLFW 3.3+/3.4+ for full feature support.)
55

66
// Implemented features:
77
// [X] Platform: Clipboard support.
88
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
99
// [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]
1010
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
11-
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Resizing cursors requires GLFW 3.4+! Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
11+
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors) with GLFW 3.1+. Resizing cursors requires GLFW 3.4+! Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
1212
// [X] Multiple Dear ImGui contexts support.
1313
// Missing features or Issues:
1414
// [ ] Touch events are only correctly identified as Touch on Windows. This create issues with some interactions. GLFW doesn't provide a way to identify touch inputs from mouse inputs, we cannot call io.AddMouseSourceEvent() to identify the source. We provide a Windows-specific workaround.
@@ -29,6 +29,7 @@
2929

3030
// CHANGELOG
3131
// (minor and older changes stripped away, please see git history for details)
32+
// 2025-11-06: Lower minimum requirement to GLFW 3.0. Though a recent version e.g GLFW 3.4 is highly recommended.
3233
// 2025-09-18: Call platform_io.ClearPlatformHandlers() on shutdown.
3334
// 2025-09-15: Content Scales are always reported as 1.0 on Wayland. FramebufferScale are always reported as 1.0 on X11. (#8920, #8921)
3435
// 2025-07-08: Made ImGui_ImplGlfw_GetContentScaleForWindow(), ImGui_ImplGlfw_GetContentScaleForMonitor() helpers return 1.0f on Emscripten and Android platforms, matching macOS logic. (#8742, #8733)
@@ -152,6 +153,7 @@
152153
#else
153154
#define GLFW_HAS_NEW_CURSORS (0)
154155
#endif
156+
#define GLFW_HAS_CREATECURSOR (GLFW_VERSION_COMBINED >= 3100) // 3.1+ glfwCreateCursor()
155157
#define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetGamepadState() new api
156158
#define GLFW_HAS_GETKEYNAME (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwGetKeyName()
157159
#define GLFW_HAS_GETERROR (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetError()
@@ -182,7 +184,9 @@ struct ImGui_ImplGlfw_Data
182184
GlfwClientApi ClientApi;
183185
double Time;
184186
GLFWwindow* MouseWindow;
187+
#if GLFW_HAS_CREATECURSOR
185188
GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
189+
#endif
186190
ImVec2 LastValidMousePos;
187191
bool IsWayland;
188192
bool InstalledCallbacks;
@@ -653,7 +657,9 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
653657
snprintf(bd->BackendPlatformName, sizeof(bd->BackendPlatformName), "imgui_impl_glfw (%d)", GLFW_VERSION_COMBINED);
654658
io.BackendPlatformUserData = (void*)bd;
655659
io.BackendPlatformName = bd->BackendPlatformName;
660+
#if GLFW_HAS_CREATECURSOR
656661
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
662+
#endif
657663
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
658664

659665
bd->Context = ImGui::GetCurrentContext();
@@ -679,6 +685,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
679685
// (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist,
680686
// GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting.
681687
// Missing cursors will return nullptr and our _UpdateMouseCursor() function will use the Arrow cursor instead.)
688+
#if GLFW_HAS_CREATECURSOR
682689
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr);
683690
bd->MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
684691
bd->MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
@@ -697,6 +704,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
697704
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
698705
#endif
699706
glfwSetErrorCallback(prev_error_callback);
707+
#endif
700708
#if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908)
701709
(void)glfwGetError(nullptr);
702710
#endif
@@ -775,10 +783,10 @@ void ImGui_ImplGlfw_Shutdown()
775783
if (bd->CanvasSelector)
776784
emscripten_set_wheel_callback(bd->CanvasSelector, nullptr, false, nullptr);
777785
#endif
778-
786+
#if GLFW_HAS_CREATECURSOR
779787
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
780788
glfwDestroyCursor(bd->MouseCursors[cursor_n]);
781-
789+
#endif
782790
// Windows: restore our WndProc hook
783791
#ifdef _WIN32
784792
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
@@ -846,7 +854,9 @@ static void ImGui_ImplGlfw_UpdateMouseCursor()
846854
{
847855
// Show OS mouse cursor
848856
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
857+
#if GLFW_HAS_CREATECURSOR
849858
glfwSetCursor(window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
859+
#endif
850860
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
851861
}
852862
}

backends/imgui_impl_glfw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
88
// [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]
99
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
10-
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors). Resizing cursors requires GLFW 3.4+! Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
10+
// [X] Platform: Mouse cursor shape and visibility (ImGuiBackendFlags_HasMouseCursors) with GLFW 3.1+. Resizing cursors requires GLFW 3.4+! Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
1111
// [X] Multiple Dear ImGui contexts support.
1212
// Missing features or Issues:
1313
// [ ] Touch events are only correctly identified as Touch on Windows. This create issues with some interactions. GLFW doesn't provide a way to identify touch inputs from mouse inputs, we cannot call io.AddMouseSourceEvent() to identify the source. We provide a Windows-specific workaround.

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Other Changes:
8787
- Backends:
8888
- GLFW: fixed building on Linux platforms where Wayland headers
8989
are not available. (#9024, #8969, #8921, #8920) [@jagot]
90+
- GLFW: lower minimum requirement from GLFW 3.1 to GLFW 3.0. Though
91+
a recent version e.g GLFW 3.4 is highly recommended! (#9055) [@Clownacy]
9092
- SDL3: fixed Platform_OpenInShellFn() return value (the return value
9193
was unused in core but might be used by a direct caller). (#9027) [@achabense]
9294
- SDL3: fixed an issue with missing characters events when an already active text

0 commit comments

Comments
 (0)