From d19d812ccb1da400d38ee37a9091f2db8e49ff67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=A4llberg?= Date: Thu, 5 Oct 2023 08:39:53 +0200 Subject: [PATCH] impr: Don't force using discrete graphics card on macOS (#1341) ### Problem description When starting ImHex on a MacBook model with both integrated and discrete graphics, it will force the computer to use the discrete graphics card. This causes increased power usage, meaning the fans will spin up, the battery will drain faster, etc. This program is not very graphics intensive, so using the discrete graphics card shouldn't be needed. ### Implementation description I changed the [`GLFW_COCOA_GRAPHICS_SWITCHING`](https://www.glfw.org/docs/latest/window_guide.html#window_hints_osx) setting in GLFW to not enforce using the discrete graphics. ### Screenshots ### Additional things My editor is configured to automatically remove trailing whitespace, so I hope that those whitespace changes are ok --- main/gui/source/init/splash_window.cpp | 1 + main/gui/source/window/window.cpp | 5 +++-- resources/dist/macos/Info.plist.in | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/main/gui/source/init/splash_window.cpp b/main/gui/source/init/splash_window.cpp index d78bde129..cba9c0c15 100644 --- a/main/gui/source/init/splash_window.cpp +++ b/main/gui/source/init/splash_window.cpp @@ -320,6 +320,7 @@ namespace hex::init { glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE); + glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, GLFW_TRUE); #else glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 29a0c004c..b62b9d2df 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -282,7 +282,7 @@ namespace hex { if (ImGui::TitleBarButton(ICON_VS_CHROME_MAXIMIZE, buttonSize)) glfwMaximizeWindow(this->m_window); } - + ImGui::PushStyleColor(ImGuiCol_ButtonActive, 0xFF7A70F1); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, 0xFF2311E8); @@ -298,7 +298,7 @@ namespace hex { ImGui::SetCursorPosX(std::max(startX, (ImGui::GetWindowWidth() - ImGui::CalcTextSize(this->m_windowTitle.c_str()).x) / 2)); ImGui::TextUnformatted(this->m_windowTitle.c_str()); } - + void Window::drawTitleBarBorder() { auto titleBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight(); auto buttonSize = ImVec2(titleBarHeight * 1.5F, titleBarHeight - 1); @@ -805,6 +805,7 @@ namespace hex { glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE); + glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, GLFW_TRUE); #else glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); diff --git a/resources/dist/macos/Info.plist.in b/resources/dist/macos/Info.plist.in index 982e90679..942edcf8e 100644 --- a/resources/dist/macos/Info.plist.in +++ b/resources/dist/macos/Info.plist.in @@ -43,6 +43,8 @@ ${MACOSX_BUNDLE_BUNDLE_VERSION} CSResourcesFileMapped + NSSupportsAutomaticGraphicsSwitching + NSHumanReadableCopyright ${MACOSX_BUNDLE_COPYRIGHT}