forked from quickshell/quickshell
core/window: add implicit size properties to window types
This commit is contained in:
parent
ead9141aca
commit
6a8284dae3
10 changed files with 140 additions and 57 deletions
|
@ -9,15 +9,15 @@
|
|||
#include "proxywindow.hpp"
|
||||
#include "windowinterface.hpp"
|
||||
|
||||
void ProxyFloatingWindow::setWidth(qint32 width) {
|
||||
if (this->window == nullptr || !this->window->isVisible()) {
|
||||
this->ProxyWindowBase::setWidth(width);
|
||||
void ProxyFloatingWindow::trySetWidth(qint32 implicitWidth) {
|
||||
if (!this->window->isVisible()) {
|
||||
this->ProxyWindowBase::trySetWidth(implicitWidth);
|
||||
}
|
||||
}
|
||||
|
||||
void ProxyFloatingWindow::setHeight(qint32 height) {
|
||||
if (this->window == nullptr || !this->window->isVisible()) {
|
||||
this->ProxyWindowBase::setHeight(height);
|
||||
void ProxyFloatingWindow::trySetHeight(qint32 implicitHeight) {
|
||||
if (!this->window->isVisible()) {
|
||||
this->ProxyWindowBase::trySetHeight(implicitHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,8 @@ 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::implicitHeightChanged, this, &FloatingWindowInterface::implicitHeightChanged);
|
||||
QObject::connect(this->window, &ProxyWindowBase::implicitWidthChanged, this, &FloatingWindowInterface::implicitWidthChanged);
|
||||
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);
|
||||
|
@ -64,6 +66,8 @@ qreal FloatingWindowInterface::devicePixelRatio() const { return this->window->d
|
|||
void FloatingWindowInterface::set(type value) { this->window->set(value); }
|
||||
|
||||
proxyPair(bool, isVisible, setVisible);
|
||||
proxyPair(qint32, implicitWidth, setImplicitWidth);
|
||||
proxyPair(qint32, implicitHeight, setImplicitHeight);
|
||||
proxyPair(qint32, width, setWidth);
|
||||
proxyPair(qint32, height, setHeight);
|
||||
proxyPair(QuickshellScreenInfo*, screen, setScreen);
|
||||
|
|
|
@ -12,10 +12,10 @@ class ProxyFloatingWindow: public ProxyWindowBase {
|
|||
public:
|
||||
explicit ProxyFloatingWindow(QObject* parent = nullptr): ProxyWindowBase(parent) {}
|
||||
|
||||
// Setting geometry while the window is visible makes the content item shrinks but not the window
|
||||
// Setting geometry while the window is visible makes the content item shrink but not the window
|
||||
// which is awful so we disable it for floating windows.
|
||||
void setWidth(qint32 width) override;
|
||||
void setHeight(qint32 height) override;
|
||||
void trySetWidth(qint32 implicitWidth) override;
|
||||
void trySetHeight(qint32 implicitHeight) override;
|
||||
};
|
||||
|
||||
///! Standard toplevel operating system window that looks like any other application.
|
||||
|
@ -36,6 +36,12 @@ public:
|
|||
[[nodiscard]] bool isBackingWindowVisible() const override;
|
||||
void setVisible(bool visible) override;
|
||||
|
||||
[[nodiscard]] qint32 implicitWidth() const override;
|
||||
void setImplicitWidth(qint32 implicitWidth) override;
|
||||
|
||||
[[nodiscard]] qint32 implicitHeight() const override;
|
||||
void setImplicitHeight(qint32 implicitHeight) override;
|
||||
|
||||
[[nodiscard]] qint32 width() const override;
|
||||
void setWidth(qint32 width) override;
|
||||
|
||||
|
|
|
@ -203,8 +203,8 @@ void ProxyWindowBase::completeWindow() {
|
|||
this->window->setScreen(this->mScreen);
|
||||
}
|
||||
|
||||
this->setWidth(this->mWidth);
|
||||
this->setHeight(this->mHeight);
|
||||
this->trySetWidth(this->implicitWidth());
|
||||
this->trySetHeight(this->implicitHeight());
|
||||
this->setColor(this->mColor);
|
||||
this->updateMask();
|
||||
|
||||
|
@ -299,28 +299,52 @@ qint32 ProxyWindowBase::y() const {
|
|||
else return this->window->y();
|
||||
}
|
||||
|
||||
qint32 ProxyWindowBase::implicitWidth() const { return this->mImplicitWidth; }
|
||||
|
||||
void ProxyWindowBase::setImplicitWidth(qint32 implicitWidth) {
|
||||
if (implicitWidth == this->mImplicitWidth) return;
|
||||
this->mImplicitWidth = implicitWidth;
|
||||
emit this->implicitWidthChanged();
|
||||
|
||||
if (this->window) this->trySetWidth(implicitWidth);
|
||||
else emit this->widthChanged();
|
||||
}
|
||||
|
||||
void ProxyWindowBase::trySetWidth(qint32 implicitWidth) { this->window->setWidth(implicitWidth); }
|
||||
|
||||
qint32 ProxyWindowBase::implicitHeight() const { return this->mImplicitHeight; }
|
||||
|
||||
void ProxyWindowBase::setImplicitHeight(qint32 implicitHeight) {
|
||||
if (implicitHeight == this->mImplicitHeight) return;
|
||||
this->mImplicitHeight = implicitHeight;
|
||||
emit this->implicitHeightChanged();
|
||||
|
||||
if (this->window) this->trySetHeight(implicitHeight);
|
||||
else emit this->heightChanged();
|
||||
}
|
||||
|
||||
void ProxyWindowBase::trySetHeight(qint32 implicitHeight) {
|
||||
this->window->setHeight(implicitHeight);
|
||||
}
|
||||
|
||||
qint32 ProxyWindowBase::width() const {
|
||||
if (this->window == nullptr) return this->mWidth;
|
||||
if (this->window == nullptr) return this->implicitWidth();
|
||||
else return this->window->width();
|
||||
}
|
||||
|
||||
void ProxyWindowBase::setWidth(qint32 width) {
|
||||
this->mWidth = width;
|
||||
if (this->window == nullptr) {
|
||||
emit this->widthChanged();
|
||||
} else this->window->setWidth(width);
|
||||
this->setImplicitWidth(width);
|
||||
qmlWarning(this) << "Setting `width` is deprecated. Set `implicitWidth` instead.";
|
||||
}
|
||||
|
||||
qint32 ProxyWindowBase::height() const {
|
||||
if (this->window == nullptr) return this->mHeight;
|
||||
if (this->window == nullptr) return this->implicitHeight();
|
||||
else return this->window->height();
|
||||
}
|
||||
|
||||
void ProxyWindowBase::setHeight(qint32 height) {
|
||||
this->mHeight = height;
|
||||
if (this->window == nullptr) {
|
||||
emit this->heightChanged();
|
||||
} else this->window->setHeight(height);
|
||||
this->setImplicitHeight(height);
|
||||
qmlWarning(this) << "Setting `height` is deprecated. Set `implicitHeight` instead.";
|
||||
}
|
||||
|
||||
void ProxyWindowBase::setScreen(QuickshellScreenInfo* screen) {
|
||||
|
|
|
@ -42,6 +42,8 @@ class ProxyWindowBase: public Reloadable {
|
|||
Q_PROPERTY(QQuickWindow* _backingWindow READ backingWindow);
|
||||
Q_PROPERTY(QQuickItem* contentItem READ contentItem CONSTANT);
|
||||
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
|
||||
Q_PROPERTY(qint32 implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged);
|
||||
Q_PROPERTY(qint32 implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged);
|
||||
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);
|
||||
|
@ -92,11 +94,20 @@ public:
|
|||
[[nodiscard]] virtual qint32 x() const;
|
||||
[[nodiscard]] virtual qint32 y() const;
|
||||
|
||||
[[nodiscard]] qint32 implicitWidth() const;
|
||||
void setImplicitWidth(qint32 implicitWidth);
|
||||
|
||||
[[nodiscard]] qint32 implicitHeight() const;
|
||||
void setImplicitHeight(qint32 implicitHeight);
|
||||
|
||||
[[nodiscard]] virtual qint32 width() const;
|
||||
virtual void setWidth(qint32 width);
|
||||
void setWidth(qint32 width);
|
||||
|
||||
[[nodiscard]] virtual qint32 height() const;
|
||||
virtual void setHeight(qint32 height);
|
||||
void setHeight(qint32 height);
|
||||
|
||||
virtual void trySetWidth(qint32 implicitWidth);
|
||||
virtual void trySetHeight(qint32 implicitHeight);
|
||||
|
||||
[[nodiscard]] qreal devicePixelRatio() const;
|
||||
|
||||
|
@ -124,6 +135,8 @@ signals:
|
|||
void backerVisibilityChanged();
|
||||
void xChanged();
|
||||
void yChanged();
|
||||
void implicitWidthChanged();
|
||||
void implicitHeightChanged();
|
||||
void widthChanged();
|
||||
void heightChanged();
|
||||
void devicePixelRatioChanged();
|
||||
|
@ -145,8 +158,8 @@ protected slots:
|
|||
|
||||
protected:
|
||||
bool mVisible = true;
|
||||
qint32 mWidth = 100;
|
||||
qint32 mHeight = 100;
|
||||
qint32 mImplicitWidth = 100;
|
||||
qint32 mImplicitHeight = 100;
|
||||
QScreen* mScreen = nullptr;
|
||||
QColor mColor = Qt::white;
|
||||
PendingRegion* mMask = nullptr;
|
||||
|
|
|
@ -53,7 +53,17 @@ class WindowInterface: public Reloadable {
|
|||
/// This property is useful for ensuring windows spawn in a specific order, and you should
|
||||
/// not use it in place of [visible](#prop.visible).
|
||||
Q_PROPERTY(bool backingWindowVisible READ isBackingWindowVisible NOTIFY backingWindowVisibleChanged);
|
||||
/// The window's desired width.
|
||||
Q_PROPERTY(qint32 implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged);
|
||||
/// The window's desired height.
|
||||
Q_PROPERTY(qint32 implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged);
|
||||
/// The window's actual width.
|
||||
///
|
||||
/// Setting this property is deprecated. Set @@implicitWidth instead.
|
||||
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
|
||||
/// The window's actual height.
|
||||
///
|
||||
/// Setting this property is deprecated. Set @@implicitHeight instead.
|
||||
Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged);
|
||||
/// The ratio between logical pixels and monitor pixels.
|
||||
///
|
||||
|
@ -147,6 +157,12 @@ public:
|
|||
[[nodiscard]] virtual bool isBackingWindowVisible() const = 0;
|
||||
virtual void setVisible(bool visible) = 0;
|
||||
|
||||
[[nodiscard]] virtual qint32 implicitWidth() const = 0;
|
||||
virtual void setImplicitWidth(qint32 implicitWidth) = 0;
|
||||
|
||||
[[nodiscard]] virtual qint32 implicitHeight() const = 0;
|
||||
virtual void setImplicitHeight(qint32 implicitHeight) = 0;
|
||||
|
||||
[[nodiscard]] virtual qint32 width() const = 0;
|
||||
virtual void setWidth(qint32 width) = 0;
|
||||
|
||||
|
@ -177,6 +193,8 @@ signals:
|
|||
void windowConnected();
|
||||
void visibleChanged();
|
||||
void backingWindowVisibleChanged();
|
||||
void implicitWidthChanged();
|
||||
void implicitHeightChanged();
|
||||
void widthChanged();
|
||||
void heightChanged();
|
||||
void devicePixelRatioChanged();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue