core/panelwindow: move Margins to types.hpp

This commit is contained in:
outfoxxed 2025-05-30 00:26:41 -07:00
parent 2773e5468f
commit ef077ddd24
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 51 additions and 44 deletions

View file

@ -1,6 +1,7 @@
#include "types.hpp"
#include <qdebug.h>
#include <qmargins.h>
#include <qnamespace.h>
#include <qrect.h>
@ -21,3 +22,5 @@ Qt::Edges Edges::toQt(Edges::Flags edges) { return Qt::Edges(edges.toInt()); }
bool Edges::isOpposing(Edges::Flags edges) {
return edges.testFlags(Edges::Top | Edges::Bottom) || edges.testFlags(Edges::Left | Edges::Right);
}
QMargins Margins::qmargins() const { return {this->left, this->top, this->right, this->bottom}; }

View file

@ -1,6 +1,7 @@
#pragma once
#include <qdebug.h>
#include <qmargins.h>
#include <qnamespace.h>
#include <qpoint.h>
#include <qqmlintegration.h>
@ -49,6 +50,33 @@ public:
QDebug operator<<(QDebug debug, const Box& box);
class Margins {
Q_GADGET;
Q_PROPERTY(qint32 left MEMBER left);
Q_PROPERTY(qint32 right MEMBER right);
Q_PROPERTY(qint32 top MEMBER top);
Q_PROPERTY(qint32 bottom MEMBER bottom);
QML_CONSTRUCTIBLE_VALUE;
QML_VALUE_TYPE(margins);
public:
[[nodiscard]] bool operator==(const Margins& other) const noexcept {
// clang-format off
return this->left == other.left
&& this->right == other.right
&& this->top == other.top
&& this->bottom == other.bottom;
// clang-format on
}
qint32 left = 0;
qint32 right = 0;
qint32 top = 0;
qint32 bottom = 0;
[[nodiscard]] QMargins qmargins() const;
};
///! Top Left Right Bottom flags.
/// Edge flags can be combined with the `|` operator.
namespace Edges { // NOLINT

View file

@ -162,10 +162,10 @@ LayerSurface::LayerSurface(LayerShellIntegration* shell, QtWaylandClient::QWayla
this->set_size(size.width(), size.height());
this->set_anchor(toWaylandAnchors(s.anchors));
this->set_margin(
QHighDpi::toNativePixels(s.margins.mTop, qwindow),
QHighDpi::toNativePixels(s.margins.mRight, qwindow),
QHighDpi::toNativePixels(s.margins.mBottom, qwindow),
QHighDpi::toNativePixels(s.margins.mLeft, qwindow)
QHighDpi::toNativePixels(s.margins.top, qwindow),
QHighDpi::toNativePixels(s.margins.right, qwindow),
QHighDpi::toNativePixels(s.margins.bottom, qwindow),
QHighDpi::toNativePixels(s.margins.left, qwindow)
);
this->set_exclusive_zone(QHighDpi::toNativePixels(s.exclusiveZone, qwindow));
this->set_keyboard_interactivity(toWaylandKeyboardFocus(s.keyboardFocus));
@ -221,10 +221,10 @@ void LayerSurface::commit() {
if (p.margins != c.margins) {
this->set_margin(
QHighDpi::toNativePixels(p.margins.mTop, this->qwindow()),
QHighDpi::toNativePixels(p.margins.mRight, this->qwindow()),
QHighDpi::toNativePixels(p.margins.mBottom, this->qwindow()),
QHighDpi::toNativePixels(p.margins.mLeft, this->qwindow())
QHighDpi::toNativePixels(p.margins.top, this->qwindow()),
QHighDpi::toNativePixels(p.margins.right, this->qwindow()),
QHighDpi::toNativePixels(p.margins.bottom, this->qwindow()),
QHighDpi::toNativePixels(p.margins.left, this->qwindow())
);
}

View file

@ -5,6 +5,7 @@
#include <qtypes.h>
#include "../core/doc.hpp"
#include "../core/types.hpp"
#include "windowinterface.hpp"
class Anchors {
@ -35,31 +36,6 @@ public:
bool mBottom = false;
};
class Margins {
Q_GADGET;
Q_PROPERTY(qint32 left MEMBER mLeft);
Q_PROPERTY(qint32 right MEMBER mRight);
Q_PROPERTY(qint32 top MEMBER mTop);
Q_PROPERTY(qint32 bottom MEMBER mBottom);
QML_VALUE_TYPE(panelMargins);
QML_STRUCTURED_VALUE;
public:
[[nodiscard]] bool operator==(const Margins& other) const noexcept {
// clang-format off
return this->mLeft == other.mLeft
&& this->mRight == other.mRight
&& this->mTop == other.mTop
&& this->mBottom == other.mBottom;
// clang-format on
}
qint32 mLeft = 0;
qint32 mRight = 0;
qint32 mTop = 0;
qint32 mBottom = 0;
};
///! Panel exclusion mode
/// See @@PanelWindow.exclusionMode.
namespace ExclusionMode { // NOLINT

View file

@ -18,6 +18,7 @@
#include "../core/generation.hpp"
#include "../core/qmlscreen.hpp"
#include "../core/types.hpp"
#include "../window/panelinterface.hpp"
#include "../window/proxywindow.hpp"
#include "util.hpp"
@ -296,15 +297,14 @@ void XPanelWindow::updateDimensions(bool propagate) {
auto geometry = QRect();
if (this->mAnchors.horizontalConstraint()) {
geometry.setX(screenGeometry.x() + this->mMargins.mLeft);
geometry.setWidth(screenGeometry.width() - this->mMargins.mLeft - this->mMargins.mRight);
geometry.setX(screenGeometry.x() + this->mMargins.left);
geometry.setWidth(screenGeometry.width() - this->mMargins.left - this->mMargins.right);
} else {
if (this->mAnchors.mLeft) {
geometry.setX(screenGeometry.x() + this->mMargins.mLeft);
geometry.setX(screenGeometry.x() + this->mMargins.left);
} else if (this->mAnchors.mRight) {
geometry.setX(
screenGeometry.x() + screenGeometry.width() - this->implicitWidth()
- this->mMargins.mRight
screenGeometry.x() + screenGeometry.width() - this->implicitWidth() - this->mMargins.right
);
} else {
geometry.setX(screenGeometry.x() + screenGeometry.width() / 2 - this->implicitWidth() / 2);
@ -314,15 +314,15 @@ void XPanelWindow::updateDimensions(bool propagate) {
}
if (this->mAnchors.verticalConstraint()) {
geometry.setY(screenGeometry.y() + this->mMargins.mTop);
geometry.setHeight(screenGeometry.height() - this->mMargins.mTop - this->mMargins.mBottom);
geometry.setY(screenGeometry.y() + this->mMargins.top);
geometry.setHeight(screenGeometry.height() - this->mMargins.top - this->mMargins.bottom);
} else {
if (this->mAnchors.mTop) {
geometry.setY(screenGeometry.y() + this->mMargins.mTop);
geometry.setY(screenGeometry.y() + this->mMargins.top);
} else if (this->mAnchors.mBottom) {
geometry.setY(
screenGeometry.y() + screenGeometry.height() - this->implicitHeight()
- this->mMargins.mBottom
- this->mMargins.bottom
);
} else {
geometry.setY(screenGeometry.y() + screenGeometry.height() / 2 - this->implicitHeight() / 2);
@ -377,10 +377,10 @@ void XPanelWindow::getExclusion(int& side, quint32& exclusiveZone) {
if (autoExclude) {
if (side == 0 || side == 1) {
exclusiveZone =
this->implicitWidth() + (side == 0 ? this->mMargins.mLeft : this->mMargins.mRight);
this->implicitWidth() + (side == 0 ? this->mMargins.left : this->mMargins.right);
} else {
exclusiveZone =
this->implicitHeight() + (side == 2 ? this->mMargins.mTop : this->mMargins.mBottom);
this->implicitHeight() + (side == 2 ? this->mMargins.top : this->mMargins.bottom);
}
} else {
exclusiveZone = this->mExclusiveZone;