1
0
mirror of synced 2024-11-28 01:20:51 +01:00

sys: Automatically disable borderless window mode if Intel CPU is used

This commit is contained in:
WerWolv 2022-02-15 22:36:36 +01:00
parent adfaa95149
commit 4357d68462
6 changed files with 39 additions and 18 deletions

View File

@ -23,6 +23,8 @@ namespace hex::init {
this->m_tasks.emplace_back(taskName, task);
}
const std::string &getGPUVendor() const { return this->m_gpuVendor; }
private:
GLFWwindow *m_window;
std::mutex m_progressMutex;
@ -38,6 +40,8 @@ namespace hex::init {
std::future<bool> processTasksAsync();
std::vector<std::pair<std::string, TaskFunction>> m_tasks;
std::string m_gpuVendor;
};
}

View File

@ -16,7 +16,7 @@ namespace hex {
class Window {
public:
Window();
Window(bool borderlessWindow);
~Window();
void loop();
@ -46,12 +46,14 @@ namespace hex {
std::string m_windowTitle;
double m_lastFrameTime;
double m_lastFrameTime = 0;
ImGui::Texture m_logoTexture = { 0 };
ImGui::Texture m_logoTexture = { nullptr };
std::list<std::string> m_popupsToOpen;
std::vector<int> m_pressedKeys;
bool m_useBorderlessWindow = false;
};
}

View File

@ -29,6 +29,8 @@ namespace hex::init {
WindowSplash::WindowSplash() : m_window(nullptr) {
this->initGLFW();
this->initImGui();
this->m_gpuVendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
}
WindowSplash::~WindowSplash() {

View File

@ -14,6 +14,12 @@ 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;
#endif
// Initialization
{
Window::initNative();
@ -27,6 +33,8 @@ int main(int argc, char **argv, char **envp) {
if (!splashWindow.loop())
ImHexApi::System::getInitArguments().insert({ "tasks-failed", {} });
useBorderlessWindow = !hex::containsIgnoreCase(splashWindow.getGPUVendor(), "Intel");
}
// Clean up
@ -37,7 +45,7 @@ int main(int argc, char **argv, char **envp) {
// Main window
{
Window window;
Window window(useBorderlessWindow);
if (argc == 1)
; // No arguments provided

View File

@ -241,16 +241,18 @@ namespace hex {
// Setup borderless window
auto hwnd = glfwGetWin32Window(this->m_window);
g_oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)windowProc);
if (this->m_useBorderlessWindow) {
g_oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)windowProc);
MARGINS borderless = { 1, 1, 1, 1 };
::DwmExtendFrameIntoClientArea(hwnd, &borderless);
MARGINS borderless = { 1, 1, 1, 1 };
::DwmExtendFrameIntoClientArea(hwnd, &borderless);
DWORD attribute = DWMNCRP_ENABLED;
::DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &attribute, sizeof(attribute));
DWORD attribute = DWMNCRP_ENABLED;
::DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &attribute, sizeof(attribute));
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE);
::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW);
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE);
::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW);
}
// Setup system theme change detector
bool themeFollowSystem = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color") == 0;
@ -318,6 +320,8 @@ namespace hex {
}
void Window::drawTitleBar() {
if (!this->m_useBorderlessWindow) return;
auto buttonSize = ImVec2(g_titleBarHeight * 1.5F, g_titleBarHeight - 1);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));

View File

@ -71,7 +71,7 @@ namespace hex {
buf->append("\n");
}
Window::Window() {
Window::Window(bool borderlessWindow) : m_useBorderlessWindow(borderlessWindow) {
{
for (const auto &[argument, value] : ImHexApi::System::getInitArguments()) {
if (argument == "no-plugins") {
@ -288,9 +288,11 @@ namespace hex {
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
if (ImGui::BeginMainMenuBar()) {
auto menuBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
ImGui::SetCursorPosX(5);
ImGui::Image(this->m_logoTexture, ImVec2(menuBarHeight, menuBarHeight));
if (this->m_useBorderlessWindow) {
auto menuBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
ImGui::SetCursorPosX(5);
ImGui::Image(this->m_logoTexture, ImVec2(menuBarHeight, menuBarHeight));
}
for (const auto &[priority, menuItem] : ContentRegistry::Interface::getMainMenuItems()) {
if (ImGui::BeginMenu(LangEntry(menuItem.unlocalizedName))) {
@ -494,12 +496,11 @@ namespace hex {
std::abort();
}
#if defined(OS_WINDOWS)
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
#elif defined(OS_MACOS)
#if defined(OS_MACOS)
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
glfwWindowHint(GLFW_DECORATED, this->m_useBorderlessWindow ? GL_FALSE : GL_TRUE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);