Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
AutotileConfig.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
6#include <phosphortileengine_export.h>
8#include <QColor>
9#include <QHash>
10#include <QJsonObject>
11#include <QString>
12#include <QVariantMap>
13
15
23{
26 QVariantMap customParams;
27 bool operator==(const AlgorithmSettings& other) const
28 {
29 if (masterCount != other.masterCount || !qFuzzyCompare(1.0 + splitRatio, 1.0 + other.splitRatio)) {
30 return false;
31 }
32 if (customParams.size() != other.customParams.size()) {
33 return false;
34 }
35 // Fuzzy-compare numeric custom param values to match splitRatio semantics.
36 // After JSON round-trip, numbers may arrive as Int/LongLong rather than Double,
37 // so check canConvert<double> rather than requiring exact QMetaType::Double.
38 for (auto it = customParams.constBegin(); it != customParams.constEnd(); ++it) {
39 auto oit = other.customParams.constFind(it.key());
40 if (oit == other.customParams.constEnd()) {
41 return false;
42 }
43 const QVariant& a = it.value();
44 const QVariant& b = oit.value();
45 const bool aNumeric = PhosphorTiles::AutotileDefaults::isNumericMetaType(a.typeId());
46 const bool bNumeric = PhosphorTiles::AutotileDefaults::isNumericMetaType(b.typeId());
47 const bool aBool = a.typeId() == QMetaType::Bool;
48 const bool bBool = b.typeId() == QMetaType::Bool;
49 if (aNumeric && bNumeric) {
50 if (!qFuzzyCompare(1.0 + a.toDouble(), 1.0 + b.toDouble())) {
51 return false;
52 }
53 } else if (aBool && bBool) {
54 if (a.toBool() != b.toBool()) {
55 return false;
56 }
57 } else if (a != b) {
58 return false;
59 }
60 }
61 return true;
62 }
63};
64
80struct PHOSPHORTILEENGINE_EXPORT AutotileConfig
81{
82 // ═══════════════════════════════════════════════════════════════════════
83 // Algorithm Selection
84 // ═══════════════════════════════════════════════════════════════════════
85
93
94 // ═══════════════════════════════════════════════════════════════════════
95 // Master Area Settings
96 // ═══════════════════════════════════════════════════════════════════════
97
106
114
118 QHash<QString, AlgorithmSettings> savedAlgorithmSettings;
119
121 static QHash<QString, AlgorithmSettings> perAlgoFromVariantMap(const QVariantMap& map);
123 static QVariantMap perAlgoToVariantMap(const QHash<QString, AlgorithmSettings>& hash);
124
125 // ═══════════════════════════════════════════════════════════════════════
126 // Gap Settings
127 // ═══════════════════════════════════════════════════════════════════════
128
136
144
148 bool usePerSideOuterGap = false;
149
157
158 // ═══════════════════════════════════════════════════════════════════════
159 // Window Insertion Behavior
160 // ═══════════════════════════════════════════════════════════════════════
161
163
164 InsertPosition insertPosition = InsertPosition::End;
165
166 // ═══════════════════════════════════════════════════════════════════════
167 // Focus Behavior
168 // ═══════════════════════════════════════════════════════════════════════
169
176 bool focusFollowsMouse = false;
177
183 bool focusNewWindows = true;
184
185 // ═══════════════════════════════════════════════════════════════════════
186 // Smart Features
187 // ═══════════════════════════════════════════════════════════════════════
188
194 bool smartGaps = true;
195
202 bool respectMinimumSize = true;
203
204 // ═══════════════════════════════════════════════════════════════════════
205 // Window Limits
206 // ═══════════════════════════════════════════════════════════════════════
207
216
237
238 // ═══════════════════════════════════════════════════════════════════════
239 // Comparison and Serialization
240 // ═══════════════════════════════════════════════════════════════════════
241
242 bool operator==(const AutotileConfig& other) const;
243 bool operator!=(const AutotileConfig& other) const;
244
248 QJsonObject toJson() const;
249
253 static AutotileConfig fromJson(const QJsonObject& json);
254
259};
260
261} // namespace PhosphorTileEngine
262
263// Enable use with QVariant
264Q_DECLARE_METATYPE(PhosphorTileEngine::AutotileConfig)
Algorithm-layer constants for the autotile/tile primitives.
Definition AutotileConfig.h:14
constexpr int DefaultMasterCount
Single master window.
Definition AutotileConstants.h:40
constexpr int DefaultInnerGap
Definition AutotileConstants.h:51
constexpr int DefaultOuterGap
Definition AutotileConstants.h:52
constexpr bool isNumericMetaType(int typeId)
Returns true if typeId is a numeric QMetaType (Double, Float, Int, UInt, LongLong,...
Definition AutotileConstants.h:90
constexpr QLatin1String DefaultAlgorithmId
Default tiling algorithm.
Definition AutotileConstants.h:42
constexpr qreal DefaultSplitRatio
50/50 split when nothing else specified
Definition AutotileConstants.h:39
constexpr int DefaultMaxWindows
Maximum tiled windows before overflow.
Definition AutotileConstants.h:41
constexpr qreal DefaultSplitRatioStep
Definition AutotileConstants.h:43
AutotileInsertPosition
Definition AutotileConstants.h:174
AutotileOverflowBehavior
Definition AutotileConstants.h:169
Per-algorithm saved settings (split ratio + master count)
Definition AutotileConfig.h:23
bool operator==(const AlgorithmSettings &other) const
Definition AutotileConfig.h:27
QVariantMap customParams
Algorithm-declared custom parameter values.
Definition AutotileConfig.h:26
int masterCount
Definition AutotileConfig.h:25
qreal splitRatio
Definition AutotileConfig.h:24
Configuration for autotiling behavior.
Definition AutotileConfig.h:81
static AutotileConfig defaults()
Get default configuration.
static QVariantMap perAlgoToVariantMap(const QHash< QString, AlgorithmSettings > &hash)
Convert internal hash to QVariantMap for the Settings layer.
static QHash< QString, AlgorithmSettings > perAlgoFromVariantMap(const QVariantMap &map)
Convert per-algorithm settings from QVariantMap (Settings layer) to internal hash.
QHash< QString, AlgorithmSettings > savedAlgorithmSettings
Per-algorithm saved settings (split ratio + master count).
Definition AutotileConfig.h:118
QJsonObject toJson() const
Serialize to JSON.
bool operator!=(const AutotileConfig &other) const
bool operator==(const AutotileConfig &other) const
static AutotileConfig fromJson(const QJsonObject &json)
Deserialize from JSON.