Skip to content

Commit ef077dd

Browse files
committed
core/panelwindow: move Margins to types.hpp
1 parent 2773e54 commit ef077dd

File tree

5 files changed

+51
-44
lines changed

5 files changed

+51
-44
lines changed

src/core/types.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "types.hpp"
22

33
#include <qdebug.h>
4+
#include <qmargins.h>
45
#include <qnamespace.h>
56
#include <qrect.h>
67

@@ -21,3 +22,5 @@ Qt::Edges Edges::toQt(Edges::Flags edges) { return Qt::Edges(edges.toInt()); }
2122
bool Edges::isOpposing(Edges::Flags edges) {
2223
return edges.testFlags(Edges::Top | Edges::Bottom) || edges.testFlags(Edges::Left | Edges::Right);
2324
}
25+
26+
QMargins Margins::qmargins() const { return {this->left, this->top, this->right, this->bottom}; }

src/core/types.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <qdebug.h>
4+
#include <qmargins.h>
45
#include <qnamespace.h>
56
#include <qpoint.h>
67
#include <qqmlintegration.h>
@@ -49,6 +50,33 @@ class Box {
4950

5051
QDebug operator<<(QDebug debug, const Box& box);
5152

53+
class Margins {
54+
Q_GADGET;
55+
Q_PROPERTY(qint32 left MEMBER left);
56+
Q_PROPERTY(qint32 right MEMBER right);
57+
Q_PROPERTY(qint32 top MEMBER top);
58+
Q_PROPERTY(qint32 bottom MEMBER bottom);
59+
QML_CONSTRUCTIBLE_VALUE;
60+
QML_VALUE_TYPE(margins);
61+
62+
public:
63+
[[nodiscard]] bool operator==(const Margins& other) const noexcept {
64+
// clang-format off
65+
return this->left == other.left
66+
&& this->right == other.right
67+
&& this->top == other.top
68+
&& this->bottom == other.bottom;
69+
// clang-format on
70+
}
71+
72+
qint32 left = 0;
73+
qint32 right = 0;
74+
qint32 top = 0;
75+
qint32 bottom = 0;
76+
77+
[[nodiscard]] QMargins qmargins() const;
78+
};
79+
5280
///! Top Left Right Bottom flags.
5381
/// Edge flags can be combined with the `|` operator.
5482
namespace Edges { // NOLINT

src/wayland/wlr_layershell/surface.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ LayerSurface::LayerSurface(LayerShellIntegration* shell, QtWaylandClient::QWayla
162162
this->set_size(size.width(), size.height());
163163
this->set_anchor(toWaylandAnchors(s.anchors));
164164
this->set_margin(
165-
QHighDpi::toNativePixels(s.margins.mTop, qwindow),
166-
QHighDpi::toNativePixels(s.margins.mRight, qwindow),
167-
QHighDpi::toNativePixels(s.margins.mBottom, qwindow),
168-
QHighDpi::toNativePixels(s.margins.mLeft, qwindow)
165+
QHighDpi::toNativePixels(s.margins.top, qwindow),
166+
QHighDpi::toNativePixels(s.margins.right, qwindow),
167+
QHighDpi::toNativePixels(s.margins.bottom, qwindow),
168+
QHighDpi::toNativePixels(s.margins.left, qwindow)
169169
);
170170
this->set_exclusive_zone(QHighDpi::toNativePixels(s.exclusiveZone, qwindow));
171171
this->set_keyboard_interactivity(toWaylandKeyboardFocus(s.keyboardFocus));
@@ -221,10 +221,10 @@ void LayerSurface::commit() {
221221

222222
if (p.margins != c.margins) {
223223
this->set_margin(
224-
QHighDpi::toNativePixels(p.margins.mTop, this->qwindow()),
225-
QHighDpi::toNativePixels(p.margins.mRight, this->qwindow()),
226-
QHighDpi::toNativePixels(p.margins.mBottom, this->qwindow()),
227-
QHighDpi::toNativePixels(p.margins.mLeft, this->qwindow())
224+
QHighDpi::toNativePixels(p.margins.top, this->qwindow()),
225+
QHighDpi::toNativePixels(p.margins.right, this->qwindow()),
226+
QHighDpi::toNativePixels(p.margins.bottom, this->qwindow()),
227+
QHighDpi::toNativePixels(p.margins.left, this->qwindow())
228228
);
229229
}
230230

src/window/panelinterface.hpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <qtypes.h>
66

77
#include "../core/doc.hpp"
8+
#include "../core/types.hpp"
89
#include "windowinterface.hpp"
910

1011
class Anchors {
@@ -35,31 +36,6 @@ class Anchors {
3536
bool mBottom = false;
3637
};
3738

38-
class Margins {
39-
Q_GADGET;
40-
Q_PROPERTY(qint32 left MEMBER mLeft);
41-
Q_PROPERTY(qint32 right MEMBER mRight);
42-
Q_PROPERTY(qint32 top MEMBER mTop);
43-
Q_PROPERTY(qint32 bottom MEMBER mBottom);
44-
QML_VALUE_TYPE(panelMargins);
45-
QML_STRUCTURED_VALUE;
46-
47-
public:
48-
[[nodiscard]] bool operator==(const Margins& other) const noexcept {
49-
// clang-format off
50-
return this->mLeft == other.mLeft
51-
&& this->mRight == other.mRight
52-
&& this->mTop == other.mTop
53-
&& this->mBottom == other.mBottom;
54-
// clang-format on
55-
}
56-
57-
qint32 mLeft = 0;
58-
qint32 mRight = 0;
59-
qint32 mTop = 0;
60-
qint32 mBottom = 0;
61-
};
62-
6339
///! Panel exclusion mode
6440
/// See @@PanelWindow.exclusionMode.
6541
namespace ExclusionMode { // NOLINT

src/x11/panel_window.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "../core/generation.hpp"
2020
#include "../core/qmlscreen.hpp"
21+
#include "../core/types.hpp"
2122
#include "../window/panelinterface.hpp"
2223
#include "../window/proxywindow.hpp"
2324
#include "util.hpp"
@@ -296,15 +297,14 @@ void XPanelWindow::updateDimensions(bool propagate) {
296297
auto geometry = QRect();
297298

298299
if (this->mAnchors.horizontalConstraint()) {
299-
geometry.setX(screenGeometry.x() + this->mMargins.mLeft);
300-
geometry.setWidth(screenGeometry.width() - this->mMargins.mLeft - this->mMargins.mRight);
300+
geometry.setX(screenGeometry.x() + this->mMargins.left);
301+
geometry.setWidth(screenGeometry.width() - this->mMargins.left - this->mMargins.right);
301302
} else {
302303
if (this->mAnchors.mLeft) {
303-
geometry.setX(screenGeometry.x() + this->mMargins.mLeft);
304+
geometry.setX(screenGeometry.x() + this->mMargins.left);
304305
} else if (this->mAnchors.mRight) {
305306
geometry.setX(
306-
screenGeometry.x() + screenGeometry.width() - this->implicitWidth()
307-
- this->mMargins.mRight
307+
screenGeometry.x() + screenGeometry.width() - this->implicitWidth() - this->mMargins.right
308308
);
309309
} else {
310310
geometry.setX(screenGeometry.x() + screenGeometry.width() / 2 - this->implicitWidth() / 2);
@@ -314,15 +314,15 @@ void XPanelWindow::updateDimensions(bool propagate) {
314314
}
315315

316316
if (this->mAnchors.verticalConstraint()) {
317-
geometry.setY(screenGeometry.y() + this->mMargins.mTop);
318-
geometry.setHeight(screenGeometry.height() - this->mMargins.mTop - this->mMargins.mBottom);
317+
geometry.setY(screenGeometry.y() + this->mMargins.top);
318+
geometry.setHeight(screenGeometry.height() - this->mMargins.top - this->mMargins.bottom);
319319
} else {
320320
if (this->mAnchors.mTop) {
321-
geometry.setY(screenGeometry.y() + this->mMargins.mTop);
321+
geometry.setY(screenGeometry.y() + this->mMargins.top);
322322
} else if (this->mAnchors.mBottom) {
323323
geometry.setY(
324324
screenGeometry.y() + screenGeometry.height() - this->implicitHeight()
325-
- this->mMargins.mBottom
325+
- this->mMargins.bottom
326326
);
327327
} else {
328328
geometry.setY(screenGeometry.y() + screenGeometry.height() / 2 - this->implicitHeight() / 2);
@@ -377,10 +377,10 @@ void XPanelWindow::getExclusion(int& side, quint32& exclusiveZone) {
377377
if (autoExclude) {
378378
if (side == 0 || side == 1) {
379379
exclusiveZone =
380-
this->implicitWidth() + (side == 0 ? this->mMargins.mLeft : this->mMargins.mRight);
380+
this->implicitWidth() + (side == 0 ? this->mMargins.left : this->mMargins.right);
381381
} else {
382382
exclusiveZone =
383-
this->implicitHeight() + (side == 2 ? this->mMargins.mTop : this->mMargins.mBottom);
383+
this->implicitHeight() + (side == 2 ? this->mMargins.top : this->mMargins.bottom);
384384
}
385385
} else {
386386
exclusiveZone = this->mExclusiveZone;

0 commit comments

Comments
 (0)