diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index badbc34642c..e6e900ec9a0 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -57,20 +57,22 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar 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; + 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(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 + 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"); @@ -737,6 +739,18 @@ void BrowserWindow::copy_selected_text() clipboard->setText(qstring_from_ak_string(text)); } +bool BrowserWindow::event(QEvent* event) +{ +#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) + if (event->type() == QEvent::DevicePixelRatioChange) { + if (m_device_pixel_ratio != devicePixelRatio()) + device_pixel_ratio_changed(devicePixelRatio()); + } +#endif + + return QMainWindow::event(event); +} + void BrowserWindow::resizeEvent(QResizeEvent* event) { QWidget::resizeEvent(event); diff --git a/Ladybird/Qt/BrowserWindow.h b/Ladybird/Qt/BrowserWindow.h index 0bd6d799549..0aa634ef29e 100644 --- a/Ladybird/Qt/BrowserWindow.h +++ b/Ladybird/Qt/BrowserWindow.h @@ -96,6 +96,7 @@ protected: bool eventFilter(QObject* obj, QEvent* event) override; private: + virtual bool event(QEvent*) override; virtual void resizeEvent(QResizeEvent*) override; virtual void moveEvent(QMoveEvent*) override; virtual void wheelEvent(QWheelEvent*) override; diff --git a/Ladybird/Qt/InspectorWidget.cpp b/Ladybird/Qt/InspectorWidget.cpp index ce8d9df996d..d083d081a6b 100644 --- a/Ladybird/Qt/InspectorWidget.cpp +++ b/Ladybird/Qt/InspectorWidget.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -21,7 +22,7 @@ extern bool is_using_dark_system_theme(QWidget&); InspectorWidget::InspectorWidget(QWidget* tab, WebContentView& content_view) : QWidget(tab, Qt::Window) { - m_inspector_view = new WebContentView({}, {}); + m_inspector_view = new WebContentView(this, {}, {}); if (is_using_dark_system_theme(*this)) m_inspector_view->update_palette(WebContentView::PaletteMode::Dark); @@ -126,20 +127,22 @@ InspectorWidget::InspectorWidget(QWidget* tab, WebContentView& content_view) 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; + 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, &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; @@ -170,6 +173,18 @@ void InspectorWidget::device_pixel_ratio_changed(qreal dpi) m_inspector_view->set_device_pixel_ratio(m_device_pixel_ratio); } +bool InspectorWidget::event(QEvent* event) +{ +#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) + if (event->type() == QEvent::DevicePixelRatioChange) { + if (m_device_pixel_ratio != devicePixelRatio()) + device_pixel_ratio_changed(devicePixelRatio()); + } +#endif + + return QWidget::event(event); +} + void InspectorWidget::closeEvent(QCloseEvent* event) { event->accept(); diff --git a/Ladybird/Qt/InspectorWidget.h b/Ladybird/Qt/InspectorWidget.h index b1400d2ea3d..78483ec23c6 100644 --- a/Ladybird/Qt/InspectorWidget.h +++ b/Ladybird/Qt/InspectorWidget.h @@ -35,6 +35,7 @@ public slots: void device_pixel_ratio_changed(qreal dpi); private: + bool event(QEvent*) override; void closeEvent(QCloseEvent*) override; QPoint to_widget_position(Gfx::IntPoint) const; diff --git a/Ladybird/Qt/Tab.cpp b/Ladybird/Qt/Tab.cpp index 4521c1e4dfa..40c8669bc2a 100644 --- a/Ladybird/Qt/Tab.cpp +++ b/Ladybird/Qt/Tab.cpp @@ -61,7 +61,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St m_layout->setSpacing(0); m_layout->setContentsMargins(0, 0, 0, 0); - m_view = new WebContentView(web_content_options, webdriver_content_ipc_path, parent_client, page_index); + m_view = new WebContentView(this, web_content_options, webdriver_content_ipc_path, parent_client, page_index); m_toolbar = new QToolBar(this); m_location_edit = new LocationEdit(this); diff --git a/Ladybird/Qt/WebContentView.cpp b/Ladybird/Qt/WebContentView.cpp index 78dd6002ad7..d4480886da6 100644 --- a/Ladybird/Qt/WebContentView.cpp +++ b/Ladybird/Qt/WebContentView.cpp @@ -54,8 +54,9 @@ namespace Ladybird { bool is_using_dark_system_theme(QWidget&); -WebContentView::WebContentView(WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, RefPtr parent_client, size_t page_index) - : m_web_content_options(web_content_options) +WebContentView::WebContentView(QWidget* window, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, RefPtr parent_client, size_t page_index) + : QAbstractScrollArea(window) + , m_web_content_options(web_content_options) , m_webdriver_content_ipc_path(webdriver_content_ipc_path) { m_client_state.client = parent_client; diff --git a/Ladybird/Qt/WebContentView.h b/Ladybird/Qt/WebContentView.h index 1bfe1c61f56..fb6b5266573 100644 --- a/Ladybird/Qt/WebContentView.h +++ b/Ladybird/Qt/WebContentView.h @@ -42,7 +42,7 @@ class WebContentView final , public WebView::ViewImplementation { Q_OBJECT public: - WebContentView(WebContentOptions const&, StringView webdriver_content_ipc_path, RefPtr parent_client = nullptr, size_t page_index = 0); + WebContentView(QWidget* window, WebContentOptions const&, StringView webdriver_content_ipc_path, RefPtr parent_client = nullptr, size_t page_index = 0); virtual ~WebContentView() override; Function on_tab_open_request;