ladybird/Ladybird/Qt/InspectorWidget.h
Dan Klishch 38164411f0 Ladybird/Qt: Properly listen for DPI changes on Wayland
Some Wayland compositors have support of fractional-scale-v1 protocol.
The protocol allows compositor to announce a preferred fractional scale
on a per-wl_surface basis. Qt forwards these Wayland events to an
application using a usual DevicePixelRatioChange event. However, in
contrast to the other platforms, this DevicePixelRatioChange event is
issued directly on widgets and not screens. Additionally, the exact
fractional scale is stored in QWindow object and not the current screen.

Note that in theory it is possible to obtain per-screen fractional
scaling on Wayland by interpolating data provided by wl_output and
xdg_output events but qtwayland does not do that.

If fractional-scale-v1 is not available, qtwayland will still fire
per-Widget DevicePixelRatioChange events, but, obviously, with the
per-screen possibly larger ceiled scaling.

This whole thing makes handling DPI changes on Wayland really simple.
All we need to do is to intercept DevicePixelRatioChange events firing
on QWindow objects and call the old device_pixel_ratio_changed handler
with the window's devicePixelRatio(). The only caveat here is not forget
to always set QWidget's parent before calling devicePixelRatio() on it.
2024-02-06 09:59:17 -07:00

65 lines
1.6 KiB
C++

/*
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "WebContentView.h"
#include <LibGfx/Point.h>
#include <LibWebView/Forward.h>
#include <QWidget>
class QAction;
class QMenu;
namespace Ladybird {
class WebContentView;
class InspectorWidget final : public QWidget {
Q_OBJECT
public:
InspectorWidget(QWidget* tab, WebContentView& content_view);
virtual ~InspectorWidget() override;
void inspect();
void reset();
void select_hovered_node();
void select_default_node();
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;
QScreen* m_current_screen;
double m_device_pixel_ratio { 0 };
WebContentView* m_inspector_view;
OwnPtr<WebView::InspectorClient> m_inspector_client;
QMenu* m_dom_node_text_context_menu { nullptr };
QMenu* m_dom_node_tag_context_menu { nullptr };
QMenu* m_dom_node_attribute_context_menu { nullptr };
QAction* m_edit_node_action { nullptr };
QAction* m_copy_node_action { nullptr };
QAction* m_screenshot_node_action { nullptr };
QAction* m_create_child_element_action { nullptr };
QAction* m_create_child_text_node_action { nullptr };
QAction* m_clone_node_action { nullptr };
QAction* m_delete_node_action { nullptr };
QAction* m_add_attribute_action { nullptr };
QAction* m_remove_attribute_action { nullptr };
QAction* m_copy_attribute_value_action { nullptr };
};
}