mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-20 23:19:44 +00:00
UI/Qt: Set WC's max FPS to the refresh rate of the current screen
This commit is contained in:
parent
b0d97c991f
commit
124bdce99c
Notes:
github-actions[bot]
2025-07-26 14:10:29 +00:00
Author: https://github.com/Lubrsi
Commit: 124bdce99c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5606
Reviewed-by: https://github.com/Psychpsyo
Reviewed-by: https://github.com/kalenikaliaksandr
5 changed files with 40 additions and 4 deletions
|
@ -82,18 +82,26 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
|
|||
// Listen for DPI changes
|
||||
m_device_pixel_ratio = devicePixelRatio();
|
||||
m_current_screen = screen();
|
||||
m_refresh_rate = m_current_screen->refreshRate();
|
||||
|
||||
if (QT_VERSION < QT_VERSION_CHECK(6, 6, 0) || QGuiApplication::platformName() != "wayland") {
|
||||
setAttribute(Qt::WA_NativeWindow);
|
||||
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
||||
QObject::connect(m_current_screen, &QScreen::logicalDotsPerInchChanged, this, &BrowserWindow::device_pixel_ratio_changed);
|
||||
QObject::connect(m_current_screen, &QScreen::refreshRateChanged, this, &BrowserWindow::refresh_rate_changed);
|
||||
QObject::connect(windowHandle(), &QWindow::screenChanged, this, [this](QScreen* screen) {
|
||||
if (m_device_pixel_ratio != devicePixelRatio())
|
||||
device_pixel_ratio_changed(devicePixelRatio());
|
||||
|
||||
// Listen for logicalDotsPerInchChanged signals on new screen
|
||||
if (m_refresh_rate != screen->refreshRate())
|
||||
refresh_rate_changed(screen->refreshRate());
|
||||
|
||||
// Listen for logicalDotsPerInchChanged and refreshRateChanged signals on new screen
|
||||
QObject::disconnect(m_current_screen, &QScreen::logicalDotsPerInchChanged, nullptr, nullptr);
|
||||
QObject::disconnect(m_current_screen, &QScreen::refreshRateChanged, nullptr, nullptr);
|
||||
m_current_screen = screen;
|
||||
QObject::connect(m_current_screen, &QScreen::logicalDotsPerInchChanged, this, &BrowserWindow::device_pixel_ratio_changed);
|
||||
QObject::connect(m_current_screen, &QScreen::refreshRateChanged, this, &BrowserWindow::refresh_rate_changed);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -893,6 +901,14 @@ void BrowserWindow::device_pixel_ratio_changed(qreal dpi)
|
|||
});
|
||||
}
|
||||
|
||||
void BrowserWindow::refresh_rate_changed(qreal refresh_rate)
|
||||
{
|
||||
m_refresh_rate = refresh_rate;
|
||||
for_each_tab([this](auto& tab) {
|
||||
tab.view().set_maximum_frames_per_second(m_refresh_rate);
|
||||
});
|
||||
}
|
||||
|
||||
void BrowserWindow::tab_title_changed(int index, QString const& title)
|
||||
{
|
||||
// NOTE: Qt uses ampersands for shortcut keys in tab titles, so we need to escape them.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue