forked from quickshell/quickshell
		
	core/panelwindow: move Margins to types.hpp
This commit is contained in:
		
							parent
							
								
									2773e5468f
								
							
						
					
					
						commit
						ef077ddd24
					
				
					 5 changed files with 51 additions and 44 deletions
				
			
		| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
#include "types.hpp"
 | 
					#include "types.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <qdebug.h>
 | 
					#include <qdebug.h>
 | 
				
			||||||
 | 
					#include <qmargins.h>
 | 
				
			||||||
#include <qnamespace.h>
 | 
					#include <qnamespace.h>
 | 
				
			||||||
#include <qrect.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) {
 | 
					bool Edges::isOpposing(Edges::Flags edges) {
 | 
				
			||||||
	return edges.testFlags(Edges::Top | Edges::Bottom) || edges.testFlags(Edges::Left | Edges::Right);
 | 
						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}; }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <qdebug.h>
 | 
					#include <qdebug.h>
 | 
				
			||||||
 | 
					#include <qmargins.h>
 | 
				
			||||||
#include <qnamespace.h>
 | 
					#include <qnamespace.h>
 | 
				
			||||||
#include <qpoint.h>
 | 
					#include <qpoint.h>
 | 
				
			||||||
#include <qqmlintegration.h>
 | 
					#include <qqmlintegration.h>
 | 
				
			||||||
| 
						 | 
					@ -49,6 +50,33 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QDebug operator<<(QDebug debug, const Box& box);
 | 
					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.
 | 
					///! Top Left Right Bottom flags.
 | 
				
			||||||
/// Edge flags can be combined with the `|` operator.
 | 
					/// Edge flags can be combined with the `|` operator.
 | 
				
			||||||
namespace Edges { // NOLINT
 | 
					namespace Edges { // NOLINT
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -162,10 +162,10 @@ LayerSurface::LayerSurface(LayerShellIntegration* shell, QtWaylandClient::QWayla
 | 
				
			||||||
	this->set_size(size.width(), size.height());
 | 
						this->set_size(size.width(), size.height());
 | 
				
			||||||
	this->set_anchor(toWaylandAnchors(s.anchors));
 | 
						this->set_anchor(toWaylandAnchors(s.anchors));
 | 
				
			||||||
	this->set_margin(
 | 
						this->set_margin(
 | 
				
			||||||
	    QHighDpi::toNativePixels(s.margins.mTop, qwindow),
 | 
						    QHighDpi::toNativePixels(s.margins.top, qwindow),
 | 
				
			||||||
	    QHighDpi::toNativePixels(s.margins.mRight, qwindow),
 | 
						    QHighDpi::toNativePixels(s.margins.right, qwindow),
 | 
				
			||||||
	    QHighDpi::toNativePixels(s.margins.mBottom, qwindow),
 | 
						    QHighDpi::toNativePixels(s.margins.bottom, qwindow),
 | 
				
			||||||
	    QHighDpi::toNativePixels(s.margins.mLeft, qwindow)
 | 
						    QHighDpi::toNativePixels(s.margins.left, qwindow)
 | 
				
			||||||
	);
 | 
						);
 | 
				
			||||||
	this->set_exclusive_zone(QHighDpi::toNativePixels(s.exclusiveZone, qwindow));
 | 
						this->set_exclusive_zone(QHighDpi::toNativePixels(s.exclusiveZone, qwindow));
 | 
				
			||||||
	this->set_keyboard_interactivity(toWaylandKeyboardFocus(s.keyboardFocus));
 | 
						this->set_keyboard_interactivity(toWaylandKeyboardFocus(s.keyboardFocus));
 | 
				
			||||||
| 
						 | 
					@ -221,10 +221,10 @@ void LayerSurface::commit() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (p.margins != c.margins) {
 | 
						if (p.margins != c.margins) {
 | 
				
			||||||
		this->set_margin(
 | 
							this->set_margin(
 | 
				
			||||||
		    QHighDpi::toNativePixels(p.margins.mTop, this->qwindow()),
 | 
							    QHighDpi::toNativePixels(p.margins.top, this->qwindow()),
 | 
				
			||||||
		    QHighDpi::toNativePixels(p.margins.mRight, this->qwindow()),
 | 
							    QHighDpi::toNativePixels(p.margins.right, this->qwindow()),
 | 
				
			||||||
		    QHighDpi::toNativePixels(p.margins.mBottom, this->qwindow()),
 | 
							    QHighDpi::toNativePixels(p.margins.bottom, this->qwindow()),
 | 
				
			||||||
		    QHighDpi::toNativePixels(p.margins.mLeft, this->qwindow())
 | 
							    QHighDpi::toNativePixels(p.margins.left, this->qwindow())
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
#include <qtypes.h>
 | 
					#include <qtypes.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "../core/doc.hpp"
 | 
					#include "../core/doc.hpp"
 | 
				
			||||||
 | 
					#include "../core/types.hpp"
 | 
				
			||||||
#include "windowinterface.hpp"
 | 
					#include "windowinterface.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Anchors {
 | 
					class Anchors {
 | 
				
			||||||
| 
						 | 
					@ -35,31 +36,6 @@ public:
 | 
				
			||||||
	bool mBottom = false;
 | 
						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
 | 
					///! Panel exclusion mode
 | 
				
			||||||
/// See @@PanelWindow.exclusionMode.
 | 
					/// See @@PanelWindow.exclusionMode.
 | 
				
			||||||
namespace ExclusionMode { // NOLINT
 | 
					namespace ExclusionMode { // NOLINT
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "../core/generation.hpp"
 | 
					#include "../core/generation.hpp"
 | 
				
			||||||
#include "../core/qmlscreen.hpp"
 | 
					#include "../core/qmlscreen.hpp"
 | 
				
			||||||
 | 
					#include "../core/types.hpp"
 | 
				
			||||||
#include "../window/panelinterface.hpp"
 | 
					#include "../window/panelinterface.hpp"
 | 
				
			||||||
#include "../window/proxywindow.hpp"
 | 
					#include "../window/proxywindow.hpp"
 | 
				
			||||||
#include "util.hpp"
 | 
					#include "util.hpp"
 | 
				
			||||||
| 
						 | 
					@ -296,15 +297,14 @@ void XPanelWindow::updateDimensions(bool propagate) {
 | 
				
			||||||
	auto geometry = QRect();
 | 
						auto geometry = QRect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (this->mAnchors.horizontalConstraint()) {
 | 
						if (this->mAnchors.horizontalConstraint()) {
 | 
				
			||||||
		geometry.setX(screenGeometry.x() + this->mMargins.mLeft);
 | 
							geometry.setX(screenGeometry.x() + this->mMargins.left);
 | 
				
			||||||
		geometry.setWidth(screenGeometry.width() - this->mMargins.mLeft - this->mMargins.mRight);
 | 
							geometry.setWidth(screenGeometry.width() - this->mMargins.left - this->mMargins.right);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if (this->mAnchors.mLeft) {
 | 
							if (this->mAnchors.mLeft) {
 | 
				
			||||||
			geometry.setX(screenGeometry.x() + this->mMargins.mLeft);
 | 
								geometry.setX(screenGeometry.x() + this->mMargins.left);
 | 
				
			||||||
		} else if (this->mAnchors.mRight) {
 | 
							} else if (this->mAnchors.mRight) {
 | 
				
			||||||
			geometry.setX(
 | 
								geometry.setX(
 | 
				
			||||||
			    screenGeometry.x() + screenGeometry.width() - this->implicitWidth()
 | 
								    screenGeometry.x() + screenGeometry.width() - this->implicitWidth() - this->mMargins.right
 | 
				
			||||||
			    - this->mMargins.mRight
 | 
					 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			geometry.setX(screenGeometry.x() + screenGeometry.width() / 2 - this->implicitWidth() / 2);
 | 
								geometry.setX(screenGeometry.x() + screenGeometry.width() / 2 - this->implicitWidth() / 2);
 | 
				
			||||||
| 
						 | 
					@ -314,15 +314,15 @@ void XPanelWindow::updateDimensions(bool propagate) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (this->mAnchors.verticalConstraint()) {
 | 
						if (this->mAnchors.verticalConstraint()) {
 | 
				
			||||||
		geometry.setY(screenGeometry.y() + this->mMargins.mTop);
 | 
							geometry.setY(screenGeometry.y() + this->mMargins.top);
 | 
				
			||||||
		geometry.setHeight(screenGeometry.height() - this->mMargins.mTop - this->mMargins.mBottom);
 | 
							geometry.setHeight(screenGeometry.height() - this->mMargins.top - this->mMargins.bottom);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if (this->mAnchors.mTop) {
 | 
							if (this->mAnchors.mTop) {
 | 
				
			||||||
			geometry.setY(screenGeometry.y() + this->mMargins.mTop);
 | 
								geometry.setY(screenGeometry.y() + this->mMargins.top);
 | 
				
			||||||
		} else if (this->mAnchors.mBottom) {
 | 
							} else if (this->mAnchors.mBottom) {
 | 
				
			||||||
			geometry.setY(
 | 
								geometry.setY(
 | 
				
			||||||
			    screenGeometry.y() + screenGeometry.height() - this->implicitHeight()
 | 
								    screenGeometry.y() + screenGeometry.height() - this->implicitHeight()
 | 
				
			||||||
			    - this->mMargins.mBottom
 | 
								    - this->mMargins.bottom
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			geometry.setY(screenGeometry.y() + screenGeometry.height() / 2 - this->implicitHeight() / 2);
 | 
								geometry.setY(screenGeometry.y() + screenGeometry.height() / 2 - this->implicitHeight() / 2);
 | 
				
			||||||
| 
						 | 
					@ -377,10 +377,10 @@ void XPanelWindow::getExclusion(int& side, quint32& exclusiveZone) {
 | 
				
			||||||
	if (autoExclude) {
 | 
						if (autoExclude) {
 | 
				
			||||||
		if (side == 0 || side == 1) {
 | 
							if (side == 0 || side == 1) {
 | 
				
			||||||
			exclusiveZone =
 | 
								exclusiveZone =
 | 
				
			||||||
			    this->implicitWidth() + (side == 0 ? this->mMargins.mLeft : this->mMargins.mRight);
 | 
								    this->implicitWidth() + (side == 0 ? this->mMargins.left : this->mMargins.right);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			exclusiveZone =
 | 
								exclusiveZone =
 | 
				
			||||||
			    this->implicitHeight() + (side == 2 ? this->mMargins.mTop : this->mMargins.mBottom);
 | 
								    this->implicitHeight() + (side == 2 ? this->mMargins.top : this->mMargins.bottom);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		exclusiveZone = this->mExclusiveZone;
 | 
							exclusiveZone = this->mExclusiveZone;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue