1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

Ladybird/Qt: Listen to DPI changes and update WebContentView accordingly

This commit is contained in:
Bastiaan van der Plaat 2023-12-13 19:10:05 +01:00 committed by Andreas Kling
parent 51ecfdf71f
commit 04b591b2e0
6 changed files with 81 additions and 15 deletions

View file

@ -27,6 +27,7 @@
#include <QPlainTextEdit>
#include <QShortcut>
#include <QTabBar>
#include <QWindow>
namespace Ladybird {
@ -55,6 +56,22 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
m_tabs_container->setDocumentMode(true);
m_tabs_container->setTabBarAutoHide(true);
// Listen for DPI changes
setAttribute(Qt::WA_NativeWindow);
setAttribute(Qt::WA_DontCreateNativeAncestors);
m_device_pixel_ratio = devicePixelRatio();
m_current_screen = screen();
QObject::connect(m_current_screen, &QScreen::logicalDotsPerInchChanged, this, &BrowserWindow::device_pixel_ratio_changed);
QObject::connect(windowHandle(), &QWindow::screenChanged, this, [this](QScreen* screen) {
if (m_device_pixel_ratio != screen->devicePixelRatio())
device_pixel_ratio_changed(screen->devicePixelRatio());
// Listen for logicalDotsPerInchChanged signals on new screen
QObject::disconnect(m_current_screen, &QScreen::logicalDotsPerInchChanged, nullptr, nullptr);
m_current_screen = screen;
QObject::connect(m_current_screen, &QScreen::logicalDotsPerInchChanged, this, &BrowserWindow::device_pixel_ratio_changed);
});
auto* menu = menuBar()->addMenu("&File");
auto* new_tab_action = new QAction("New &Tab", this);
@ -562,6 +579,14 @@ int BrowserWindow::tab_index(Tab* tab)
return m_tabs_container->indexOf(tab);
}
void BrowserWindow::device_pixel_ratio_changed(qreal dpi)
{
m_device_pixel_ratio = dpi;
for_each_tab([this](auto& tab) {
tab.view().set_device_pixel_ratio(m_device_pixel_ratio);
});
}
void BrowserWindow::tab_title_changed(int index, QString const& title)
{
m_tabs_container->setTabText(index, title);