diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index 56bcbcd21..347525f6f 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -112,6 +112,8 @@ namespace hex { void setGlobalScale(float scale); void setProgramArguments(int argc, char **argv, char **envp); + + void setBorderlessWindowMode(bool enabled); } struct ProgramArguments { @@ -131,6 +133,8 @@ namespace hex { ImVec2 getMainWindowSize(); ImGuiID getMainDockSpaceId(); + bool isBorderlessWindowModeEnabled(); + std::map &getInitArguments(); } diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index b76f0275d..c324a6edd 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -189,6 +189,11 @@ namespace hex { s_programArguments.envp = envp; } + static bool s_borderlessWindowMode; + void setBorderlessWindowMode(bool enabled) { + s_borderlessWindowMode = enabled; + } + } @@ -225,6 +230,10 @@ namespace hex { return impl::s_mainDockSpaceId; } + bool isBorderlessWindowModeEnabled() { + return impl::s_borderlessWindowMode; + } + std::map &getInitArguments() { static std::map initArgs; diff --git a/main/include/window.hpp b/main/include/window.hpp index 9f3636f43..ee6efbf51 100644 --- a/main/include/window.hpp +++ b/main/include/window.hpp @@ -16,7 +16,7 @@ namespace hex { class Window { public: - Window(bool borderlessWindow); + Window(); ~Window(); void loop(); @@ -52,8 +52,6 @@ namespace hex { std::list m_popupsToOpen; std::vector m_pressedKeys; - - bool m_useBorderlessWindow = false; }; } \ No newline at end of file diff --git a/main/source/main.cpp b/main/source/main.cpp index dae4578ae..d9dfe3b64 100644 --- a/main/source/main.cpp +++ b/main/source/main.cpp @@ -14,10 +14,9 @@ int main(int argc, char **argv, char **envp) { using namespace hex; ImHexApi::System::impl::setProgramArguments(argc, argv, envp); - bool useBorderlessWindow = false; #if defined(OS_WINDOWS) - useBorderlessWindow = true; + ImHexApi::System::impl::setBorderlessWindowMode(true); #endif // Initialization @@ -28,13 +27,21 @@ int main(int argc, char **argv, char **envp) { init::WindowSplash splashWindow; + // Intel's OpenGL driver has weird bugs that cause the drawn window to be offset to the bottom right. + // This can be fixed by either using Mesa3D's OpenGL Software renderer or by simply disabling it. + // If you want to try if it works anyways on your GPU, set the hex.builtin.setting.interface.force_borderless_window_mode setting to 1 + + bool isIntelGPU = hex::containsIgnoreCase(splashWindow.getGPUVendor(), "Intel"); + ImHexApi::System::impl::setBorderlessWindowMode(!isIntelGPU); + + if (isIntelGPU) + log::warn("Intel GPU detected! Intel's OpenGL driver has bugs that can cause issues when using ImHex. If you experience any rendering bugs, please try the Mesa3D Software Renderer"); + for (const auto &[name, task] : init::getInitTasks()) splashWindow.addStartupTask(name, task); if (!splashWindow.loop()) ImHexApi::System::getInitArguments().insert({ "tasks-failed", {} }); - - useBorderlessWindow = !hex::containsIgnoreCase(splashWindow.getGPUVendor(), "Intel"); } // Clean up @@ -45,7 +52,7 @@ int main(int argc, char **argv, char **envp) { // Main window { - Window window(useBorderlessWindow); + Window window; if (argc == 1) ; // No arguments provided diff --git a/main/source/window/win_window.cpp b/main/source/window/win_window.cpp index 144c78844..f154b4c8a 100644 --- a/main/source/window/win_window.cpp +++ b/main/source/window/win_window.cpp @@ -241,7 +241,7 @@ namespace hex { // Setup borderless window auto hwnd = glfwGetWin32Window(this->m_window); - if (this->m_useBorderlessWindow) { + if (ImHexApi::System::isBorderlessWindowModeEnabled()) { g_oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)windowProc); MARGINS borderless = { 1, 1, 1, 1 }; @@ -300,7 +300,7 @@ namespace hex { } void Window::drawTitleBar() { - if (!this->m_useBorderlessWindow) return; + if (!ImHexApi::System::isBorderlessWindowModeEnabled()) return; auto buttonSize = ImVec2(g_titleBarHeight * 1.5F, g_titleBarHeight - 1); diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index e36346957..0db3fe0b2 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -71,7 +71,7 @@ namespace hex { buf->append("\n"); } - Window::Window(bool borderlessWindow) : m_useBorderlessWindow(borderlessWindow) { + Window::Window() { { for (const auto &[argument, value] : ImHexApi::System::getInitArguments()) { if (argument == "no-plugins") { @@ -289,7 +289,7 @@ namespace hex { ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); if (ImGui::BeginMainMenuBar()) { - if (this->m_useBorderlessWindow) { + if (ImHexApi::System::isBorderlessWindowModeEnabled()) { auto menuBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight(); ImGui::SetCursorPosX(5); ImGui::Image(this->m_logoTexture, ImVec2(menuBarHeight, menuBarHeight)); @@ -501,7 +501,7 @@ namespace hex { glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #endif - glfwWindowHint(GLFW_DECORATED, this->m_useBorderlessWindow ? GL_FALSE : GL_TRUE); + glfwWindowHint(GLFW_DECORATED, ImHexApi::System::isBorderlessWindowModeEnabled() ? GL_FALSE : GL_TRUE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); diff --git a/plugins/windows/source/plugin_windows.cpp b/plugins/windows/source/plugin_windows.cpp index 2ddc5349d..c011ec16d 100644 --- a/plugins/windows/source/plugin_windows.cpp +++ b/plugins/windows/source/plugin_windows.cpp @@ -43,6 +43,13 @@ static void detectSystemTheme() { }); } +static void checkBorderlessWindowOverride() { + bool borderlessWindowForced = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.force_borderless_window_mode", 0) != 0; + + if (borderlessWindowForced) + ImHexApi::System::impl::setBorderlessWindowMode(true); +} + IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") { using namespace hex::plugin::windows; @@ -57,4 +64,5 @@ IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") { registerSettings(); detectSystemTheme(); + checkBorderlessWindowOverride(); }