Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
Zone.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7#include "phosphorzones_export.h"
8#include <QObject>
9#include <QRect>
10#include <QUuid>
11#include <QString>
12#include <QColor>
13#include <QJsonObject>
14
15namespace PhosphorZones {
16
31enum class ZoneGeometryMode {
34};
35
46class PHOSPHORZONES_EXPORT Zone : public QObject
47{
48 Q_OBJECT
49
50 Q_PROPERTY(QUuid id READ id CONSTANT)
51 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
52 Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
54 Q_PROPERTY(int zoneNumber READ zoneNumber WRITE setZoneNumber NOTIFY zoneNumberChanged)
55 Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor NOTIFY highlightColorChanged)
56 Q_PROPERTY(QColor inactiveColor READ inactiveColor WRITE setInactiveColor NOTIFY inactiveColorChanged)
57 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
58 Q_PROPERTY(qreal activeOpacity READ activeOpacity WRITE setActiveOpacity NOTIFY activeOpacityChanged)
60 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
61 Q_PROPERTY(int borderRadius READ borderRadius WRITE setBorderRadius NOTIFY borderRadiusChanged)
62 Q_PROPERTY(bool isHighlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged)
64 Q_PROPERTY(
67 Q_PROPERTY(QRectF fixedGeometry READ fixedGeometry WRITE setFixedGeometry NOTIFY fixedGeometryChanged)
68
69public:
70 explicit Zone(QObject* parent = nullptr);
71 explicit Zone(const QRectF& geometry, QObject* parent = nullptr);
72 ~Zone() override = default;
73
74 // QObjects should not be copied - use clone() instead
75 Zone(const Zone&) = delete;
76 Zone& operator=(const Zone&) = delete;
77
83 Q_INVOKABLE Zone* clone(QObject* parent = nullptr) const;
84
89 void copyPropertiesFrom(const Zone& other);
90
91 // Identification
92 QUuid id() const
93 {
94 return m_id;
95 }
96 QString name() const
97 {
98 return m_name;
99 }
100 void setName(const QString& name);
101
102 // Geometry (absolute pixel coordinates)
103 QRectF geometry() const
104 {
105 return m_geometry;
106 }
107 void setGeometry(const QRectF& geometry);
108
109 // Relative geometry (0.0-1.0 normalized coordinates for resolution independence)
110 QRectF relativeGeometry() const
111 {
112 return m_relativeGeometry;
113 }
115
116 // Zone numbering for keyboard navigation
117 int zoneNumber() const
118 {
119 return m_zoneNumber;
120 }
121 void setZoneNumber(int number);
122
123 // Ricer-friendly appearance customization
124 QColor highlightColor() const
125 {
126 return m_highlightColor;
127 }
128 void setHighlightColor(const QColor& color);
129
130 QColor inactiveColor() const
131 {
132 return m_inactiveColor;
133 }
134 void setInactiveColor(const QColor& color);
135
136 QColor borderColor() const
137 {
138 return m_borderColor;
139 }
140 void setBorderColor(const QColor& color);
141
142 qreal activeOpacity() const
143 {
144 return m_activeOpacity;
145 }
146 void setActiveOpacity(qreal opacity);
147
148 qreal inactiveOpacity() const
149 {
150 return m_inactiveOpacity;
151 }
152 void setInactiveOpacity(qreal opacity);
153
154 int borderWidth() const
155 {
156 return m_borderWidth;
157 }
158 void setBorderWidth(int width);
159
160 int borderRadius() const
161 {
162 return m_borderRadius;
163 }
164 void setBorderRadius(int radius);
165
166 bool isHighlighted() const
167 {
168 return m_isHighlighted;
169 }
170 void setHighlighted(bool highlighted);
171
172 bool useCustomColors() const
173 {
174 return m_useCustomColors;
175 }
176 void setUseCustomColors(bool useCustom);
177
179 {
180 return m_overlayDisplayMode;
181 }
182 void setOverlayDisplayMode(int mode);
183
184 // Per-zone geometry mode
186 {
187 return m_geometryMode;
188 }
189 int geometryModeInt() const
190 {
191 return static_cast<int>(m_geometryMode);
192 }
193 bool isFixedGeometry() const
194 {
195 return m_geometryMode == ZoneGeometryMode::Fixed;
196 }
198 void setGeometryModeInt(int mode);
199
200 QRectF fixedGeometry() const
201 {
202 return m_fixedGeometry;
203 }
204 void setFixedGeometry(const QRectF& geometry);
205
228 static QRectF sanitizeFixedGeometry(const QRectF& geometry);
229
243 Q_INVOKABLE QRectF normalizedGeometry(const QRectF& referenceGeometry, qreal screenScale = 0.0) const;
244
245 // Geometry calculations
246 Q_INVOKABLE bool containsPoint(const QPointF& point) const;
247 Q_INVOKABLE qreal distanceToPoint(const QPointF& point) const;
249 Q_INVOKABLE QRectF calculateAbsoluteGeometry(const QRectF& screenGeometry, qreal screenScale = 0.0) const;
250
256 qreal fixedGeometryDivisor(qreal screenScale) const;
257
264 static QRectF fixedGeometryToLogical(const QRectF& fixedGeometry, qreal divisor);
265
276 const QRectF& fixedGeometry, const QRectF& screenGeometry,
277 qreal fixedDivisor = 1.0);
278
279 // Serialization
280 QJsonObject toJson(const QRectF& referenceGeometry = QRectF()) const;
281 static Zone* fromJson(const QJsonObject& json, QObject* parent = nullptr);
282
283Q_SIGNALS:
300
301private:
302 QUuid m_id;
303 QString m_name;
304 QRectF m_geometry;
305 QRectF m_relativeGeometry;
306 int m_zoneNumber = 0;
307
308 // Appearance (ricer-friendly) — defaults sourced from PhosphorZones::ZoneDefaults.
309 QColor m_highlightColor = ::PhosphorZones::ZoneDefaults::HighlightColor;
310 QColor m_inactiveColor = ::PhosphorZones::ZoneDefaults::InactiveColor;
311 QColor m_borderColor = ::PhosphorZones::ZoneDefaults::BorderColor;
312 qreal m_activeOpacity = ::PhosphorZones::ZoneDefaults::Opacity;
313 qreal m_inactiveOpacity = ::PhosphorZones::ZoneDefaults::InactiveOpacity;
316 bool m_isHighlighted = false;
317 bool m_useCustomColors = false;
318 int m_overlayDisplayMode = -1; // -1 = use layout/global setting
319
320 // Per-zone geometry mode
322 QRectF m_fixedGeometry; // Pixel coords relative to screen origin, in the layout's fixed unit
323};
324
325} // namespace PhosphorZones
~Zone() override=default
QRectF fixedGeometry() const
Definition Zone.h:200
void setRelativeGeometry(const QRectF &relativeGeometry)
bool useCustomColors() const
Definition Zone.h:172
void setGeometry(const QRectF &geometry)
static QRectF fixedGeometryToLogical(const QRectF &fixedGeometry, qreal divisor)
fixedGeometry in logical units: every component divided by divisor, a non-positive one reading as 1....
void setActiveOpacity(qreal opacity)
static QRectF sanitizeFixedGeometry(const QRectF &geometry)
Normalize a fixedGeometry payload arriving from an untrusted boundary.
QColor highlightColor() const
Definition Zone.h:124
QColor inactiveColor() const
Definition Zone.h:130
void setInactiveColor(const QColor &color)
Zone(const QRectF &geometry, QObject *parent=nullptr)
void inactiveOpacityChanged()
ZoneGeometryMode geometryMode() const
Definition Zone.h:185
int overlayDisplayMode() const
Definition Zone.h:178
static QRectF computeAbsoluteGeometry(ZoneGeometryMode mode, const QRectF &relativeGeometry, const QRectF &fixedGeometry, const QRectF &screenGeometry, qreal fixedDivisor=1.0)
Pure helper shared between Zone::calculateAbsoluteGeometry and LayoutWorker (which runs off-thread an...
qreal distanceToPoint(const QPointF &point) const
int zoneNumber() const
Definition Zone.h:117
void setGeometryMode(ZoneGeometryMode mode)
QRectF relativeGeometry() const
Definition Zone.h:110
void setBorderColor(const QColor &color)
int geometryModeInt() const
Definition Zone.h:189
int borderRadius() const
Definition Zone.h:160
QString name() const
Definition Zone.h:96
Zone(const Zone &)=delete
void relativeGeometryChanged()
void setZoneNumber(int number)
void useCustomColorsChanged()
bool isHighlighted() const
Definition Zone.h:166
int borderWidth() const
Definition Zone.h:154
Zone & operator=(const Zone &)=delete
void copyPropertiesFrom(const Zone &other)
Copies properties from another zone (excluding ID).
void setName(const QString &name)
QRectF calculateAbsoluteGeometry(const QRectF &screenGeometry, qreal screenScale=0.0) const
screenScale as normalizedGeometry() takes it.
bool containsPoint(const QPointF &point) const
void setHighlightColor(const QColor &color)
Zone(QObject *parent=nullptr)
qreal fixedGeometryDivisor(qreal screenScale) const
What this zone's fixed geometry is divided by on an output of logical scale screenScale: its layout's...
void setGeometryModeInt(int mode)
static Zone * fromJson(const QJsonObject &json, QObject *parent=nullptr)
void setBorderWidth(int width)
QRectF normalizedGeometry(const QRectF &referenceGeometry, qreal screenScale=0.0) const
Returns normalized 0-1 coordinates regardless of geometry mode.
void overlayDisplayModeChanged()
void setFixedGeometry(const QRectF &geometry)
void highlightColorChanged()
bool isFixedGeometry() const
Definition Zone.h:193
QColor borderColor() const
Definition Zone.h:136
void setHighlighted(bool highlighted)
void setBorderRadius(int radius)
QUuid id() const
Definition Zone.h:92
QRectF geometry() const
Definition Zone.h:103
QJsonObject toJson(const QRectF &referenceGeometry=QRectF()) const
void setOverlayDisplayMode(int mode)
void setUseCustomColors(bool useCustom)
Zone * clone(QObject *parent=nullptr) const
Creates a copy of this zone with a new unique ID.
qreal activeOpacity() const
Definition Zone.h:142
void setInactiveOpacity(qreal opacity)
qreal inactiveOpacity() const
Definition Zone.h:148
const QColor HighlightColor
Windows blue.
Definition ZoneDefaults.h:29
constexpr int BorderRadius
Definition ZoneDefaults.h:38
const QColor InactiveColor
Definition ZoneDefaults.h:30
constexpr qreal Opacity
Definition ZoneDefaults.h:35
constexpr int BorderWidth
Definition ZoneDefaults.h:37
constexpr qreal InactiveOpacity
Definition ZoneDefaults.h:36
const QColor BorderColor
Definition ZoneDefaults.h:31
Definition IWindowTrackingService.h:24
ZoneGeometryMode
Geometry mode for individual zones.
Definition Zone.h:31
@ Relative
Definition Zone.h:32
@ Fixed
Definition Zone.h:33