diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 583b6aa5c..e006cf7a3 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -985,9 +985,22 @@ namespace hex { glfwWindowHint(GLFW_MAXIMIZED, initialWindowProperties->maximized); } + int monitorX, monitorY; + int monitorWidth = std::numeric_limits::max(), monitorHeight = std::numeric_limits::max(); + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + if (monitor != nullptr) { + const GLFWvidmode *mode = glfwGetVideoMode(monitor); + if (mode != nullptr) { + glfwGetMonitorPos(monitor, &monitorX, &monitorY); + + monitorWidth = mode->width; + monitorHeight = mode->height; + } + } + // Create window m_windowTitle = "ImHex"; - m_window = glfwCreateWindow(1280_scaled, 720_scaled, m_windowTitle.c_str(), nullptr, nullptr); + m_window = glfwCreateWindow(std::min(1280_scaled, monitorWidth - 50_scaled), std::min(720_scaled, monitorHeight - 50_scaled), m_windowTitle.c_str(), nullptr, nullptr); ImHexApi::System::impl::setMainWindowHandle(m_window); @@ -1007,18 +1020,11 @@ namespace hex { glfwSwapInterval(0); // Center window - GLFWmonitor *monitor = glfwGetPrimaryMonitor(); - if (monitor != nullptr) { - const GLFWvidmode *mode = glfwGetVideoMode(monitor); - if (mode != nullptr) { - int monitorX, monitorY; - glfwGetMonitorPos(monitor, &monitorX, &monitorY); + if (monitorWidth != std::numeric_limits::max() && monitorHeight != std::numeric_limits::max()) { + int windowWidth, windowHeight; + glfwGetWindowSize(m_window, &windowWidth, &windowHeight); - int windowWidth, windowHeight; - glfwGetWindowSize(m_window, &windowWidth, &windowHeight); - - glfwSetWindowPos(m_window, monitorX + (mode->width - windowWidth) / 2, monitorY + (mode->height - windowHeight) / 2); - } + glfwSetWindowPos(m_window, monitorX + (monitorWidth - windowWidth) / 2, monitorY + (monitorHeight - windowHeight) / 2); } // Set up initial window position @@ -1040,6 +1046,9 @@ namespace hex { int width = 0, height = 0; glfwGetWindowSize(m_window, &width, &height); + width = std::min(width, monitorWidth - int(50_scaled)); + height = std::min(height, monitorHeight - int(100_scaled)); + if (initialWindowProperties.has_value()) { width = initialWindowProperties->width; height = initialWindowProperties->height;