From 4164a755b156fcc7c16f0874d393a322fe2f9133 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 22 Aug 2022 18:56:11 -0400 Subject: [PATCH] game: fix transition from fullscreen (not borderless) to windowed (#1786) * scripts: remove references to non-existent script * game: fix transition from fullscreen (not borderless) to windowed * game: ensure window is position away from the corner of the display when switching from fullscreen --- Taskfile.yml | 10 -------- game/graphics/pipelines/opengl.cpp | 39 ++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 5a51a5dfb0..2d0d4b4faf 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -98,16 +98,6 @@ tasks: offline-tests: cmds: - '{{.OFFLINETEST_BIN_RELEASE_DIR}}/offline-test --iso_data_path "./iso_data/{{.GAME}}" --game {{.GAME}}' - # TODO - update or replace - # add-reference-test: - # cmds: - # - task: decomp-file - # - python ./scripts/add-reference-test.py --file "{{.FILES}}" - # - task: offline-tests - # add-reference-test-no-decomp: - # cmds: - # - python ./scripts/add-reference-test.py --file "{{.FILES}}" - # - task: offline-tests update-ref-tests: cmds: - cmd: python ./scripts/tasks/default-file-or-folder.py --path failures diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index 3f026299cd..b8527286d1 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -536,6 +536,7 @@ void GLDisplay::update_fullscreen(GfxDisplayMode mode, int screen) { switch (mode) { case GfxDisplayMode::Windowed: { // windowed + // TODO - display mode doesn't re-position the window int x, y, width, height; if (m_last_fullscreen_mode == GfxDisplayMode::Windowed) { @@ -544,33 +545,43 @@ void GLDisplay::update_fullscreen(GfxDisplayMode mode, int screen) { height = m_last_windowed_height; x = m_last_windowed_xpos; y = m_last_windowed_ypos; + lg::debug("Windowed -> Windowed - x:{} | y:{}", x, y); } else { - // fullscreen -> windowed, use last windowed size but on the monitor previously - // fullscreened + // fullscreen -> windowed, use last windowed size but on the monitor previously fullscreened + // + // glfwGetMonitorWorkarea will return the width/height of the scaled fullscreen window + // - for example, you full screened a 1280x720 game on a 4K monitor -- you won't get the 4k + // resolution! + // + // Additionally, the coordinates for the top left seem very weird in stacked displays (you + // get a negative Y coordinate) int monitorX, monitorY, monitorWidth, monitorHeight; glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight); width = m_last_windowed_width; height = m_last_windowed_height; - x = monitorX + (monitorWidth / 2) - (width / 2); - y = monitorY + (monitorHeight / 2) - (height / 2); + if (monitorX < 0) { + x = monitorX - 50; + } else { + x = monitorX + 50; + } + if (monitorY < 0) { + y = monitorY - 50; + } else { + y = monitorY + 50; + } + lg::debug("FS -> Windowed screen: {} - x:{}:{}/{} | y:{}:{}/{}", screen, monitorX, x, width, + monitorY, y, height); } glfwSetWindowAttrib(m_window, GLFW_DECORATED, GLFW_TRUE); glfwSetWindowFocusCallback(m_window, NULL); glfwSetWindowAttrib(m_window, GLFW_FLOATING, GLFW_FALSE); - glfwSetWindowMonitor(m_window, NULL, x, y, width, height, GLFW_DONT_CARE); - - // these might have changed, only store them on a legit change, not on the initial update - if (m_last_fullscreen_mode != GfxDisplayMode::ForceUpdate) { - m_last_windowed_width = width; - m_last_windowed_height = height; - m_last_windowed_xpos = x; - m_last_windowed_ypos = y; - } } break; case GfxDisplayMode::Fullscreen: { + // TODO - when transitioning from fullscreen to windowed, it will use the old primary display + // which is to say, dragging the window to a different monitor won't update the used display // fullscreen const GLFWvidmode* vmode = glfwGetVideoMode(monitor); glfwSetWindowAttrib(m_window, GLFW_DECORATED, GLFW_FALSE); @@ -579,6 +590,8 @@ void GLDisplay::update_fullscreen(GfxDisplayMode mode, int screen) { glfwSetWindowMonitor(m_window, monitor, 0, 0, vmode->width, vmode->height, GLFW_DONT_CARE); } break; case GfxDisplayMode::Borderless: { + // TODO - when transitioning from fullscreen to windowed, it will use the old primary display + // which is to say, dragging the window to a different monitor won't update the used display // borderless fullscreen int x, y; glfwGetMonitorPos(monitor, &x, &y);