Qt: delay resize events using a timer (#13614)
Some checks are pending
🐧 Linux Builds / AppImage (push) Waiting to run
🐧 Linux Builds / Flatpak (push) Waiting to run
🍎 MacOS Builds / Defaults (push) Waiting to run
🖥️ Windows Builds / Lint VS Project Files (push) Waiting to run
🖥️ Windows Builds / SSE4 (push) Blocked by required conditions
🖥️ Windows Builds / AVX2 (push) Blocked by required conditions
🖥️ Windows Builds / CMake (push) Waiting to run

This commit is contained in:
GovanifY 2025-11-30 00:17:05 +01:00 committed by GitHub
parent 3e8327e934
commit 0cbd884234
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View File

@ -13,6 +13,7 @@
#include "common/Console.h"
#include <QtCore/QDebug>
#include <QtCore/QTimer>
#include <QtGui/QGuiApplication>
#include <QtGui/QKeyEvent>
#include <QtGui/QResizeEvent>
@ -32,6 +33,10 @@
DisplaySurface::DisplaySurface()
: QWindow()
{
m_resize_debounce_timer = new QTimer(this);
m_resize_debounce_timer->setSingleShot(true);
m_resize_debounce_timer->setTimerType(Qt::PreciseTimer);
connect(m_resize_debounce_timer, &QTimer::timeout, this, &DisplaySurface::onResizeDebounceTimer);
}
DisplaySurface::~DisplaySurface()
@ -245,6 +250,11 @@ void DisplaySurface::handleKeyInputEvent(QEvent* event)
}
}
void DisplaySurface::onResizeDebounceTimer()
{
emit windowResizedEvent(m_pending_window_width, m_pending_window_height, m_pending_window_scale);
}
bool DisplaySurface::event(QEvent* event)
{
switch (event->type())
@ -355,10 +365,17 @@ bool DisplaySurface::event(QEvent* event)
// avoid spamming resize events for paint events (sent on move on windows)
if (m_last_window_width != scaled_width || m_last_window_height != scaled_height || m_last_window_scale != dpr)
{
m_pending_window_width = scaled_width;
m_pending_window_height = scaled_height;
m_pending_window_scale = dpr;
m_last_window_width = scaled_width;
m_last_window_height = scaled_height;
m_last_window_scale = dpr;
emit windowResizedEvent(scaled_width, scaled_height, dpr);
// qt spams resize events, sometimes several time per ms.
// since a vulkan resize swap chain event takes between 15 to 25ms this is,
// need less to say, unwanted.
m_resize_debounce_timer->start(100);
}
updateCenterPos();

View File

@ -3,6 +3,7 @@
#pragma once
#include "common/WindowInfo.h"
#include <QtCore/QTimer>
#include <QtGui/QDragMoveEvent>
#include <QtGui/QWindow>
#include <optional>
@ -42,6 +43,9 @@ protected:
bool event(QEvent* event) override;
bool eventFilter(QObject* object, QEvent* event) override;
private Q_SLOTS:
void onResizeDebounceTimer();
private:
bool isActuallyFullscreen() const;
void updateCenterPos();
@ -60,5 +64,10 @@ private:
u32 m_last_window_height = 0;
float m_last_window_scale = 1.0f;
QTimer* m_resize_debounce_timer = nullptr;
u32 m_pending_window_width = 0;
u32 m_pending_window_height = 0;
float m_pending_window_scale = 1.0f;
QWidget* m_container = nullptr;
};