1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +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

@ -12,6 +12,7 @@
#include <QCloseEvent>
#include <QMenu>
#include <QVBoxLayout>
#include <QWindow>
namespace Ladybird {
@ -123,6 +124,22 @@ InspectorWidget::InspectorWidget(QWidget* tab, WebContentView& content_view)
setWindowTitle("Inspector");
resize(875, 825);
// 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, &InspectorWidget::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, &InspectorWidget::device_pixel_ratio_changed);
});
}
InspectorWidget::~InspectorWidget() = default;
@ -147,6 +164,12 @@ void InspectorWidget::select_default_node()
m_inspector_client->select_default_node();
}
void InspectorWidget::device_pixel_ratio_changed(qreal dpi)
{
m_device_pixel_ratio = dpi;
m_inspector_view->set_device_pixel_ratio(m_device_pixel_ratio);
}
void InspectorWidget::closeEvent(QCloseEvent* event)
{
event->accept();