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 <QHash>
9#include <QJsonObject>
10#include <QString>
11#include <QVariantMap>
12
14
22{
26 QVariantMap customParams;
27 bool operator==(const AlgorithmSettings& other) const
28 {
29 if (masterCount != other.masterCount || maxWindows != other.maxWindows
30 || !qFuzzyCompare(1.0 + splitRatio, 1.0 + other.splitRatio)) {
31 return false;
32 }
33 if (customParams.size() != other.customParams.size()) {
34 return false;
35 }
36 // Fuzzy-compare numeric custom param values to match splitRatio semantics.
37 // After JSON round-trip, numbers may arrive as Int/LongLong rather than Double,
38 // so check canConvert<double> rather than requiring exact QMetaType::Double.
39 for (auto it = customParams.constBegin(); it != customParams.constEnd(); ++it) {
40 auto oit = other.customParams.constFind(it.key());
41 if (oit == other.customParams.constEnd()) {
42 return false;
43 }
44 const QVariant& a = it.value();
45 const QVariant& b = oit.value();
46 const bool aNumeric = PhosphorTiles::AutotileDefaults::isNumericMetaType(a.typeId());
47 const bool bNumeric = PhosphorTiles::AutotileDefaults::isNumericMetaType(b.typeId());
48 const bool aBool = a.typeId() == QMetaType::Bool;
49 const bool bBool = b.typeId() == QMetaType::Bool;
50 if (aNumeric && bNumeric) {
51 if (!qFuzzyCompare(1.0 + a.toDouble(), 1.0 + b.toDouble())) {
52 return false;
53 }
54 } else if (aBool && bBool) {
55 if (a.toBool() != b.toBool()) {
56 return false;
57 }
58 } else if (a != b) {
59 return false;
60 }
61 }
62 return true;
63 }
64};
65
81struct PHOSPHORTILEENGINE_EXPORT AutotileConfig
82{
83 // ═══════════════════════════════════════════════════════════════════════
84 // Algorithm Selection
85 // ═══════════════════════════════════════════════════════════════════════
86
94
95 // ═══════════════════════════════════════════════════════════════════════
96 // Master Area Settings
97 // ═══════════════════════════════════════════════════════════════════════
98
107
115
119 QHash<QString, AlgorithmSettings> savedAlgorithmSettings;
120
122 static QHash<QString, AlgorithmSettings> perAlgoFromVariantMap(const QVariantMap& map);
124 static QVariantMap perAlgoToVariantMap(const QHash<QString, AlgorithmSettings>& hash);
125
126 // ═══════════════════════════════════════════════════════════════════════
127 // Gap Settings
128 // ═══════════════════════════════════════════════════════════════════════
129
137
145
149 bool usePerSideOuterGap = false;
150
158
159 // ═══════════════════════════════════════════════════════════════════════
160 // Window Insertion Behavior
161 // ═══════════════════════════════════════════════════════════════════════
162
164
165 InsertPosition insertPosition = InsertPosition::End;
166
167 // ═══════════════════════════════════════════════════════════════════════
168 // Focus Behavior
169 // ═══════════════════════════════════════════════════════════════════════
170
177 bool focusFollowsMouse = false;
178
184 bool focusNewWindows = true;
185
186 // ═══════════════════════════════════════════════════════════════════════
187 // Smart Features
188 // ═══════════════════════════════════════════════════════════════════════
189
195 bool smartGaps = true;
196
203 bool respectMinimumSize = true;
204
205 // ═══════════════════════════════════════════════════════════════════════
206 // Window Limits
207 // ═══════════════════════════════════════════════════════════════════════
208
217
238
239 // ═══════════════════════════════════════════════════════════════════════
240 // Comparison and Serialization
241 // ═══════════════════════════════════════════════════════════════════════
242
243 bool operator==(const AutotileConfig& other) const;
244 bool operator!=(const AutotileConfig& other) const;
245
249 QJsonObject toJson() const;
250
254 static AutotileConfig fromJson(const QJsonObject& json);
255
260};
261
262} // namespace PhosphorTileEngine
263
264// Enable use with QVariant
265Q_DECLARE_METATYPE(PhosphorTileEngine::AutotileConfig)
Algorithm-layer constants for the autotile/tile primitives.
Definition AutotileConfig.h:13
constexpr int DefaultMasterCount
Single master window.
Definition AutotileConstants.h:42
constexpr int DefaultInnerGap
Definition AutotileConstants.h:58
constexpr int DefaultOuterGap
Definition AutotileConstants.h:59
constexpr bool isNumericMetaType(int typeId)
Returns true if typeId is a numeric QMetaType (Double, Float, Int, UInt, LongLong,...
Definition AutotileConstants.h:123
constexpr QLatin1String DefaultAlgorithmId
Default tiling algorithm.
Definition AutotileConstants.h:49
constexpr qreal DefaultSplitRatio
50/50 split when nothing else specified
Definition AutotileConstants.h:41
constexpr int DefaultMaxWindows
Maximum tiled windows before overflow.
Definition AutotileConstants.h:43
constexpr qreal DefaultSplitRatioStep
Definition AutotileConstants.h:50
AutotileInsertPosition
Definition AutotileConstants.h:191
AutotileOverflowBehavior
Definition AutotileConstants.h:186
Per-algorithm saved settings (split ratio, master count, max windows)
Definition AutotileConfig.h:22
int maxWindows
Definition AutotileConfig.h:25
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:24
qreal splitRatio
Definition AutotileConfig.h:23
Configuration for autotiling behavior.
Definition AutotileConfig.h:82
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, max windows).
Definition AutotileConfig.h:119
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.