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
This commit is contained in:
David Mentler 2024-05-19 14:14:57 +02:00 committed by GitHub
parent d5eb6b5bbc
commit 2cb673fd81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 8 deletions

View File

@ -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<Window *>(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<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;
});