Skip to content

Commit 6a8284d

Browse files
committed
core/window: add implicit size properties to window types
1 parent ead9141 commit 6a8284d

File tree

10 files changed

+140
-57
lines changed

10 files changed

+140
-57
lines changed

src/wayland/wlr_layershell.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,17 @@ bool WlrLayershell::deleteOnInvisible() const {
7171
return true;
7272
}
7373

74-
void WlrLayershell::setWidth(qint32 width) {
75-
this->mWidth = width;
76-
74+
void WlrLayershell::trySetWidth(qint32 implicitWidth) {
7775
// only update the actual size if not blocked by anchors
7876
if (!this->ext->anchors().horizontalConstraint()) {
79-
this->ProxyWindowBase::setWidth(width);
77+
this->ProxyWindowBase::trySetWidth(implicitWidth);
8078
}
8179
}
8280

83-
void WlrLayershell::setHeight(qint32 height) {
84-
this->mHeight = height;
85-
81+
void WlrLayershell::trySetHeight(qint32 implicitHeight) {
8682
// only update the actual size if not blocked by anchors
8783
if (!this->ext->anchors().verticalConstraint()) {
88-
this->ProxyWindowBase::setHeight(height);
84+
this->ProxyWindowBase::trySetHeight(implicitHeight);
8985
}
9086
}
9187

@@ -108,10 +104,11 @@ Anchors WlrLayershell::anchors() const { return this->ext->anchors(); }
108104

109105
void WlrLayershell::setAnchors(Anchors anchors) {
110106
this->ext->setAnchors(anchors);
107+
if (!this->window) return;
111108

112109
// explicitly set width values are tracked so the entire screen isn't covered if an anchor is removed.
113-
if (!anchors.horizontalConstraint()) this->ProxyWindowBase::setWidth(this->mWidth);
114-
if (!anchors.verticalConstraint()) this->ProxyWindowBase::setHeight(this->mHeight);
110+
if (!anchors.horizontalConstraint()) this->ProxyWindowBase::trySetWidth(this->implicitWidth());
111+
if (!anchors.verticalConstraint()) this->ProxyWindowBase::trySetHeight(this->implicitHeight());
115112
}
116113

117114
bool WlrLayershell::aboveWindows() const { return this->layer() > WlrLayer::Bottom; }
@@ -190,6 +187,8 @@ WaylandPanelInterface::WaylandPanelInterface(QObject* parent)
190187
QObject::connect(this->layer, &ProxyWindowBase::windowConnected, this, &WaylandPanelInterface::windowConnected);
191188
QObject::connect(this->layer, &ProxyWindowBase::visibleChanged, this, &WaylandPanelInterface::visibleChanged);
192189
QObject::connect(this->layer, &ProxyWindowBase::backerVisibilityChanged, this, &WaylandPanelInterface::backingWindowVisibleChanged);
190+
QObject::connect(this->layer, &ProxyWindowBase::implicitHeightChanged, this, &WaylandPanelInterface::implicitHeightChanged);
191+
QObject::connect(this->layer, &ProxyWindowBase::implicitWidthChanged, this, &WaylandPanelInterface::implicitWidthChanged);
193192
QObject::connect(this->layer, &ProxyWindowBase::heightChanged, this, &WaylandPanelInterface::heightChanged);
194193
QObject::connect(this->layer, &ProxyWindowBase::widthChanged, this, &WaylandPanelInterface::widthChanged);
195194
QObject::connect(this->layer, &ProxyWindowBase::devicePixelRatioChanged, this, &WaylandPanelInterface::devicePixelRatioChanged);
@@ -232,6 +231,8 @@ qreal WaylandPanelInterface::devicePixelRatio() const { return this->layer->devi
232231
void WaylandPanelInterface::set(type value) { this->layer->set(value); }
233232

234233
proxyPair(bool, isVisible, setVisible);
234+
proxyPair(qint32, implicitWidth, setImplicitWidth);
235+
proxyPair(qint32, implicitHeight, setImplicitHeight);
235236
proxyPair(qint32, width, setWidth);
236237
proxyPair(qint32, height, setHeight);
237238
proxyPair(QuickshellScreenInfo*, screen, setScreen);

src/wayland/wlr_layershell.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class WlrLayershell: public ProxyWindowBase {
6969
void connectWindow() override;
7070
[[nodiscard]] bool deleteOnInvisible() const override;
7171

72-
void setWidth(qint32 width) override;
73-
void setHeight(qint32 height) override;
72+
void trySetWidth(qint32 implicitWidth) override;
73+
void trySetHeight(qint32 implicitHeight) override;
7474

7575
void setScreen(QuickshellScreenInfo* screen) override;
7676

@@ -140,6 +140,12 @@ class WaylandPanelInterface: public PanelWindowInterface {
140140
[[nodiscard]] bool isBackingWindowVisible() const override;
141141
void setVisible(bool visible) override;
142142

143+
[[nodiscard]] qint32 implicitWidth() const override;
144+
void setImplicitWidth(qint32 implicitWidth) override;
145+
146+
[[nodiscard]] qint32 implicitHeight() const override;
147+
void setImplicitHeight(qint32 implicitHeight) override;
148+
143149
[[nodiscard]] qint32 width() const override;
144150
void setWidth(qint32 width) override;
145151

src/wayland/wlr_layershell/surface.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "surface.hpp"
2+
#include <algorithm>
23
#include <any>
34

45
#include <private/qhighdpiscaling_p.h>
@@ -61,8 +62,8 @@ toWaylandKeyboardFocus(const WlrKeyboardFocus::Enum& focus) noexcept {
6162

6263
[[nodiscard]] QSize constrainedSize(const Anchors& anchors, const QSize& size) noexcept {
6364
return QSize(
64-
anchors.horizontalConstraint() ? 0 : size.width(),
65-
anchors.verticalConstraint() ? 0 : size.height()
65+
anchors.horizontalConstraint() ? 0 : std::max(1, size.width()),
66+
anchors.verticalConstraint() ? 0 : std::max(1, size.height())
6667
);
6768
}
6869

src/window/floatingwindow.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
#include "proxywindow.hpp"
1010
#include "windowinterface.hpp"
1111

12-
void ProxyFloatingWindow::setWidth(qint32 width) {
13-
if (this->window == nullptr || !this->window->isVisible()) {
14-
this->ProxyWindowBase::setWidth(width);
12+
void ProxyFloatingWindow::trySetWidth(qint32 implicitWidth) {
13+
if (!this->window->isVisible()) {
14+
this->ProxyWindowBase::trySetWidth(implicitWidth);
1515
}
1616
}
1717

18-
void ProxyFloatingWindow::setHeight(qint32 height) {
19-
if (this->window == nullptr || !this->window->isVisible()) {
20-
this->ProxyWindowBase::setHeight(height);
18+
void ProxyFloatingWindow::trySetHeight(qint32 implicitHeight) {
19+
if (!this->window->isVisible()) {
20+
this->ProxyWindowBase::trySetHeight(implicitHeight);
2121
}
2222
}
2323

@@ -32,6 +32,8 @@ FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
3232
QObject::connect(this->window, &ProxyWindowBase::backerVisibilityChanged, this, &FloatingWindowInterface::backingWindowVisibleChanged);
3333
QObject::connect(this->window, &ProxyWindowBase::heightChanged, this, &FloatingWindowInterface::heightChanged);
3434
QObject::connect(this->window, &ProxyWindowBase::widthChanged, this, &FloatingWindowInterface::widthChanged);
35+
QObject::connect(this->window, &ProxyWindowBase::implicitHeightChanged, this, &FloatingWindowInterface::implicitHeightChanged);
36+
QObject::connect(this->window, &ProxyWindowBase::implicitWidthChanged, this, &FloatingWindowInterface::implicitWidthChanged);
3537
QObject::connect(this->window, &ProxyWindowBase::devicePixelRatioChanged, this, &FloatingWindowInterface::devicePixelRatioChanged);
3638
QObject::connect(this->window, &ProxyWindowBase::screenChanged, this, &FloatingWindowInterface::screenChanged);
3739
QObject::connect(this->window, &ProxyWindowBase::windowTransformChanged, this, &FloatingWindowInterface::windowTransformChanged);
@@ -64,6 +66,8 @@ qreal FloatingWindowInterface::devicePixelRatio() const { return this->window->d
6466
void FloatingWindowInterface::set(type value) { this->window->set(value); }
6567

6668
proxyPair(bool, isVisible, setVisible);
69+
proxyPair(qint32, implicitWidth, setImplicitWidth);
70+
proxyPair(qint32, implicitHeight, setImplicitHeight);
6771
proxyPair(qint32, width, setWidth);
6872
proxyPair(qint32, height, setHeight);
6973
proxyPair(QuickshellScreenInfo*, screen, setScreen);

src/window/floatingwindow.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class ProxyFloatingWindow: public ProxyWindowBase {
1212
public:
1313
explicit ProxyFloatingWindow(QObject* parent = nullptr): ProxyWindowBase(parent) {}
1414

15-
// Setting geometry while the window is visible makes the content item shrinks but not the window
15+
// Setting geometry while the window is visible makes the content item shrink but not the window
1616
// which is awful so we disable it for floating windows.
17-
void setWidth(qint32 width) override;
18-
void setHeight(qint32 height) override;
17+
void trySetWidth(qint32 implicitWidth) override;
18+
void trySetHeight(qint32 implicitHeight) override;
1919
};
2020

2121
///! Standard toplevel operating system window that looks like any other application.
@@ -36,6 +36,12 @@ class FloatingWindowInterface: public WindowInterface {
3636
[[nodiscard]] bool isBackingWindowVisible() const override;
3737
void setVisible(bool visible) override;
3838

39+
[[nodiscard]] qint32 implicitWidth() const override;
40+
void setImplicitWidth(qint32 implicitWidth) override;
41+
42+
[[nodiscard]] qint32 implicitHeight() const override;
43+
void setImplicitHeight(qint32 implicitHeight) override;
44+
3945
[[nodiscard]] qint32 width() const override;
4046
void setWidth(qint32 width) override;
4147

src/window/proxywindow.cpp

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ void ProxyWindowBase::completeWindow() {
203203
this->window->setScreen(this->mScreen);
204204
}
205205

206-
this->setWidth(this->mWidth);
207-
this->setHeight(this->mHeight);
206+
this->trySetWidth(this->implicitWidth());
207+
this->trySetHeight(this->implicitHeight());
208208
this->setColor(this->mColor);
209209
this->updateMask();
210210

@@ -299,28 +299,52 @@ qint32 ProxyWindowBase::y() const {
299299
else return this->window->y();
300300
}
301301

302+
qint32 ProxyWindowBase::implicitWidth() const { return this->mImplicitWidth; }
303+
304+
void ProxyWindowBase::setImplicitWidth(qint32 implicitWidth) {
305+
if (implicitWidth == this->mImplicitWidth) return;
306+
this->mImplicitWidth = implicitWidth;
307+
emit this->implicitWidthChanged();
308+
309+
if (this->window) this->trySetWidth(implicitWidth);
310+
else emit this->widthChanged();
311+
}
312+
313+
void ProxyWindowBase::trySetWidth(qint32 implicitWidth) { this->window->setWidth(implicitWidth); }
314+
315+
qint32 ProxyWindowBase::implicitHeight() const { return this->mImplicitHeight; }
316+
317+
void ProxyWindowBase::setImplicitHeight(qint32 implicitHeight) {
318+
if (implicitHeight == this->mImplicitHeight) return;
319+
this->mImplicitHeight = implicitHeight;
320+
emit this->implicitHeightChanged();
321+
322+
if (this->window) this->trySetHeight(implicitHeight);
323+
else emit this->heightChanged();
324+
}
325+
326+
void ProxyWindowBase::trySetHeight(qint32 implicitHeight) {
327+
this->window->setHeight(implicitHeight);
328+
}
329+
302330
qint32 ProxyWindowBase::width() const {
303-
if (this->window == nullptr) return this->mWidth;
331+
if (this->window == nullptr) return this->implicitWidth();
304332
else return this->window->width();
305333
}
306334

307335
void ProxyWindowBase::setWidth(qint32 width) {
308-
this->mWidth = width;
309-
if (this->window == nullptr) {
310-
emit this->widthChanged();
311-
} else this->window->setWidth(width);
336+
this->setImplicitWidth(width);
337+
qmlWarning(this) << "Setting `width` is deprecated. Set `implicitWidth` instead.";
312338
}
313339

314340
qint32 ProxyWindowBase::height() const {
315-
if (this->window == nullptr) return this->mHeight;
341+
if (this->window == nullptr) return this->implicitHeight();
316342
else return this->window->height();
317343
}
318344

319345
void ProxyWindowBase::setHeight(qint32 height) {
320-
this->mHeight = height;
321-
if (this->window == nullptr) {
322-
emit this->heightChanged();
323-
} else this->window->setHeight(height);
346+
this->setImplicitHeight(height);
347+
qmlWarning(this) << "Setting `height` is deprecated. Set `implicitHeight` instead.";
324348
}
325349

326350
void ProxyWindowBase::setScreen(QuickshellScreenInfo* screen) {

src/window/proxywindow.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class ProxyWindowBase: public Reloadable {
4242
Q_PROPERTY(QQuickWindow* _backingWindow READ backingWindow);
4343
Q_PROPERTY(QQuickItem* contentItem READ contentItem CONSTANT);
4444
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
45+
Q_PROPERTY(qint32 implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged);
46+
Q_PROPERTY(qint32 implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged);
4547
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
4648
Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged);
4749
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged);
@@ -92,11 +94,20 @@ class ProxyWindowBase: public Reloadable {
9294
[[nodiscard]] virtual qint32 x() const;
9395
[[nodiscard]] virtual qint32 y() const;
9496

97+
[[nodiscard]] qint32 implicitWidth() const;
98+
void setImplicitWidth(qint32 implicitWidth);
99+
100+
[[nodiscard]] qint32 implicitHeight() const;
101+
void setImplicitHeight(qint32 implicitHeight);
102+
95103
[[nodiscard]] virtual qint32 width() const;
96-
virtual void setWidth(qint32 width);
104+
void setWidth(qint32 width);
97105

98106
[[nodiscard]] virtual qint32 height() const;
99-
virtual void setHeight(qint32 height);
107+
void setHeight(qint32 height);
108+
109+
virtual void trySetWidth(qint32 implicitWidth);
110+
virtual void trySetHeight(qint32 implicitHeight);
100111

101112
[[nodiscard]] qreal devicePixelRatio() const;
102113

@@ -124,6 +135,8 @@ class ProxyWindowBase: public Reloadable {
124135
void backerVisibilityChanged();
125136
void xChanged();
126137
void yChanged();
138+
void implicitWidthChanged();
139+
void implicitHeightChanged();
127140
void widthChanged();
128141
void heightChanged();
129142
void devicePixelRatioChanged();
@@ -145,8 +158,8 @@ protected slots:
145158

146159
protected:
147160
bool mVisible = true;
148-
qint32 mWidth = 100;
149-
qint32 mHeight = 100;
161+
qint32 mImplicitWidth = 100;
162+
qint32 mImplicitHeight = 100;
150163
QScreen* mScreen = nullptr;
151164
QColor mColor = Qt::white;
152165
PendingRegion* mMask = nullptr;

src/window/windowinterface.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ class WindowInterface: public Reloadable {
5353
/// This property is useful for ensuring windows spawn in a specific order, and you should
5454
/// not use it in place of [visible](#prop.visible).
5555
Q_PROPERTY(bool backingWindowVisible READ isBackingWindowVisible NOTIFY backingWindowVisibleChanged);
56+
/// The window's desired width.
57+
Q_PROPERTY(qint32 implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged);
58+
/// The window's desired height.
59+
Q_PROPERTY(qint32 implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged);
60+
/// The window's actual width.
61+
///
62+
/// Setting this property is deprecated. Set @@implicitWidth instead.
5663
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
64+
/// The window's actual height.
65+
///
66+
/// Setting this property is deprecated. Set @@implicitHeight instead.
5767
Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged);
5868
/// The ratio between logical pixels and monitor pixels.
5969
///
@@ -147,6 +157,12 @@ class WindowInterface: public Reloadable {
147157
[[nodiscard]] virtual bool isBackingWindowVisible() const = 0;
148158
virtual void setVisible(bool visible) = 0;
149159

160+
[[nodiscard]] virtual qint32 implicitWidth() const = 0;
161+
virtual void setImplicitWidth(qint32 implicitWidth) = 0;
162+
163+
[[nodiscard]] virtual qint32 implicitHeight() const = 0;
164+
virtual void setImplicitHeight(qint32 implicitHeight) = 0;
165+
150166
[[nodiscard]] virtual qint32 width() const = 0;
151167
virtual void setWidth(qint32 width) = 0;
152168

@@ -177,6 +193,8 @@ class WindowInterface: public Reloadable {
177193
void windowConnected();
178194
void visibleChanged();
179195
void backingWindowVisibleChanged();
196+
void implicitWidthChanged();
197+
void implicitHeightChanged();
180198
void widthChanged();
181199
void heightChanged();
182200
void devicePixelRatioChanged();

0 commit comments

Comments
 (0)