forked from quickshell/quickshell
		
	core/window: add QsWindow.devicePixelRatio
This commit is contained in:
		
							parent
							
								
									bc73d35d03
								
							
						
					
					
						commit
						b336129c34
					
				
					 9 changed files with 48 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -192,6 +192,7 @@ WaylandPanelInterface::WaylandPanelInterface(QObject* parent)
 | 
			
		|||
	QObject::connect(this->layer, &ProxyWindowBase::backerVisibilityChanged, this, &WaylandPanelInterface::backingWindowVisibleChanged);
 | 
			
		||||
	QObject::connect(this->layer, &ProxyWindowBase::heightChanged, this, &WaylandPanelInterface::heightChanged);
 | 
			
		||||
	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::windowTransformChanged, this, &WaylandPanelInterface::windowTransformChanged);
 | 
			
		||||
	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(); }
 | 
			
		||||
ProxyWindowBase* WaylandPanelInterface::proxyWindow() const { return this->layer; }
 | 
			
		||||
QQuickItem* WaylandPanelInterface::contentItem() const { return this->layer->contentItem(); }
 | 
			
		||||
 | 
			
		||||
bool WaylandPanelInterface::isBackingWindowVisible() const {
 | 
			
		||||
	return this->layer->isVisibleDirect();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
qreal WaylandPanelInterface::devicePixelRatio() const { return this->layer->devicePixelRatio(); }
 | 
			
		||||
 | 
			
		||||
// NOLINTBEGIN
 | 
			
		||||
#define proxyPair(type, get, set)                                                                  \
 | 
			
		||||
	type WaylandPanelInterface::get() const { return this->layer->get(); }                           \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -146,6 +146,8 @@ public:
 | 
			
		|||
	[[nodiscard]] qint32 height() const override;
 | 
			
		||||
	void setHeight(qint32 height) override;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] virtual qreal devicePixelRatio() const override;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] QuickshellScreenInfo* screen() const override;
 | 
			
		||||
	void setScreen(QuickshellScreenInfo* screen) override;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,6 +32,7 @@ FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
 | 
			
		|||
	QObject::connect(this->window, &ProxyWindowBase::backerVisibilityChanged, this, &FloatingWindowInterface::backingWindowVisibleChanged);
 | 
			
		||||
	QObject::connect(this->window, &ProxyWindowBase::heightChanged, this, &FloatingWindowInterface::heightChanged);
 | 
			
		||||
	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::windowTransformChanged, this, &FloatingWindowInterface::windowTransformChanged);
 | 
			
		||||
	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(); }
 | 
			
		||||
ProxyWindowBase* FloatingWindowInterface::proxyWindow() const { return this->window; }
 | 
			
		||||
QQuickItem* FloatingWindowInterface::contentItem() const { return this->window->contentItem(); }
 | 
			
		||||
 | 
			
		||||
bool FloatingWindowInterface::isBackingWindowVisible() const {
 | 
			
		||||
	return this->window->isVisibleDirect();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
qreal FloatingWindowInterface::devicePixelRatio() const { return this->window->devicePixelRatio(); }
 | 
			
		||||
 | 
			
		||||
// NOLINTBEGIN
 | 
			
		||||
#define proxyPair(type, get, set)                                                                  \
 | 
			
		||||
	type FloatingWindowInterface::get() const { return this->window->get(); }                        \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,6 +42,8 @@ public:
 | 
			
		|||
	[[nodiscard]] qint32 height() const override;
 | 
			
		||||
	void setHeight(qint32 height) override;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] virtual qreal devicePixelRatio() const override;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] QuickshellScreenInfo* screen() const override;
 | 
			
		||||
	void setScreen(QuickshellScreenInfo* screen) override;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
#include "proxywindow.hpp"
 | 
			
		||||
 | 
			
		||||
#include <private/qquickwindow_p.h>
 | 
			
		||||
#include <qcoreevent.h>
 | 
			
		||||
#include <qevent.h>
 | 
			
		||||
#include <qnamespace.h>
 | 
			
		||||
#include <qobject.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -191,6 +192,7 @@ void ProxyWindowBase::connectWindow() {
 | 
			
		|||
	QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyWindowBase::screenChanged);
 | 
			
		||||
	QObject::connect(this->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged);
 | 
			
		||||
	QObject::connect(this->window, &ProxiedWindow::exposed, this, &ProxyWindowBase::runLints);
 | 
			
		||||
	QObject::connect(this->window, &ProxiedWindow::devicePixelRatioChanged, this, &ProxyWindowBase::devicePixelRatioChanged);
 | 
			
		||||
	// clang-format on
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -213,6 +215,7 @@ void ProxyWindowBase::completeWindow() {
 | 
			
		|||
	emit this->yChanged();
 | 
			
		||||
	emit this->widthChanged();
 | 
			
		||||
	emit this->heightChanged();
 | 
			
		||||
	emit this->devicePixelRatioChanged();
 | 
			
		||||
 | 
			
		||||
	this->mContentItem->setParentItem(this->window->contentItem());
 | 
			
		||||
	this->mContentItem->setWidth(this->width());
 | 
			
		||||
| 
						 | 
				
			
			@ -411,6 +414,12 @@ void ProxyWindowBase::setSurfaceFormat(QsSurfaceFormat format) {
 | 
			
		|||
	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() {
 | 
			
		||||
	if (this->window != nullptr) this->updateMask();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -456,6 +465,14 @@ void ProxyWindowAttached::setWindow(ProxyWindowBase* window) {
 | 
			
		|||
	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) {
 | 
			
		||||
	this->QQuickWindow::exposeEvent(event);
 | 
			
		||||
	emit this->exposed();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,6 +44,7 @@ class ProxyWindowBase: public Reloadable {
 | 
			
		|||
	Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
 | 
			
		||||
	Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
 | 
			
		||||
	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(QColor color READ color WRITE setColor NOTIFY colorChanged);
 | 
			
		||||
	Q_PROPERTY(PendingRegion* mask READ mask WRITE setMask NOTIFY maskChanged);
 | 
			
		||||
| 
						 | 
				
			
			@ -97,6 +98,8 @@ public:
 | 
			
		|||
	[[nodiscard]] virtual qint32 height() const;
 | 
			
		||||
	virtual void setHeight(qint32 height);
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] qreal devicePixelRatio() const;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] virtual QuickshellScreenInfo* screen() const;
 | 
			
		||||
	virtual void setScreen(QuickshellScreenInfo* screen);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -122,6 +125,7 @@ signals:
 | 
			
		|||
	void yChanged();
 | 
			
		||||
	void widthChanged();
 | 
			
		||||
	void heightChanged();
 | 
			
		||||
	void devicePixelRatioChanged();
 | 
			
		||||
	void windowTransformChanged();
 | 
			
		||||
	void screenChanged();
 | 
			
		||||
	void colorChanged();
 | 
			
		||||
| 
						 | 
				
			
			@ -192,8 +196,10 @@ public:
 | 
			
		|||
 | 
			
		||||
signals:
 | 
			
		||||
	void exposed();
 | 
			
		||||
	void devicePixelRatioChanged();
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	bool event(QEvent* event) override;
 | 
			
		||||
	void exposeEvent(QExposeEvent* event) override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,6 +55,12 @@ class WindowInterface: public Reloadable {
 | 
			
		|||
	Q_PROPERTY(bool backingWindowVisible READ isBackingWindowVisible NOTIFY backingWindowVisibleChanged);
 | 
			
		||||
	Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
 | 
			
		||||
	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.
 | 
			
		||||
	///
 | 
			
		||||
	/// This may be modified to move the window to the given screen.
 | 
			
		||||
| 
						 | 
				
			
			@ -147,6 +153,8 @@ public:
 | 
			
		|||
	[[nodiscard]] virtual qint32 height() const = 0;
 | 
			
		||||
	virtual void setHeight(qint32 height) = 0;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] virtual qreal devicePixelRatio() const = 0;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] virtual QuickshellScreenInfo* screen() const = 0;
 | 
			
		||||
	virtual void setScreen(QuickshellScreenInfo* screen) = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -171,6 +179,7 @@ signals:
 | 
			
		|||
	void backingWindowVisibleChanged();
 | 
			
		||||
	void widthChanged();
 | 
			
		||||
	void heightChanged();
 | 
			
		||||
	void devicePixelRatioChanged();
 | 
			
		||||
	void screenChanged();
 | 
			
		||||
	void windowTransformChanged();
 | 
			
		||||
	void colorChanged();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -478,6 +478,7 @@ XPanelInterface::XPanelInterface(QObject* parent)
 | 
			
		|||
	QObject::connect(this->panel, &ProxyWindowBase::backerVisibilityChanged, this, &XPanelInterface::backingWindowVisibleChanged);
 | 
			
		||||
	QObject::connect(this->panel, &ProxyWindowBase::heightChanged, this, &XPanelInterface::heightChanged);
 | 
			
		||||
	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::windowTransformChanged, this, &XPanelInterface::windowTransformChanged);
 | 
			
		||||
	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; }
 | 
			
		||||
QQuickItem* XPanelInterface::contentItem() const { return this->panel->contentItem(); }
 | 
			
		||||
bool XPanelInterface::isBackingWindowVisible() const { return this->panel->isVisibleDirect(); }
 | 
			
		||||
qreal XPanelInterface::devicePixelRatio() const { return this->panel->devicePixelRatio(); }
 | 
			
		||||
 | 
			
		||||
// NOLINTBEGIN
 | 
			
		||||
#define proxyPair(type, get, set)                                                                  \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -127,6 +127,8 @@ public:
 | 
			
		|||
	[[nodiscard]] qint32 height() const override;
 | 
			
		||||
	void setHeight(qint32 height) override;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] virtual qreal devicePixelRatio() const override;
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] QuickshellScreenInfo* screen() const override;
 | 
			
		||||
	void setScreen(QuickshellScreenInfo* screen) override;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue