Skip to content

Commit

Permalink
impr: Stop rubber banding while resizing on macOS (#1690)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
mentlerd committed May 19, 2024
1 parent d5eb6b5 commit 2cb673f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions main/gui/source/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<Window *>(glfwGetWindowUserPointer(window));
win->m_unlockFrameRate = true;

Expand All @@ -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<Window *>(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<Window *>(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<Window *>(glfwGetWindowUserPointer(window));
win->m_unlockFrameRate = true;
});
Expand Down

0 comments on commit 2cb673f

Please sign in to comment.