core/window: add QsWindow.devicePixelRatio

This commit is contained in:
outfoxxed 2025-01-22 03:33:46 -08:00
parent bc73d35d03
commit b336129c34
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
9 changed files with 48 additions and 0 deletions

View file

@ -192,6 +192,7 @@ WaylandPanelInterface::WaylandPanelInterface(QObject* parent)
QObject::connect(this->layer, &ProxyWindowBase::backerVisibilityChanged, this, &WaylandPanelInterface::backingWindowVisibleChanged); QObject::connect(this->layer, &ProxyWindowBase::backerVisibilityChanged, this, &WaylandPanelInterface::backingWindowVisibleChanged);
QObject::connect(this->layer, &ProxyWindowBase::heightChanged, this, &WaylandPanelInterface::heightChanged); QObject::connect(this->layer, &ProxyWindowBase::heightChanged, this, &WaylandPanelInterface::heightChanged);
QObject::connect(this->layer, &ProxyWindowBase::widthChanged, this, &WaylandPanelInterface::widthChanged); QObject::connect(this->layer, &ProxyWindowBase::widthChanged, this, &WaylandPanelInterface::widthChanged);
QObject::connect(this->layer, &ProxyWindowBase::devicePixelRatioChanged, this, &WaylandPanelInterface::devicePixelRatioChanged);
QObject::connect(this->layer, &ProxyWindowBase::screenChanged, this, &WaylandPanelInterface::screenChanged); QObject::connect(this->layer, &ProxyWindowBase::screenChanged, this, &WaylandPanelInterface::screenChanged);
QObject::connect(this->layer, &ProxyWindowBase::windowTransformChanged, this, &WaylandPanelInterface::windowTransformChanged); QObject::connect(this->layer, &ProxyWindowBase::windowTransformChanged, this, &WaylandPanelInterface::windowTransformChanged);
QObject::connect(this->layer, &ProxyWindowBase::colorChanged, this, &WaylandPanelInterface::colorChanged); QObject::connect(this->layer, &ProxyWindowBase::colorChanged, this, &WaylandPanelInterface::colorChanged);
@ -218,10 +219,13 @@ void WaylandPanelInterface::onReload(QObject* oldInstance) {
QQmlListProperty<QObject> WaylandPanelInterface::data() { return this->layer->data(); } QQmlListProperty<QObject> WaylandPanelInterface::data() { return this->layer->data(); }
ProxyWindowBase* WaylandPanelInterface::proxyWindow() const { return this->layer; } ProxyWindowBase* WaylandPanelInterface::proxyWindow() const { return this->layer; }
QQuickItem* WaylandPanelInterface::contentItem() const { return this->layer->contentItem(); } QQuickItem* WaylandPanelInterface::contentItem() const { return this->layer->contentItem(); }
bool WaylandPanelInterface::isBackingWindowVisible() const { bool WaylandPanelInterface::isBackingWindowVisible() const {
return this->layer->isVisibleDirect(); return this->layer->isVisibleDirect();
} }
qreal WaylandPanelInterface::devicePixelRatio() const { return this->layer->devicePixelRatio(); }
// NOLINTBEGIN // NOLINTBEGIN
#define proxyPair(type, get, set) \ #define proxyPair(type, get, set) \
type WaylandPanelInterface::get() const { return this->layer->get(); } \ type WaylandPanelInterface::get() const { return this->layer->get(); } \

View file

@ -146,6 +146,8 @@ public:
[[nodiscard]] qint32 height() const override; [[nodiscard]] qint32 height() const override;
void setHeight(qint32 height) override; void setHeight(qint32 height) override;
[[nodiscard]] virtual qreal devicePixelRatio() const override;
[[nodiscard]] QuickshellScreenInfo* screen() const override; [[nodiscard]] QuickshellScreenInfo* screen() const override;
void setScreen(QuickshellScreenInfo* screen) override; void setScreen(QuickshellScreenInfo* screen) override;

View file

@ -32,6 +32,7 @@ FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
QObject::connect(this->window, &ProxyWindowBase::backerVisibilityChanged, this, &FloatingWindowInterface::backingWindowVisibleChanged); QObject::connect(this->window, &ProxyWindowBase::backerVisibilityChanged, this, &FloatingWindowInterface::backingWindowVisibleChanged);
QObject::connect(this->window, &ProxyWindowBase::heightChanged, this, &FloatingWindowInterface::heightChanged); QObject::connect(this->window, &ProxyWindowBase::heightChanged, this, &FloatingWindowInterface::heightChanged);
QObject::connect(this->window, &ProxyWindowBase::widthChanged, this, &FloatingWindowInterface::widthChanged); QObject::connect(this->window, &ProxyWindowBase::widthChanged, this, &FloatingWindowInterface::widthChanged);
QObject::connect(this->window, &ProxyWindowBase::devicePixelRatioChanged, this, &FloatingWindowInterface::devicePixelRatioChanged);
QObject::connect(this->window, &ProxyWindowBase::screenChanged, this, &FloatingWindowInterface::screenChanged); QObject::connect(this->window, &ProxyWindowBase::screenChanged, this, &FloatingWindowInterface::screenChanged);
QObject::connect(this->window, &ProxyWindowBase::windowTransformChanged, this, &FloatingWindowInterface::windowTransformChanged); QObject::connect(this->window, &ProxyWindowBase::windowTransformChanged, this, &FloatingWindowInterface::windowTransformChanged);
QObject::connect(this->window, &ProxyWindowBase::colorChanged, this, &FloatingWindowInterface::colorChanged); QObject::connect(this->window, &ProxyWindowBase::colorChanged, this, &FloatingWindowInterface::colorChanged);
@ -50,10 +51,13 @@ void FloatingWindowInterface::onReload(QObject* oldInstance) {
QQmlListProperty<QObject> FloatingWindowInterface::data() { return this->window->data(); } QQmlListProperty<QObject> FloatingWindowInterface::data() { return this->window->data(); }
ProxyWindowBase* FloatingWindowInterface::proxyWindow() const { return this->window; } ProxyWindowBase* FloatingWindowInterface::proxyWindow() const { return this->window; }
QQuickItem* FloatingWindowInterface::contentItem() const { return this->window->contentItem(); } QQuickItem* FloatingWindowInterface::contentItem() const { return this->window->contentItem(); }
bool FloatingWindowInterface::isBackingWindowVisible() const { bool FloatingWindowInterface::isBackingWindowVisible() const {
return this->window->isVisibleDirect(); return this->window->isVisibleDirect();
} }
qreal FloatingWindowInterface::devicePixelRatio() const { return this->window->devicePixelRatio(); }
// NOLINTBEGIN // NOLINTBEGIN
#define proxyPair(type, get, set) \ #define proxyPair(type, get, set) \
type FloatingWindowInterface::get() const { return this->window->get(); } \ type FloatingWindowInterface::get() const { return this->window->get(); } \

View file

@ -42,6 +42,8 @@ public:
[[nodiscard]] qint32 height() const override; [[nodiscard]] qint32 height() const override;
void setHeight(qint32 height) override; void setHeight(qint32 height) override;
[[nodiscard]] virtual qreal devicePixelRatio() const override;
[[nodiscard]] QuickshellScreenInfo* screen() const override; [[nodiscard]] QuickshellScreenInfo* screen() const override;
void setScreen(QuickshellScreenInfo* screen) override; void setScreen(QuickshellScreenInfo* screen) override;

View file

@ -1,6 +1,7 @@
#include "proxywindow.hpp" #include "proxywindow.hpp"
#include <private/qquickwindow_p.h> #include <private/qquickwindow_p.h>
#include <qcoreevent.h>
#include <qevent.h> #include <qevent.h>
#include <qnamespace.h> #include <qnamespace.h>
#include <qobject.h> #include <qobject.h>
@ -191,6 +192,7 @@ void ProxyWindowBase::connectWindow() {
QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyWindowBase::screenChanged); QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyWindowBase::screenChanged);
QObject::connect(this->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged); QObject::connect(this->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged);
QObject::connect(this->window, &ProxiedWindow::exposed, this, &ProxyWindowBase::runLints); QObject::connect(this->window, &ProxiedWindow::exposed, this, &ProxyWindowBase::runLints);
QObject::connect(this->window, &ProxiedWindow::devicePixelRatioChanged, this, &ProxyWindowBase::devicePixelRatioChanged);
// clang-format on // clang-format on
} }
@ -213,6 +215,7 @@ void ProxyWindowBase::completeWindow() {
emit this->yChanged(); emit this->yChanged();
emit this->widthChanged(); emit this->widthChanged();
emit this->heightChanged(); emit this->heightChanged();
emit this->devicePixelRatioChanged();
this->mContentItem->setParentItem(this->window->contentItem()); this->mContentItem->setParentItem(this->window->contentItem());
this->mContentItem->setWidth(this->width()); this->mContentItem->setWidth(this->width());
@ -411,6 +414,12 @@ void ProxyWindowBase::setSurfaceFormat(QsSurfaceFormat format) {
emit this->surfaceFormatChanged(); emit this->surfaceFormatChanged();
} }
qreal ProxyWindowBase::devicePixelRatio() const {
if (this->window != nullptr) return this->window->devicePixelRatio();
if (this->mScreen != nullptr) return this->mScreen->devicePixelRatio();
return 1.0;
}
void ProxyWindowBase::onMaskChanged() { void ProxyWindowBase::onMaskChanged() {
if (this->window != nullptr) this->updateMask(); if (this->window != nullptr) this->updateMask();
} }
@ -456,6 +465,14 @@ void ProxyWindowAttached::setWindow(ProxyWindowBase* window) {
emit this->windowChanged(); emit this->windowChanged();
} }
bool ProxiedWindow::event(QEvent* event) {
if (event->type() == QEvent::DevicePixelRatioChange) {
emit this->devicePixelRatioChanged();
}
return this->QQuickWindow::event(event);
}
void ProxiedWindow::exposeEvent(QExposeEvent* event) { void ProxiedWindow::exposeEvent(QExposeEvent* event) {
this->QQuickWindow::exposeEvent(event); this->QQuickWindow::exposeEvent(event);
emit this->exposed(); emit this->exposed();

View file

@ -44,6 +44,7 @@ class ProxyWindowBase: public Reloadable {
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged); Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged); Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged); Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged);
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged);
Q_PROPERTY(QuickshellScreenInfo* screen READ screen WRITE setScreen NOTIFY screenChanged); Q_PROPERTY(QuickshellScreenInfo* screen READ screen WRITE setScreen NOTIFY screenChanged);
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged); Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged);
Q_PROPERTY(PendingRegion* mask READ mask WRITE setMask NOTIFY maskChanged); Q_PROPERTY(PendingRegion* mask READ mask WRITE setMask NOTIFY maskChanged);
@ -97,6 +98,8 @@ public:
[[nodiscard]] virtual qint32 height() const; [[nodiscard]] virtual qint32 height() const;
virtual void setHeight(qint32 height); virtual void setHeight(qint32 height);
[[nodiscard]] qreal devicePixelRatio() const;
[[nodiscard]] virtual QuickshellScreenInfo* screen() const; [[nodiscard]] virtual QuickshellScreenInfo* screen() const;
virtual void setScreen(QuickshellScreenInfo* screen); virtual void setScreen(QuickshellScreenInfo* screen);
@ -122,6 +125,7 @@ signals:
void yChanged(); void yChanged();
void widthChanged(); void widthChanged();
void heightChanged(); void heightChanged();
void devicePixelRatioChanged();
void windowTransformChanged(); void windowTransformChanged();
void screenChanged(); void screenChanged();
void colorChanged(); void colorChanged();
@ -192,8 +196,10 @@ public:
signals: signals:
void exposed(); void exposed();
void devicePixelRatioChanged();
protected: protected:
bool event(QEvent* event) override;
void exposeEvent(QExposeEvent* event) override; void exposeEvent(QExposeEvent* event) override;
private: private:

View file

@ -55,6 +55,12 @@ class WindowInterface: public Reloadable {
Q_PROPERTY(bool backingWindowVisible READ isBackingWindowVisible NOTIFY backingWindowVisibleChanged); Q_PROPERTY(bool backingWindowVisible READ isBackingWindowVisible NOTIFY backingWindowVisibleChanged);
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged); Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged); Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged);
/// The ratio between logical pixels and monitor pixels.
///
/// Qt's coordinate system works in logical pixels, which equal N monitor pixels
/// depending on scale factor. This property returns the amount of monitor pixels
/// in a logical pixel for the current window.
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged);
/// The screen that the window currently occupies. /// The screen that the window currently occupies.
/// ///
/// This may be modified to move the window to the given screen. /// This may be modified to move the window to the given screen.
@ -147,6 +153,8 @@ public:
[[nodiscard]] virtual qint32 height() const = 0; [[nodiscard]] virtual qint32 height() const = 0;
virtual void setHeight(qint32 height) = 0; virtual void setHeight(qint32 height) = 0;
[[nodiscard]] virtual qreal devicePixelRatio() const = 0;
[[nodiscard]] virtual QuickshellScreenInfo* screen() const = 0; [[nodiscard]] virtual QuickshellScreenInfo* screen() const = 0;
virtual void setScreen(QuickshellScreenInfo* screen) = 0; virtual void setScreen(QuickshellScreenInfo* screen) = 0;
@ -171,6 +179,7 @@ signals:
void backingWindowVisibleChanged(); void backingWindowVisibleChanged();
void widthChanged(); void widthChanged();
void heightChanged(); void heightChanged();
void devicePixelRatioChanged();
void screenChanged(); void screenChanged();
void windowTransformChanged(); void windowTransformChanged();
void colorChanged(); void colorChanged();

View file

@ -478,6 +478,7 @@ XPanelInterface::XPanelInterface(QObject* parent)
QObject::connect(this->panel, &ProxyWindowBase::backerVisibilityChanged, this, &XPanelInterface::backingWindowVisibleChanged); QObject::connect(this->panel, &ProxyWindowBase::backerVisibilityChanged, this, &XPanelInterface::backingWindowVisibleChanged);
QObject::connect(this->panel, &ProxyWindowBase::heightChanged, this, &XPanelInterface::heightChanged); QObject::connect(this->panel, &ProxyWindowBase::heightChanged, this, &XPanelInterface::heightChanged);
QObject::connect(this->panel, &ProxyWindowBase::widthChanged, this, &XPanelInterface::widthChanged); QObject::connect(this->panel, &ProxyWindowBase::widthChanged, this, &XPanelInterface::widthChanged);
QObject::connect(this->panel, &ProxyWindowBase::devicePixelRatioChanged, this, &XPanelInterface::devicePixelRatioChanged);
QObject::connect(this->panel, &ProxyWindowBase::screenChanged, this, &XPanelInterface::screenChanged); QObject::connect(this->panel, &ProxyWindowBase::screenChanged, this, &XPanelInterface::screenChanged);
QObject::connect(this->panel, &ProxyWindowBase::windowTransformChanged, this, &XPanelInterface::windowTransformChanged); QObject::connect(this->panel, &ProxyWindowBase::windowTransformChanged, this, &XPanelInterface::windowTransformChanged);
QObject::connect(this->panel, &ProxyWindowBase::colorChanged, this, &XPanelInterface::colorChanged); QObject::connect(this->panel, &ProxyWindowBase::colorChanged, this, &XPanelInterface::colorChanged);
@ -505,6 +506,7 @@ QQmlListProperty<QObject> XPanelInterface::data() { return this->panel->data();
ProxyWindowBase* XPanelInterface::proxyWindow() const { return this->panel; } ProxyWindowBase* XPanelInterface::proxyWindow() const { return this->panel; }
QQuickItem* XPanelInterface::contentItem() const { return this->panel->contentItem(); } QQuickItem* XPanelInterface::contentItem() const { return this->panel->contentItem(); }
bool XPanelInterface::isBackingWindowVisible() const { return this->panel->isVisibleDirect(); } bool XPanelInterface::isBackingWindowVisible() const { return this->panel->isVisibleDirect(); }
qreal XPanelInterface::devicePixelRatio() const { return this->panel->devicePixelRatio(); }
// NOLINTBEGIN // NOLINTBEGIN
#define proxyPair(type, get, set) \ #define proxyPair(type, get, set) \

View file

@ -127,6 +127,8 @@ public:
[[nodiscard]] qint32 height() const override; [[nodiscard]] qint32 height() const override;
void setHeight(qint32 height) override; void setHeight(qint32 height) override;
[[nodiscard]] virtual qreal devicePixelRatio() const override;
[[nodiscard]] QuickshellScreenInfo* screen() const override; [[nodiscard]] QuickshellScreenInfo* screen() const override;
void setScreen(QuickshellScreenInfo* screen) override; void setScreen(QuickshellScreenInfo* screen) override;