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{
25 QVariantMap customParams;
26 bool operator==(const AlgorithmSettings& other) const
27 {
28 if (masterCount != other.masterCount || !qFuzzyCompare(1.0 + splitRatio, 1.0 + other.splitRatio)) {
29 return false;
30 }
31 if (customParams.size() != other.customParams.size()) {
32 return false;
33 }
34 // Fuzzy-compare numeric custom param values to match splitRatio semantics.
35 // After JSON round-trip, numbers may arrive as Int/LongLong rather than Double,
36 // so check canConvert<double> rather than requiring exact QMetaType::Double.
37 for (auto it = customParams.constBegin(); it != customParams.constEnd(); ++it) {
38 auto oit = other.customParams.constFind(it.key());
39 if (oit == other.customParams.constEnd()) {
40 return false;
41 }
42 const QVariant& a = it.value();
43 const QVariant& b = oit.value();
44 const bool aNumeric = PhosphorTiles::AutotileDefaults::isNumericMetaType(a.typeId());
45 const bool bNumeric = PhosphorTiles::AutotileDefaults::isNumericMetaType(b.typeId());
46 const bool aBool = a.typeId() == QMetaType::Bool;
47 const bool bBool = b.typeId() == QMetaType::Bool;
48 if (aNumeric && bNumeric) {
49 if (!qFuzzyCompare(1.0 + a.toDouble(), 1.0 + b.toDouble())) {
50 return false;
51 }
52 } else if (aBool && bBool) {
53 if (a.toBool() != b.toBool()) {
54 return false;
55 }
56 } else if (a != b) {
57 return false;
58 }
59 }
60 return true;
61 }
62};
63
79struct PHOSPHORTILEENGINE_EXPORT AutotileConfig
80{
81 // ═══════════════════════════════════════════════════════════════════════
82 // Algorithm Selection
83 // ═══════════════════════════════════════════════════════════════════════
84
92
93 // ═══════════════════════════════════════════════════════════════════════
94 // Master Area Settings
95 // ═══════════════════════════════════════════════════════════════════════
96
105
113
117 QHash<QString, AlgorithmSettings> savedAlgorithmSettings;
118
120 static QHash<QString, AlgorithmSettings> perAlgoFromVariantMap(const QVariantMap& map);
122 static QVariantMap perAlgoToVariantMap(const QHash<QString, AlgorithmSettings>& hash);
123
124 // ═══════════════════════════════════════════════════════════════════════
125 // Gap Settings
126 // ═══════════════════════════════════════════════════════════════════════
127
135
143
147 bool usePerSideOuterGap = false;
148
156
157 // ═══════════════════════════════════════════════════════════════════════
158 // Window Insertion Behavior
159 // ═══════════════════════════════════════════════════════════════════════
160
162
163 InsertPosition insertPosition = InsertPosition::End;
164
165 // ═══════════════════════════════════════════════════════════════════════
166 // Focus Behavior
167 // ═══════════════════════════════════════════════════════════════════════
168
175 bool focusFollowsMouse = false;
176
182 bool focusNewWindows = true;
183
184 // ═══════════════════════════════════════════════════════════════════════
185 // Smart Features
186 // ═══════════════════════════════════════════════════════════════════════
187
193 bool smartGaps = true;
194
201 bool respectMinimumSize = true;
202
203 // ═══════════════════════════════════════════════════════════════════════
204 // Window Limits
205 // ═══════════════════════════════════════════════════════════════════════
206
215
236
237 // ═══════════════════════════════════════════════════════════════════════
238 // Comparison and Serialization
239 // ═══════════════════════════════════════════════════════════════════════
240
241 bool operator==(const AutotileConfig& other) const;
242 bool operator!=(const AutotileConfig& other) const;
243
247 QJsonObject toJson() const;
248
252 static AutotileConfig fromJson(const QJsonObject& json);
253
258};
259
260} // namespace PhosphorTileEngine
261
262// Enable use with QVariant
263Q_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:53
constexpr int DefaultOuterGap
Definition AutotileConstants.h:54
constexpr bool isNumericMetaType(int typeId)
Returns true if typeId is a numeric QMetaType (Double, Float, Int, UInt, LongLong,...
Definition AutotileConstants.h:100
constexpr QLatin1String DefaultAlgorithmId
Default tiling algorithm.
Definition AutotileConstants.h:44
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:45
AutotileInsertPosition
Definition AutotileConstants.h:170
AutotileOverflowBehavior
Definition AutotileConstants.h:165
Per-algorithm saved settings (split ratio + master count)
Definition AutotileConfig.h:22
bool operator==(const AlgorithmSettings &other) const
Definition AutotileConfig.h:26
QVariantMap customParams
Algorithm-declared custom parameter values.
Definition AutotileConfig.h:25
int masterCount
Definition AutotileConfig.h:24
qreal splitRatio
Definition AutotileConfig.h:23
Configuration for autotiling behavior.
Definition AutotileConfig.h:80
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:117
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.