From ef077ddd24150fa5c07900d8d5ce833c76742f1c Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 30 May 2025 00:26:41 -0700 Subject: [PATCH] core/panelwindow: move Margins to types.hpp --- src/core/types.cpp | 3 +++ src/core/types.hpp | 28 ++++++++++++++++++++++++++ src/wayland/wlr_layershell/surface.cpp | 16 +++++++-------- src/window/panelinterface.hpp | 26 +----------------------- src/x11/panel_window.cpp | 22 ++++++++++---------- 5 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/core/types.cpp b/src/core/types.cpp index 5ed63a02..81c1d010 100644 --- a/src/core/types.cpp +++ b/src/core/types.cpp @@ -1,6 +1,7 @@ #include "types.hpp" #include +#include #include #include @@ -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}; } diff --git a/src/core/types.hpp b/src/core/types.hpp index 5c7bd2b1..b6cb2598 100644 --- a/src/core/types.hpp +++ b/src/core/types.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -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 diff --git a/src/wayland/wlr_layershell/surface.cpp b/src/wayland/wlr_layershell/surface.cpp index c690c0a1..3188c6b1 100644 --- a/src/wayland/wlr_layershell/surface.cpp +++ b/src/wayland/wlr_layershell/surface.cpp @@ -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()) ); } diff --git a/src/window/panelinterface.hpp b/src/window/panelinterface.hpp index b9664ff9..22c47c98 100644 --- a/src/window/panelinterface.hpp +++ b/src/window/panelinterface.hpp @@ -5,6 +5,7 @@ #include #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 diff --git a/src/x11/panel_window.cpp b/src/x11/panel_window.cpp index a81b6162..9ffbeb50 100644 --- a/src/x11/panel_window.cpp +++ b/src/x11/panel_window.cpp @@ -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;