From 2cb673fd81f560ea2f62de90fdeabc3be7257f5f Mon Sep 17 00:00:00 2001 From: David Mentler Date: Sun, 19 May 2024 14:14:57 +0200 Subject: [PATCH] impr: Stop rubber banding while resizing on macOS (#1690) ### Problem description On macOS `glfwSetWindowSizeCallback` is invoked early during window resizing, rendering a frame in that callback leads to wonky results as the new framebuffer is swapped before the OS has the chance to actually resize the window: https://github.com/WerWolv/ImHex/assets/1068675/46336419-3fc2-4aa1-b16f-68b0c00e3584 ### Implementation description Window contents are redrawn only from `glfwSetWindowRefreshCallback` during resizing, fixing the issue: https://github.com/WerWolv/ImHex/assets/1068675/3acc5d4a-b2a5-42f0-9015-5e7172a027cf --- main/gui/source/window/window.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 444291351..204f16dfe 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -156,6 +156,10 @@ namespace hex { void Window::fullFrame() { static u32 crashWatchdog = 0; + if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) { + return; + } + try { this->frameBegin(); this->frame(); @@ -802,8 +806,6 @@ namespace hex { glfwSetWindowPosCallback(m_window, [](GLFWwindow *window, int x, int y) { ImHexApi::System::impl::setMainWindowPosition(x, y); - if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) return; - auto win = static_cast(glfwGetWindowUserPointer(window)); win->m_unlockFrameRate = true; @@ -815,17 +817,22 @@ namespace hex { if (!glfwGetWindowAttrib(window, GLFW_ICONIFIED)) ImHexApi::System::impl::setMainWindowSize(width, height); - if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) return; - auto win = static_cast(glfwGetWindowUserPointer(window)); win->m_unlockFrameRate = true; - - win->fullFrame(); + + #if !defined(OS_MACOS) + win->fullFrame(); + #endif }); + #if defined(OS_MACOS) + glfwSetWindowRefreshCallback(m_window, [](GLFWwindow *window) { + auto win = static_cast(glfwGetWindowUserPointer(window)); + win->fullFrame(); + }); + #endif + glfwSetCursorPosCallback(m_window, [](GLFWwindow *window, double, double) { - if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) return; - auto win = static_cast(glfwGetWindowUserPointer(window)); win->m_unlockFrameRate = true; });