From d0c1213ea0a0a3d5f934221086f6f5a13fc42a2a Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 25 Jan 2025 23:30:00 +0100 Subject: [PATCH] fix: Crash on systems where XDG_SESSION_TYPE isn't defined --- .../imgui/backend/source/imgui_impl_glfw.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/third_party/imgui/backend/source/imgui_impl_glfw.cpp b/lib/third_party/imgui/backend/source/imgui_impl_glfw.cpp index 19c40867e..0febd7b48 100644 --- a/lib/third_party/imgui/backend/source/imgui_impl_glfw.cpp +++ b/lib/third_party/imgui/backend/source/imgui_impl_glfw.cpp @@ -386,13 +386,23 @@ static void ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow* window, int mods) // IMHEX PATCH BEGIN ImGuiIO& io = ImGui::GetIO(); - static bool isX11 = std::string_view(std::getenv("XDG_SESSION_TYPE")) == "x11"; +#ifdef __linux__ + static bool isX11 = [] { + const auto sessionType = std::getenv("XDG_SESSION_TYPE"); + if (sessionType == nullptr) + return false; + + return std::string_view(sessionType) == "x11"; + }(); + if (isX11) { io.AddKeyEvent(ImGuiMod_Ctrl, (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)); io.AddKeyEvent(ImGuiMod_Shift, (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS)); io.AddKeyEvent(ImGuiMod_Alt, (glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS)); io.AddKeyEvent(ImGuiMod_Super, (glfwGetKey(window, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS)); - } else { + } else +#endif + { io.AddKeyEvent(ImGuiMod_Ctrl, (mods & GLFW_MOD_CONTROL) != 0); io.AddKeyEvent(ImGuiMod_Shift, (mods & GLFW_MOD_SHIFT) != 0); io.AddKeyEvent(ImGuiMod_Alt, (mods & GLFW_MOD_ALT) != 0);