Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
AutotileEngine.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"
16#include <QHash>
17#include <QJsonObject>
18#include <QObject>
19#include <QRect>
20#include <QSet>
21#include <QSize>
22#include <QString>
23#include <QStringList>
24#include <QTimer>
25#include <cstdint>
26#include <functional>
27#include <memory>
28#include <optional>
29
32
33namespace PhosphorZones {
34class Layout;
35class LayoutRegistry;
36}
37
38namespace PhosphorTileEngine {
39
40class AutotileConfig;
41struct TileEvacueePark;
42
45} // namespace PhosphorTileEngine
46
47// ScreenManager lives in libs/phosphor-screens; forward-declared here.
48namespace PhosphorScreens {
49class ScreenManager;
50}
51
52namespace PhosphorTiles {
54class TilingAlgorithm;
55class TilingState;
56}
57
58namespace PhosphorTileEngine {
59
70class PHOSPHORTILEENGINE_EXPORT AutotileEngine : public PhosphorEngine::PlacementEngineBase
71{
72 Q_OBJECT
73 Q_PROPERTY(bool enabled READ isEnabled NOTIFY enabledChanged)
74 Q_PROPERTY(QString algorithm READ algorithm WRITE setAlgorithm NOTIFY algorithmChanged)
75
78
79public:
80 explicit AutotileEngine(PhosphorZones::LayoutRegistry* layoutManager,
81 PhosphorEngine::IWindowTrackingService* windowTracker,
82 PhosphorScreens::ScreenManager* screenManager,
83 PhosphorTiles::ITileAlgorithmRegistry* algorithmRegistry, QObject* parent = nullptr);
84 ~AutotileEngine() override;
85
87 PhosphorTiles::ITileAlgorithmRegistry* algorithmRegistry() const
88 {
89 return m_algorithmRegistry;
90 }
91
106 void setWindowRegistry(QObject* registry) override;
107
108 // ═══════════════════════════════════════════════════════════════════════════
109 // Per-screen autotile state (derived from layout assignments)
110 // ═══════════════════════════════════════════════════════════════════════════
111
116 bool isEnabled() const noexcept override;
117
127 QSet<int> desktopsWithActiveState() const override;
128
134 bool isAutotileScreen(const QString& screenId) const;
135
159 bool isWindowTracked(const QString& windowId) const override
160 {
161 // Canonicalize like every sibling predicate (isWindowTiled,
162 // screenForTrackedWindow): callers pass raw daemon/effect composite
163 // ids, and a mutated-appId window must still resolve to its
164 // tracked entry.
165 const QString canonical = canonicalizeForLookup(windowId);
166 const auto* state = m_states.forWindow(canonical);
167 return state && state->containsWindow(canonical);
168 }
169
177 bool isWindowTiled(const QString& rawWindowId) const override;
178
190 bool isWindowFloatingInAutotile(const QString& windowId) const;
191
200 QStringList allFloatingWindows() const;
201
202 // IPlacementEngine
203 bool isActiveOnScreen(const QString& screenId) const override;
204
205 // ═══════════════════════════════════════════════════════════════════════════
206 // IPlacementEngine — generic screen/window management overrides
207 //
208 // Each override delegates to the concrete autotile method below it.
209 // AutotileAdaptor continues to call the concrete methods directly.
210 // ═══════════════════════════════════════════════════════════════════════════
211
212 QSet<QString> activeScreens() const override
213 {
214 return autotileScreens();
215 }
216 void setActiveScreens(const QSet<QString>& screens) override
217 {
218 setAutotileScreens(screens);
219 }
220
227 QStringList managedWindowOrder(const QString& screenId) const override
228 {
229 return capturedWindowOrder(screenId);
230 }
231 QStringList capturedWindowOrder(const QString& screenId) const;
236 QString managedFocusedWindow(const QString& screenId) const override;
239 int stickyPinnedDesktopForScreen(const QString& screenId) const override
240 {
241 return m_context.stickyPinnedDesktop(screenId);
242 }
243 bool isModeSpecificFloated(const QString& windowId) const override
244 {
245 return isAutotileFloated(windowId);
246 }
247 void clearModeSpecificFloatMarker(const QString& windowId) override
248 {
249 clearAutotileFloated(windowId);
250 }
251 bool isWindowManaged(const QString& windowId) const override
252 {
253 return isWindowTiled(windowId);
254 }
255 QString algorithmId() const override
256 {
257 return algorithm();
258 }
259 void markModeSpecificFloated(const QString& windowId) override
260 {
261 markAutotileFloated(windowId);
262 }
263
268 const QSet<QString>& autotileScreens() const
269 {
270 return m_autotileScreens;
271 }
272
277 QString activeScreen() const override
278 {
279 return m_activeScreen;
280 }
281
299 void setAutotileScreens(const QSet<QString>& screens);
300
310 void setCurrentDesktop(int desktop) override;
311
322 void setCurrentDesktopForScreen(const QString& screenId, int desktop) override;
323
325 void clearCurrentDesktopForScreen(const QString& screenId) override;
326
330 {
331 m_crossSurfaceResolver = resolver;
332 }
333
343 void setCurrentActivity(const QString& activity) override;
344
360
368 reconcileDesktopMemberships(const QString& screenId, const PhosphorEngine::DesktopSpanQuery& spanOf) override;
370 reconcileWindowMemberships(const QString& windowId, const PhosphorEngine::DesktopSpanQuery& spanOf) override;
371
374 void pruneStatesForDesktop(int removedDesktop) override;
375 void renumberDesktopsAfterRemoval(int removedDesktop) override;
376 void remapDesktops(const PhosphorEngine::DesktopRemap& remap) override;
377
384 void pruneStatesForActivities(const QStringList& validActivities) override;
385
396 void pruneStatesForRemovedScreen(const QString& physicalScreenId) override;
397
401 int currentDesktop() const noexcept
402 {
403 return m_context.currentDesktop();
404 }
405
409 const QString& currentActivity() const noexcept
410 {
411 return m_context.currentActivity();
412 }
413
414 // ═══════════════════════════════════════════════════════════════════════════
415 // Algorithm selection
416 // ═══════════════════════════════════════════════════════════════════════════
417
422 QString algorithm() const noexcept;
423
431 void setAlgorithm(const QString& algorithmId) override;
432
437 PhosphorTiles::TilingAlgorithm* currentAlgorithm() const;
438
439 // ═══════════════════════════════════════════════════════════════════════════
440 // Tiling state access
441 // ═══════════════════════════════════════════════════════════════════════════
442
451 PhosphorTiles::TilingState* tilingStateForScreen(const QString& screenId);
452
453 PhosphorEngine::IPlacementState* stateForScreen(const QString& screenId) override;
454 const PhosphorEngine::IPlacementState* stateForScreen(const QString& screenId) const override;
455
460 AutotileConfig* config() const noexcept;
461
462 // ═══════════════════════════════════════════════════════════════════════════
463 // Session Persistence
464 // ═══════════════════════════════════════════════════════════════════════════
465
475 void saveState() override;
476
485 void loadState() override;
486
497 void setPersistenceDelegate(std::function<void()> saveFn, std::function<void()> loadFn)
498 {
499 m_persistSaveFn = std::move(saveFn);
500 m_persistLoadFn = std::move(loadFn);
501 }
502
524 using RestorePositionPredicate = std::function<bool(const QString& windowId, const QString& screenIdHint)>;
525
529 {
530 m_restorePositionPredicate = std::move(predicate);
531 }
532
549 using FloatPredicate = std::function<bool(const QString& windowId, const QString& screenId)>;
550
552 {
553 m_floatPredicate = std::move(predicate);
554 }
555
556 // Cross-engine handoff (see PhosphorEngine/IPlacementEngine.h for contract)
557 // Layout capability (see IPlacementEngine's Layout capability section)
561 {
563 }
564
565 QString engineId() const override
566 {
568 }
569 void handoffReceive(const HandoffContext& ctx) override;
570 void handoffRelease(const QString& windowId) override;
571 QString screenForTrackedWindow(const QString& windowId) const override
572 {
573 return m_states.keyForWindow(canonicalizeForLookup(windowId)).screenId;
574 }
575
595 void onWindowResized(const QString& rawWindowId, const QRect& oldFrame, const QRect& newFrame,
596 const QString& screenId) override;
597 // ═══════════════════════════════════════════════════════════════════════════
598 // Settings synchronization
599 // ═══════════════════════════════════════════════════════════════════════════
600
604
605 // Per-screen config — forwarded to PerScreenConfigResolver (IPlacementEngine overrides)
606 void applyPerScreenConfig(const QString& screenId, const QVariantMap& overrides) override;
607 void clearPerScreenConfig(const QString& screenId) override;
608 QVariantMap perScreenOverrides(const QString& screenId) const override;
609 bool hasPerScreenOverride(const QString& screenId, const QString& key) const;
610 void updatePerScreenOverride(const QString& screenId, const QString& key, const QVariant& value);
611
612 // Inject the per-context (window-rule) gap-override provider, forwarded to PerScreenConfigResolver. The daemon
613 // supplies the screen's current-context gap overrides so tiled windows honour context gap rules like snapping does.
614 void setContextGapProvider(std::function<QVariantMap(const QString& screenId)> provider);
615
622 using ContextTilesResolver = std::function<bool(const QString& screenId, int desktop, const QString& activity)>;
624 {
625 m_contextModeResolver = std::move(resolver);
626 }
627
632 std::function<bool(const QString& screenId, int desktop, const QString& activity)> resolver)
633 {
634 m_scrollingModeResolver = std::move(resolver);
635 }
636
637 // Mark the active (screen, desktop, activity) state's split ratio / master
638 // count as user-tuned so propagateGlobalSplitRatio/MasterCount leaves it
639 // alone — the adjustment stays local to that desktop instead of bleeding into
640 // the global config. Called by NavigationController after a shortcut/resize
641 // adjustment in the no-per-screen-override case.
642 void noteSplitRatioUserTuned(const QString& screenId);
643 void noteMasterCountUserTuned(const QString& screenId);
644
645 // Effective per-screen values — forwarded to PerScreenConfigResolver
646 int effectiveInnerGap(const QString& screenId) const;
647 ::PhosphorLayout::EdgeGaps effectiveOuterGaps(const QString& screenId) const;
648 bool effectiveSmartGaps(const QString& screenId) const;
649 bool effectiveRespectMinimumSize(const QString& screenId) const;
650 int effectiveMaxWindows(const QString& screenId) const;
652 qreal effectiveSplitRatioStep(const QString& screenId) const override;
653 int runtimeMaxWindows() const override;
664 std::optional<int> savedMaxWindowsForAlgorithm(const QString& algorithmId) const override;
665 QString effectiveAlgorithmId(const QString& screenId) const;
666 PhosphorTiles::TilingAlgorithm* effectiveAlgorithm(const QString& screenId) const;
667
675 void clearScreenScheduling(const QString& screenId);
676
683 void clearPendingInitialOrder(const QString& screenId);
684
692 void purgeFromPendingOrders(const QString& windowId);
693
703 void notifyAlgorithmWindowAdded(PhosphorTiles::TilingState* state, const QString& screenId,
704 const QString& windowId);
705
717 void requestPostRetileFocus(const QString& screenId, const QString& windowId);
718
719 // ═══════════════════════════════════════════════════════════════════════════
720 // Manual tiling operations
721 // ═══════════════════════════════════════════════════════════════════════════
722
723 void setInnerGap(int gap);
724 void setOuterGap(int gap);
725 void setSmartGaps(bool enabled);
726 void setFocusNewWindows(bool enabled);
735 Q_INVOKABLE void retile(const QString& screenId = QString()) override;
736
743 Q_INVOKABLE void swapWindows(const QString& windowId1, const QString& windowId2);
744
753 Q_INVOKABLE void promoteToMaster(const QString& windowId);
754
762 Q_INVOKABLE void demoteFromMaster(const QString& windowId);
763
770 Q_INVOKABLE void swapFocusedWithMaster() override;
771
772 // ═══════════════════════════════════════════════════════════════════════════
773 // Focus/window cycling
774 // ═══════════════════════════════════════════════════════════════════════════
775
781 Q_INVOKABLE void focusNext();
782
788 Q_INVOKABLE void focusPrevious();
789
795 Q_INVOKABLE void focusMaster() override;
796
805 void setFocusedWindow(const QString& windowId);
806
816 void setActiveScreenHint(const QString& screenId) override;
817
818 // ═══════════════════════════════════════════════════════════════════════════
819 // Split ratio adjustment
820 // ═══════════════════════════════════════════════════════════════════════════
821
829 Q_INVOKABLE void increaseMasterRatio(qreal delta = kDefaultSplitRatioStep) override;
830
838 Q_INVOKABLE void decreaseMasterRatio(qreal delta = kDefaultSplitRatioStep) override;
839
855 void setGlobalSplitRatio(qreal ratio);
856
867 void setGlobalMasterCount(int count);
868
869 // ═══════════════════════════════════════════════════════════════════════════
870 // Master count adjustment
871 // ═══════════════════════════════════════════════════════════════════════════
872
876 Q_INVOKABLE void increaseMasterCount() override;
877
881 Q_INVOKABLE void decreaseMasterCount() override;
882
883 // ═══════════════════════════════════════════════════════════════════════════
884 // Window rotation and floating (context-aware shortcuts support)
885 // ═══════════════════════════════════════════════════════════════════════════
886
896 Q_INVOKABLE void rotateWindowOrder(bool clockwise = true);
897
907 Q_INVOKABLE void toggleFocusedWindowFloat();
908
924 Q_INVOKABLE void switchFocusBetweenFloatingAndTiling(const QString& screenId) override;
925
937 Q_INVOKABLE void toggleWindowFloat(const QString& windowId, const QString& screenId) override;
938
949 Q_INVOKABLE void swapFocusedInDirection(const QString& direction, const QString& action = QStringLiteral("move"));
950
959 Q_INVOKABLE void focusInDirection(const QString& direction, const QString& action = QStringLiteral("focus"));
960
968 Q_INVOKABLE void moveFocusedToPosition(int position);
969
970 // ═══════════════════════════════════════════════════════════════════════════
971 // IPlacementEngine — navigation overrides
972 //
973 // Each override absorbs what AutotileNavigationAdapter did: translate
974 // the user-intent-shaped IPlacementEngine call into the existing
975 // concrete AutotileEngine method with the right parameters.
976 // ═══════════════════════════════════════════════════════════════════════════
977
978 void focusInDirection(const QString& direction, const PhosphorEngine::NavigationContext& ctx) override;
979 void moveFocusedInDirection(const QString& direction, const PhosphorEngine::NavigationContext& ctx) override;
980 void spanFocusedInDirection(const QString& direction, const PhosphorEngine::NavigationContext& ctx) override;
981 void swapFocusedInDirection(const QString& direction, const PhosphorEngine::NavigationContext& ctx) override;
982 void moveFocusedToPosition(int position, const PhosphorEngine::NavigationContext& ctx) override;
983 void rotateWindows(bool clockwise, const PhosphorEngine::NavigationContext& ctx) override;
984
989 QString entryWindowForCrossing(const QString& screenId, const QString& direction) const;
994 int windowOrderIndexForWindow(const QString& screenId, const QString& windowId) const;
997 std::optional<PhosphorEngine::WindowPlacement> capturePlacement(const QString& windowId) const override;
1003 std::optional<PhosphorEngine::WindowPlacement>
1004 capturePlacementForKey(const QString& windowId, const PhosphorEngine::TilingStateKey& key) const;
1007 void cycleFocus(bool forward, const PhosphorEngine::NavigationContext& ctx) override;
1010
1011 // Autotile-specific navigation, callable on the concrete engine.
1012 void rotateWindows(bool clockwise, const QString& screenId);
1013
1031 Q_INVOKABLE void setWindowFloat(const QString& windowId, bool shouldFloat,
1032 const QString& screenId = QString()) override;
1033
1044 Q_INVOKABLE void floatWindow(const QString& windowId);
1045
1051 Q_INVOKABLE void unfloatWindow(const QString& windowId);
1052
1053 // ═══════════════════════════════════════════════════════════════════════════
1054 // PhosphorZones::Zone-ordered window transitions (snapping ↔ autotile)
1055 // ═══════════════════════════════════════════════════════════════════════════
1056
1070 void setInitialWindowOrder(const QString& screenId, const QStringList& windowIds) override;
1071
1082 QStringList tiledWindowOrder(const QString& screenId) const;
1083
1084 // ═══════════════════════════════════════════════════════════════════════════
1085 // Window event handlers (public API for external notification)
1086 // ═══════════════════════════════════════════════════════════════════════════
1087
1091 using IPlacementEngine::windowOpened;
1092 void windowOpened(const QString& windowId, const QString& screenId, int minWidth, int minHeight) override;
1102 bool claimCrossScreenReopen(const QString& windowId, const QString& openingScreenId, int minWidth,
1103 int minHeight) override;
1104 void noteCrossScreenClaimsExhausted(const QString& windowId, bool exhausted) override;
1105 QString heldScreenForWindow(const QString& windowId) const override;
1106 std::optional<PhosphorEngine::PlacementStateKey> heldKeyForWindow(const QString& windowId) const override;
1107
1108 // Evacuee park (src/autotileengine/evacueepark.cpp; IPlacementEngine's contract). A context out of view is
1109 // seated at once on a screen this engine tiles, else granted for insertWindow to seat on the window's arrival.
1110 QStringList parkOutput(const QString& physicalScreenId) override;
1111 bool readoptParked(const QString& windowId, const QString& parkedPhysicalId,
1112 const QString& returnedPhysicalId) override;
1113 void dropParked(const QString& windowId, const QString& physicalScreenId, int desktop,
1114 const QString& activity) override;
1115 bool hasParked(const QString& windowId, const QString& physicalScreenId) const override;
1116
1119 void windowMinSizeUpdated(const QString& windowId, int minWidth, int minHeight) override;
1120 QSize windowMinimumSize(const QString& windowId) const override;
1121
1130 void windowClosed(const QString& windowId) override;
1131
1141 void windowFocused(const QString& windowId, const QString& screenId) override;
1142
1143 // ═══════════════════════════════════════════════════════════════════════════
1144 // Retile helpers (public — used by extracted classes)
1145 // ═══════════════════════════════════════════════════════════════════════════
1146
1154 void scheduleRetileForScreen(const QString& screenId) override;
1155
1156 // ═══════════════════════════════════════════════════════════════════════════
1157 // Drag-insert preview (trigger-held window drag reorders autotile stack)
1158 // ═══════════════════════════════════════════════════════════════════════════
1159
1184 bool beginDragInsertPreview(const QString& rawWindowId, const QString& screenId) override;
1185
1197 void updateDragInsertPreview(int insertIndex);
1198
1206 void updateDragInsertPreview(const DragInsertTarget& target) override;
1207
1216
1228 void cancelDragInsertPreview(bool dragStillActive = false) override;
1229
1245 void setInteractiveDragWindow(const QString& windowId) override;
1246
1268 int computeDragInsertIndexAtPoint(const QString& screenId, const QPoint& cursorPos) const;
1269
1274 DragInsertTarget computeDragInsertTargetAtPoint(const QString& screenId, const QPoint& cursorPos) const override;
1275
1279 bool hasDragInsertPreview() const override
1280 {
1281 return m_dragInsertPreview.has_value();
1282 }
1283
1290 {
1291 return m_dragInsertPreview ? m_dragInsertPreview->windowId : QString();
1292 }
1293
1297 QString dragInsertPreviewScreenId() const override
1298 {
1299 return m_dragInsertPreview ? m_dragInsertPreview->targetScreenId : QString();
1300 }
1301
1309 QString dragInsertPreviewPriorScreenId() const override
1310 {
1311 return m_dragInsertPreview && m_dragInsertPreview->hadPriorState ? m_dragInsertPreview->priorKey.screenId
1312 : QString();
1313 }
1314
1324 void retileAfterOperation(const QString& screenId, bool operationSucceeded);
1325
1326Q_SIGNALS:
1331 void enabledChanged(bool enabled);
1332
1345 void autotileScreensChanged(const QStringList& screenIds, bool isDesktopSwitch);
1346
1347 // algorithmChanged(const QString&) — inherited from PlacementEngineBase.
1348 // placementChanged(const QString&) — inherited from PlacementEngineBase.
1349 // Replaces the former tilingChanged signal; all internal emitters now
1350 // emit placementChanged, and callers connect to the base-class signal.
1351 // windowsReleased(const QStringList&, const QSet<QString>&) — inherited
1352 // from PlacementEngineBase. Replaces windowsReleasedFromTiling.
1353
1354 // windowFloatingChanged (emitted from performToggleFloat and
1355 // setWindowFloat with user-intent semantics: the downstream handler
1356 // restores pre-tile geometry, shows the navigation OSD, etc.),
1357 // activateWindowRequested, and navigationFeedback are inherited from
1358 // PlacementEngineBase. Plain comments, not a doxygen block — this class
1359 // declares no signal of those names for a doc block to attach to.
1360
1361 // windowFloatingStateSynced and windowsBatchFloated are inherited from
1362 // PlacementEngineBase. Autotile-specific documentation: windowFloatingStateSynced
1363 // is emitted when the engine floats a window on its own initiative (a Float
1364 // rule or a restored float at insert) and the daemon must mirror it. The
1365 // downstream handler updates WTS bookkeeping without geometry restore.
1366 // windowsBatchFloated is emitted when overflow windows are batch-floated
1367 // during applyTiling; the daemon handler updates WTS state directly.
1368
1377 void windowsTiled(const QString& tileRequestsJson);
1378
1379public:
1380 // ═══════════════════════════════════════════════════════════════════════════
1381 // Autotile-float origin tracking (ephemeral, not persisted)
1382 // ═══════════════════════════════════════════════════════════════════════════
1383
1384 void markAutotileFloated(const QString& rawWindowId);
1385 void clearAutotileFloated(const QString& rawWindowId);
1386 bool isAutotileFloated(const QString& rawWindowId) const;
1387
1388 int pruneStaleWindows(const QSet<QString>& aliveWindowIds) override;
1389
1396 QRect lastManagedRect(const QString& rawWindowId) const override;
1397
1398private Q_SLOTS:
1399 void onWindowAdded(const QString& windowId);
1400 void onWindowRemoved(const QString& windowId);
1401 void onWindowFocused(const QString& windowId);
1402 void onScreenGeometryChanged(const QString& screenId);
1403 void onLayoutChanged(PhosphorZones::Layout* layout);
1404
1405private:
1406 void connectSignals();
1407 bool insertWindow(const QString& windowId, const QString& screenId);
1409 QList<QSize> managedSizesOnScreen(const QString& screenId) const;
1410 // Passive float-state sync after insertWindow() places a window FLOATING
1411 // (matched Float rule / restored saved float); a tiled placement announces
1412 // nothing. Shared by onWindowAdded and backfillWindows so the two cannot
1413 // diverge.
1414 void emitInsertFloatStateSync(const QString& windowId, const QString& screenId);
1418 void insertWindowByConfigOrder(PhosphorTiles::TilingState* state, const QString& windowId, const QString& screenId);
1420 void installContextResolver();
1421 struct PendingMembership;
1422 void collectMembershipWork(const QString& windowId, const QString& screenId,
1423 const PhosphorEngine::TilingStateKey& currentKey,
1424 const PhosphorEngine::DesktopSpan& span, bool adoptAllowed,
1425 QList<PendingMembership>& pending) const;
1426 PhosphorEngine::MembershipReconcileResult applyMembershipWork(const QString& screenId,
1427 const PhosphorEngine::TilingStateKey& currentKey,
1428 const QList<PendingMembership>& pending);
1432 void syncFloatMirrorForContext(const QString& screenId, const PhosphorEngine::TilingStateKey& currentKey);
1433 bool adoptIntoContext(const QString& windowId, const PhosphorEngine::TilingStateKey& key);
1434 void releaseMembership(const QString& windowId, const PhosphorEngine::TilingStateKey& key);
1438 void dropFromOtherContexts(const QString& windowId, const PhosphorEngine::TilingStateKey& keepKey);
1441 void retileIfDirtyBackground(const QString& screenId);
1446 bool contextRunsAutotile(const PhosphorEngine::TilingStateKey& key) const;
1447 void removeWindow(const QString& windowId);
1448
1454 QString removeTrackedWindowNoRetile(const QString& windowId);
1455
1460 void dropClosedWindowFromDragPreview(const QString& windowId);
1461 bool storeWindowMinSize(const QString& windowId, int minWidth, int minHeight);
1462 bool recalculateLayout(const QString& screenId);
1463 void applyTiling(const QString& screenId);
1464
1474 bool applyTreeResizeReflow(PhosphorTiles::TilingState* state, const QString& windowId, const QRect& oldFrame,
1475 const QRect& newFrame, const QString& screenId);
1476 bool shouldTileWindow(const QString& windowId) const;
1477 QString screenForWindow(const QString& windowId) const;
1478 QRect screenGeometry(const QString& screenId) const;
1479
1483 bool isKnownScreen(const QString& screenId) const;
1484
1518 bool releaseScreenStateForTeardown(const PhosphorEngine::TilingStateKey& key, PhosphorTiles::TilingState* state,
1519 QStringList& releasedWindows, bool drainOverflow = true,
1520 bool clearScreenOrderMaps = true);
1521
1542 bool migrateStateKey(const PhosphorEngine::PlacementStateKey& oldKey,
1543 const PhosphorEngine::PlacementStateKey& newKey);
1545 void applyDesktopRemap(const PhosphorEngine::DesktopRemap& remap);
1546
1557 void migrateWindowBetweenKeys(const QString& windowId, const PhosphorEngine::TilingStateKey& oldKey,
1558 const QString& newScreenId);
1559
1570 void revalidateWindowContext(const QString& windowId, const QString& screenId);
1571
1580 PhosphorEngine::TilingStateKey currentKeyForScreen(const QString& screenId) const
1581 {
1582 // Precedence and the sticky-pin / per-output subtleties live in the
1583 // shared ScreenContextTracker (sticky-pin override > per-output desktop >
1584 // global desktop; activity = current activity).
1585 return m_context.currentKeyForScreen(screenId);
1586 }
1587
1595 enum class PropagateScope {
1596 CurrentContext,
1597 AllContexts,
1598 };
1599
1603 void propagateGlobalSplitRatio(PropagateScope scope = PropagateScope::CurrentContext);
1604
1608 void propagateGlobalMasterCount(PropagateScope scope = PropagateScope::CurrentContext);
1609
1621 void backfillWindows();
1622
1635 void retileScreen(const QString& screenId);
1636
1646 void scheduleRetileRetry(const QString& screenId);
1647
1651 void processRetileRetries();
1652
1653 // ═══════════════════════════════════════════════════════════════════════════════
1654 // Helper Methods
1655 // ═══════════════════════════════════════════════════════════════════════════════
1656
1667 bool cleanupPendingOrderIfResolved(const QString& screenId);
1668 void schedulePendingOrderTimeout(const QString& screenId, uint64_t generation);
1669
1676 bool warnIfEmptyWindowId(const QString& windowId, const char* operation) const;
1677
1693 QString canonicalizeWindowId(const QString& rawWindowId);
1694
1701 void cleanupCanonical(const QString& anyWindowId);
1702
1713 void purgePendingFocusForWindow(const QString& windowId);
1714
1729 void sweepPhantomTracking(const QString& windowId);
1730
1738 QString canonicalizeForLookup(const QString& rawWindowId) const;
1739
1752 QString currentAppIdFor(const QString& anyWindowId) const;
1753
1770 void performToggleFloat(PhosphorTiles::TilingState* state, const QString& windowId, const QString& screenId);
1771
1780 void toggleWindowFloatAs(const QString& rawWindowId, const QString& screenId, const QString& failureAction);
1781
1791 PhosphorTiles::TilingState* stateForWindow(const QString& windowId, QString* outScreenId = nullptr);
1792
1793 QSet<QString> m_autotileFloatedWindows;
1794
1795 PhosphorZones::LayoutRegistry* m_layoutManager = nullptr;
1797 std::function<bool(const QString& screenId, int desktop, const QString& activity)> m_scrollingModeResolver;
1798 PhosphorEngine::IWindowTrackingService* m_windowTracker = nullptr;
1799 PhosphorScreens::ScreenManager* m_screenManager = nullptr;
1803 PhosphorEngine::ICrossSurfaceResolver* m_crossSurfaceResolver = nullptr;
1804 PhosphorEngine::IWindowRegistry* m_windowRegistry = nullptr;
1808 QMetaObject::Connection m_appIdResolverHook;
1809 PhosphorTiles::ITileAlgorithmRegistry* m_algorithmRegistry = nullptr;
1810 std::unique_ptr<AutotileConfig> m_config;
1811 std::unique_ptr<PerScreenConfigResolver> m_configResolver;
1812 std::unique_ptr<NavigationController> m_navigation;
1813 QTimer m_writeBackGuardTimer;
1814 QTimer m_settingsRetileTimer;
1815
1816 // Persistence delegates (storage stays in the WTA)
1817 std::function<void()> m_persistSaveFn;
1818 std::function<void()> m_persistLoadFn;
1819
1820 // Floated-position-restore gate. Empty until the daemon wires it; while empty
1821 // the engine always re-applies a floated window's recorded position (historical
1822 // behaviour). See RestorePositionPredicate doc above.
1823 RestorePositionPredicate m_restorePositionPredicate{};
1824
1825 // Rule-driven open-floating gate; empty until the daemon wires it (see FloatPredicate).
1826 FloatPredicate m_floatPredicate{};
1827
1828 // Alias for the type hoisted to AutotileEngineTypes.h.
1829 using MigrationArrival = ::PhosphorTileEngine::MigrationArrival;
1830 std::optional<MigrationArrival> m_migrationArrival;
1832 QSet<QString> m_crossScreenClaimsExhausted;
1833
1836 bool insertShouldFloat(const QString& windowId, const QString& screenId) const;
1837
1838 QSet<QString> m_autotileScreens;
1839 QString m_algorithmId;
1840 bool m_algorithmEverSet = false;
1848 bool m_refreshingFromSettings = false;
1849 QString m_activeScreen; // Last-focused screen (updated by onWindowFocused)
1850
1851 // Per-screen tiling states + the windowId→memberships reverse map (one
1852 // key per state holding the window, with a context resolver picking the
1853 // one in view). States are owned via Qt parent (this); PerScreenStates
1854 // holds the two maps and their lockstep bookkeeping — engine-specific
1855 // lifecycle stays in this class.
1856 PhosphorEngine::PerScreenStates<PhosphorTiles::TilingState> m_states;
1857
1858 // Screen+desktop states whose split ratio / master count the user has
1859 // explicitly tuned (keyboard shortcut or interactive resize). propagateGlobal*
1860 // skips these so a per-desktop tweak survives a settings refresh and is never
1861 // written into the global config — keeping the adjustment local to that
1862 // (screen, desktop, activity). Cleared on an algorithm switch and when the
1863 // user changes the corresponding global value in settings. This is
1864 // within-session state only: it is not persisted, so the per-desktop tweak
1865 // does not survive a daemon restart (neither does the value it guards —
1866 // autotile persistence is per-window, not per-desktop ratio/count).
1867 QSet<PhosphorEngine::TilingStateKey> m_userTunedSplitRatio;
1868 QSet<PhosphorEngine::TilingStateKey> m_userTunedMasterCount;
1869
1870 // Script-state bags rescued from TilingStates that a teardown destroys, so a
1871 // re-created state for the same key can pick its bag back up. See
1872 // StashedScriptState in AutotileEngineTypes.h for the full rationale (harvest
1873 // rules, the algorithm tag, split-tree carry). The alias keeps the
1874 // AutotileEngine::StashedScriptState spelling valid for existing call sites.
1875 using StashedScriptState = ::PhosphorTileEngine::StashedScriptState;
1876 std::unordered_map<PhosphorEngine::TilingStateKey, StashedScriptState> m_scriptStateStash;
1877
1886 void stashScriptState(const PhosphorEngine::TilingStateKey& key, PhosphorTiles::TilingState* state);
1887
1896 void restoreStashedScriptState(const PhosphorEngine::TilingStateKey& key, PhosphorTiles::TilingState* state);
1897
1912 void restoreStashedSplitTree(const PhosphorEngine::TilingStateKey& key, PhosphorTiles::TilingState* state,
1913 const PhosphorTiles::TilingAlgorithm* algo);
1914
1922 void dropStashedScriptStatesForAlgorithmChange(const QString& screenId, const QString& newAlgorithmId);
1923
1924 QHash<QString, QSize> m_windowMinSizes; // windowId -> minimum size from KWin
1925
1926 // Canonical windowId → tile rect last emitted for it by applyTiling.
1927 // Backs lastManagedRect(): deliberately NOT cleared when the window
1928 // leaves the tiled state (that survival is the point — see the base
1929 // doc). Cleared on exactly two events: a genuine cross-screen move off
1930 // an autotile screen (the reposition has already moved the frame off
1931 // the old tile rect) and stale-window pruning. Everything else KEEPS
1932 // the entry — windowClosed (the effect notifies autotile before
1933 // WindowTracking, so the orchestrator's close capture and its tile-rect
1934 // guard run after this engine's teardown), handoffRelease (the adopting
1935 // engine's capture runs right after the release), and
1936 // releaseScreenStateForTeardown (windows still open) — because in each
1937 // the live frame can still be the tile rect, exactly when the
1938 // orchestrator's guard needs this memory. Closed windows' entries are
1939 // reclaimed by pruneStaleWindows, whose sweep is independent of
1940 // tracking. Used solely for an exact frame comparison, so a stale rect
1941 // is harmless.
1942 QHash<QString, QRect> m_lastAppliedTileRect;
1943
1944 // Instance id → first-seen canonical windowId.
1945 //
1946 // Fallback for when no shared WindowRegistry is attached (unit tests).
1947 // With a registry, canonicalization delegates to it instead. Production
1948 // daemons always take the registry path, so this map stays empty.
1949 //
1950 // The canonical form is the FIRST windowId string we saw for a given
1951 // instance id. Subsequent arrivals with a mutated appId (Electron/CEF
1952 // apps that swap WM_CLASS mid-session) resolve back to that canonical
1953 // form so every map/PhosphorTiles::TilingState key in the engine stays consistent.
1954 QHash<QString, QString> m_canonicalByInstance;
1955
1956 // Current desktop/activity context — the global current desktop, per-output
1957 // desktop overrides (#648), the sticky-desktop pin, the current activity, and
1958 // the "ever set" arming flags. Used by tilingStateForScreen() to construct
1959 // the owning key via currentKeyForScreen(). Fed by setCurrentDesktop()/
1960 // setCurrentActivity()/setCurrentDesktopForScreen() BEFORE updateEngineScreens()
1961 // runs on a desktop/activity switch.
1962 PhosphorEngine::ScreenContextTracker m_context;
1963
1964 // Armed by a genuine desktop/activity switch (see the setCurrent* mutators);
1965 // consumed by setAutotileScreens()/the desktop-switch pass. Engine-specific,
1966 // so it stays here rather than in the shared ScreenContextTracker.
1967 bool m_isDesktopContextSwitch = false;
1968
1969 // Pre-seeded window order for snapping → autotile transitions.
1970 // Keyed by stable EDID-based screen ID (PhosphorScreens::ScreenIdentity::identifierFor).
1971 // Consumed by the strict seed in setAutotileScreens() (visible windows,
1972 // eagerly) and by insertWindow() as remaining windows arrive; purged
1973 // per-window via purgeFromPendingOrders on every path that stops managing
1974 // the window (close, insert refusal, handoff release, the off-autotile
1975 // focus arm, the cross-screen claim refusal, the onWindowAdded skip arm
1976 // and the shared phantom sweep), swept
1977 // by pruneStaleWindows, and reaped by the pending-order timeout — which
1978 // deliberately RETAINS an order holding live minimized placeholders, so
1979 // those entries persist until the window opens or closes.
1980 QHash<QString, QStringList> m_pendingInitialOrders;
1981 QHash<QString, uint64_t> m_pendingOrderGeneration;
1987 uint64_t m_pendingOrderSerial = 0;
1988 // Screens whose pendingInitialOrders entry is "strict" — saved order
1989 // wins even when arrival order differs. Set by setInitialWindowOrder
1990 // (mode transition: the daemon intentionally pre-computed an order from
1991 // the previous mode's zones, and that order MUST be preserved).
1992 // Lifetime is TIED to the pending order's own: cleared wherever the
1993 // order is removed (full consumption, per-window purge emptying it,
1994 // stale-window sweep, timeout reap, screen teardown) — an order retained
1995 // for a minimized placeholder keeps its strict flag with it. Entries seeded by
1996 // setInitialWindowOrder (mode transition) are the strict ones, and it is the
1997 // only producer in the tree, so every entry is strict today. Advisory
1998 // entries reconstructed per-window from the placement store would NOT be in
1999 // this set — for those the saved position is honored only when it appends at the
2000 // current tail, otherwise insertPosition takes over. This is the behaviour
2001 // users expect from their "After existing" / "After focused" / "As main
2002 // window" preference for new windows.
2003 QSet<QString> m_strictInitialOrderScreens;
2004
2005 // Per-screen overflow tracking with O(1) reverse-index lookups.
2006 OverflowManager m_overflow;
2007
2008 bool m_retiling = false;
2009
2010 // Queued-connection retile coalescing: windowOpened D-Bus calls arriving in
2011 // the same event loop pass are coalesced into a single retile per screen.
2012 // Uses QMetaObject::invokeMethod(Qt::QueuedConnection) which fires after
2013 // all currently-pending events are processed — no fixed delay needed.
2014 QSet<QString> m_pendingRetileScreens;
2021 QSet<PhosphorEngine::TilingStateKey> m_dirtyBackgroundContexts;
2022 bool m_retilePending = false;
2023
2024 // Bounded retry for transient screen geometry failures.
2025 // When QScreen is temporarily unavailable (e.g. during Wayland desktop switch),
2026 // recalculateLayout cannot compute zone geometry. Rather than silently dropping
2027 // the retile (leaving stale zones), we retry after a short interval.
2028 // Per-screen retry counts prevent infinite loops; cleared on success or screen removal.
2029 static constexpr int MaxRetileRetries = 3;
2030 static constexpr int RetileRetryIntervalMs = 150;
2031 QTimer m_retileRetryTimer;
2032 QSet<QString> m_retileRetryScreens;
2033 QHash<QString, int> m_retileRetryCount;
2034
2035 // Deferred focus, keyed by screen: set by onWindowAdded and
2036 // requestPostRetileFocus, emitted after that screen's applyTiling so the
2037 // focus request arrives at KWin AFTER windowsTiled (whose onComplete raises
2038 // windows in tiling order). Without this, the raise loop buries the new
2039 // window. Per-screen so an entry stranded by a no-op retile cannot be
2040 // consumed by another screen's batch and activate the wrong window.
2041 QHash<QString, QString> m_pendingFocusByScreen;
2042
2043 // Focus-before-track reseed: a windowFocused() can name a window not yet tracked in a TilingState, most
2044 // visibly on daemon restart, where the effect re-notifies the active window during bring-up and the
2045 // re-announce (windowsOpenedBatch) lands afterwards. onWindowFocused would drop that focus, leaving a
2046 // focus-driven layout (Theater) with no focused window until the user clicks around. Stash the dropped id
2047 // here and replay it in onWindowAdded once the window is tracked.
2048 QString m_pendingFocusReseedWindowId;
2049
2050 // DragInsertPreview moved to AutotileEngineTypes.h; alias keeps the
2051 // AutotileEngine::DragInsertPreview spelling valid for existing call sites.
2052 using DragInsertPreview = ::PhosphorTileEngine::DragInsertPreview;
2053 std::optional<DragInsertPreview> m_dragInsertPreview;
2054
2059 QString m_dragCancelFilterWindowId;
2060
2066 QString m_interactiveDragWindow;
2067
2074 void processPendingRetiles();
2075
2077 std::optional<std::pair<int, bool>> takeGrantedParkedPlace(const QString& windowId,
2079 PhosphorTiles::TilingState* state);
2081 PhosphorTiles::TilingState* tilingStateForKey(const PhosphorEngine::TilingStateKey& key);
2082
2083 // Appended last (installed header). Created by the first parkOutput.
2084 std::unique_ptr<TileEvacueePark> m_evacueePark;
2085 ContextTilesResolver m_contextModeResolver;
2086};
2087
2088} // namespace PhosphorTileEngine
How KWin's desktop positions moved in one change of its desktop list: for each 1-based position in th...
Definition DesktopRemap.h:29
Definition IAutotileSettings.h:15
Resolves the neighbouring surface — output or virtual desktop — in a direction, for cross-surface win...
Definition ICrossSurfaceResolver.h:21
static constexpr qreal kDefaultSplitRatioStep
One home for the master/split ratio step so the default return below and the two default arguments ca...
Definition IPlacementEngine.h:1147
LayoutSupport
How this engine relates to user-selectable layouts — the entries the layout picker,...
Definition IPlacementEngine.h:955
@ Placement
Layouts drive window placement (snap zone layouts, autotile algorithm cards): the classic picker sema...
Definition IPlacementEngine.h:962
Definition IWindowRegistry.h:49
Definition IWindowTrackingService.h:35
Abstract base class for placement engines.
Definition PlacementEngineBase.h:36
void algorithmChanged(const QString &algorithmId)
Emitted when the active tiling algorithm changes.
Centralized screen-topology service.
Definition Manager.h:86
void snapAllWindows(const PhosphorEngine::NavigationContext &ctx) override
Bring every unmanaged window on the screen back under this engine's placement (zones for snap,...
void setGlobalMasterCount(int count)
Set master count globally (config + every state, every desktop).
QSet< QString > activeScreens() const override
Definition AutotileEngine.h:212
void setCurrentDesktop(int desktop) override
Set the current virtual desktop for per-desktop tiling state.
void promoteToMaster(const QString &windowId)
Promote a window to the master area.
void pruneStatesForActivities(const QStringList &validActivities) override
Prune PhosphorTiles::TilingState entries for activities not in the given set.
void updateStickyScreenPins(const PhosphorEngine::StickyPredicate &, PhosphorEngine::StickyPinPhase) override
Pin screens where all autotiled windows are sticky (on all desktops).
friend class NavigationController
Definition AutotileEngine.h:76
PhosphorEngine::MembershipReconcileResult reconcileDesktopMemberships(const QString &screenId, const PhosphorEngine::DesktopSpanQuery &spanOf) override
Give a window a tile on every desktop it occupies.
bool effectiveSmartGaps(const QString &screenId) const
void pruneStatesForRemovedScreen(const QString &physicalScreenId) override
Prune PhosphorTiles::TilingState entries for a permanently removed monitor.
void swapFocusedInDirection(const QString &direction, const PhosphorEngine::NavigationContext &ctx) override
Swap the focused window with the adjacent window.
QString dragInsertPreviewWindowId() const
Get the window ID of the active drag-insert preview, or empty.
Definition AutotileEngine.h:1289
void clearModeSpecificFloatMarker(const QString &windowId) override
Definition AutotileEngine.h:247
void setFocusNewWindows(bool enabled)
QString algorithmId() const override
Definition AutotileEngine.h:255
QStringList parkOutput(const QString &physicalScreenId) override
Copy every context of physicalScreenId (each of its virtual screens) into the park,...
void retileAfterOperation(const QString &screenId, bool operationSucceeded)
Helper to retile a screen after a window operation.
void decreaseMasterRatio(qreal delta=kDefaultSplitRatioStep) override
Decrease the master area ratio.
void setRestorePositionPredicate(RestorePositionPredicate predicate)
Inject the floated-position-restore gate.
Definition AutotileEngine.h:528
void increaseMasterCount() override
Increase the number of master windows.
std::function< bool(const QString &windowId, const QString &screenId)> FloatPredicate
Predicate deciding whether an opening window should start FLOATING because a "Float this app" rule ma...
Definition AutotileEngine.h:549
void setGlobalSplitRatio(qreal ratio)
Set master ratio globally (config + every state, every desktop).
void purgeFromPendingOrders(const QString &windowId)
Purge windowId from every pending initial order, with full bookkeeping: empty orders drop their gener...
PhosphorEngine::IAutotileSettings * autotileSettings() const
void setFloatPredicate(FloatPredicate predicate)
Definition AutotileEngine.h:551
QStringList tiledWindowOrder(const QString &screenId) const
Get the current tiled window order for a screen.
void reapplyLayout(const PhosphorEngine::NavigationContext &ctx) override
Re-apply the current layout to all managed windows.
QSet< int > desktopsWithActiveState() const override
The virtual-desktop numbers any per-context entry names: a state, a parked context,...
bool effectiveRespectMinimumSize(const QString &screenId) const
void applyPerScreenConfig(const QString &screenId, const QVariantMap &overrides) override
void windowFocused(const QString &windowId, const QString &screenId) override
Notify the engine that a window was focused.
void toggleFocusedWindowFloat()
Toggle the focused window between tiled and floating states.
QStringList capturedWindowOrder(const QString &screenId) const
void commitDragInsertPreview() override
Commit the active drag-insert preview.
bool isWindowTiled(const QString &rawWindowId) const override
Check if a window is currently tiled (tracked AND not floating).
QString dragInsertPreviewScreenId() const override
Get the target screen ID of the active drag-insert preview, or empty.
Definition AutotileEngine.h:1297
void moveFocusedToPosition(int position)
Move the focused window to a specific position in the tiling order.
void markAutotileFloated(const QString &rawWindowId)
void refreshConfigFromSettings() override
Re-read all tuning values from the engine's settings interface.
void moveFocusedInDirection(const QString &direction, const PhosphorEngine::NavigationContext &ctx) override
Move the focused window to the adjacent slot.
PhosphorEngine::MembershipReconcileResult reconcileWindowMemberships(const QString &windowId, const PhosphorEngine::DesktopSpanQuery &spanOf) override
The same pass for ONE window, on the screen it is held on.
bool isActiveOnScreen(const QString &screenId) const override
Whether this engine is active on the given screen.
PhosphorTiles::TilingState * tilingStateForScreen(const QString &screenId)
Get the tiling state for a specific screen.
void setCrossSurfaceResolver(PhosphorEngine::ICrossSurfaceResolver *resolver) override
Inject the cross-surface resolver (neighbouring output / desktop lookup) used by directional navigati...
Definition AutotileEngine.h:329
int currentDesktop() const noexcept
Get the current virtual desktop tracked by the engine.
Definition AutotileEngine.h:401
void windowOpened(const QString &windowId, const QString &screenId, int minWidth, int minHeight) override
A new window appeared on this engine's screen.
int windowOrderIndexForWindow(const QString &screenId, const QString &windowId) const
The RAW window-order index of windowId on screenId (current desktop; counts floats,...
void windowsTiled(const QString &tileRequestsJson)
Emitted when windows are tiled to new geometries (batch).
void rotateWindowOrder(bool clockwise=true)
Rotate all tiled windows by one position.
void scheduleRetileForScreen(const QString &screenId) override
Schedule a deferred retile for a screen.
void loadState() override
Load tiling state via persistence delegate (IPlacementEngine contract).
void windowMinSizeUpdated(const QString &windowId, int minWidth, int minHeight) override
A window's minimum size changed after windowOpened (0 when unconstrained): retiles when it differs fr...
std::optional< PhosphorEngine::PlacementStateKey > heldKeyForWindow(const QString &windowId) const override
The (screen, desktop, activity) key of the state that genuinely holds windowId, tiled or floating,...
void pushToEmptyZone(const PhosphorEngine::NavigationContext &ctx) override
Move the focused window to the first empty slot.
void swapWindows(const QString &windowId1, const QString &windowId2)
Swap positions of two tiled windows.
void saveState() override
Save tiling state via persistence delegate (IPlacementEngine contract).
void toggleFocusedFloat(const PhosphorEngine::NavigationContext &ctx) override
Toggle the focused window between managed and floating.
void dropParked(const QString &windowId, const QString &physicalScreenId, int desktop, const QString &activity) override
Forget windowId's parked contexts; an empty physicalScreenId, a desktop of 0 or an empty activity mat...
void setCurrentDesktopForScreen(const QString &screenId, int desktop) override
Set a single screen's current virtual desktop (Plasma 6.7 per-output virtual desktops,...
void focusPrevious()
Focus the previous tiled window.
void clearScreenScheduling(const QString &screenId)
Drop every per-screen SCHEDULING entry for screenId: pending retiles, retile retry state,...
void toggleWindowFloat(const QString &windowId, const QString &screenId) override
Toggle a specific window between tiled and floating states.
PhosphorTiles::ITileAlgorithmRegistry * algorithmRegistry() const
The injected tile-algorithm registry. Borrowed — owner outlives the engine.
Definition AutotileEngine.h:87
bool hasDragInsertPreview() const override
Query whether a drag-insert preview is currently active.
Definition AutotileEngine.h:1279
QStringList managedWindowOrder(const QString &screenId) const override
Capture-on-leave order: the tiled order PLUS minimize-floated windows at their windowOrder positions.
Definition AutotileEngine.h:227
bool isAutotileFloated(const QString &rawWindowId) const
void clearPerScreenConfig(const QString &screenId) override
void setInitialWindowOrder(const QString &screenId, const QStringList &windowIds) override
Pre-seed initial window order for deterministic snapping → autotile transitions.
void setWindowFloat(const QString &windowId, bool shouldFloat, const QString &screenId=QString()) override
Set the floating state of a specific window.
void setInteractiveDragWindow(const QString &windowId) override
Mark windowId as under a compositor interactive move (IPlacementEngine contract).
void cycleFocus(bool forward, const PhosphorEngine::NavigationContext &ctx) override
Cycle keyboard focus through managed windows.
void moveFocusedToPosition(int position, const PhosphorEngine::NavigationContext &ctx) override
Move the focused window to the Nth position.
void decreaseMasterCount() override
Decrease the number of master windows.
void noteMasterCountUserTuned(const QString &screenId)
AutotileConfig * config() const noexcept
Get the autotile configuration.
void focusNext()
Focus the next tiled window.
void rotateWindows(bool clockwise, const QString &screenId)
int effectiveInnerGap(const QString &screenId) const
PhosphorEngine::IPlacementState * stateForScreen(const QString &screenId) override
Per-screen state object for the given screen.
void floatWindow(const QString &windowId)
Float a specific window by its ID (convenience forwarder).
void remapDesktops(const PhosphorEngine::DesktopRemap &remap) override
OPTIONAL: KWin's desktop list changed (a removal, an insert or a reorder).
QString algorithm() const noexcept
Get current algorithm ID.
void spanFocusedInDirection(const QString &direction, const PhosphorEngine::NavigationContext &ctx) override
Grow or shrink the focused window's zone span toward the direction: extend into the adjacent zone(s) ...
DragInsertTarget computeDragInsertTargetAtPoint(const QString &screenId, const QPoint &cursorPos) const override
IPlacementEngine drop-target form: wraps the flat index into DragInsertTarget::primary (invalid when ...
void autotileScreensChanged(const QStringList &screenIds, bool isDesktopSwitch)
Emitted when the set of autotile screens changes.
void focusInDirection(const QString &direction, const QString &action=QStringLiteral("focus"))
Focus the adjacent window in tiling order with OSD feedback.
std::function< bool(const QString &windowId, const QString &screenIdHint)> RestorePositionPredicate
Predicate consulted on reopen to decide whether a FLOATED (untiled) window should have its previous g...
Definition AutotileEngine.h:524
void increaseMasterRatio(qreal delta=kDefaultSplitRatioStep) override
Increase the master area ratio.
bool isWindowManaged(const QString &windowId) const override
Whether the engine considers the window "managed" (eligible for layout operations).
Definition AutotileEngine.h:251
void updatePerScreenOverride(const QString &screenId, const QString &key, const QVariant &value)
int pruneStaleWindows(const QSet< QString > &aliveWindowIds) override
Drop any per-engine bookkeeping for windows not in aliveWindowIds.
void noteCrossScreenClaimsExhausted(const QString &windowId, bool exhausted) override
INERT, kept for ABI: fed the removed cross-screen defer gates.
void setActiveScreens(const QSet< QString > &screens) override
Definition AutotileEngine.h:216
QString entryWindowForCrossing(const QString &screenId, const QString &direction) const
Cross-mode swap support (queried by the daemon when THIS engine is the target): the tiled window at s...
bool isWindowTracked(const QString &windowId) const override
Check if a window is currently tracked in any autotile state.
Definition AutotileEngine.h:159
QString managedFocusedWindow(const QString &screenId) const override
Capture half only.
bool hasPerScreenOverride(const QString &screenId, const QString &key) const
void focusMaster() override
Focus the master window.
void switchFocusBetweenFloatingAndTiling(const QString &screenId) override
Jump focus between the float layer and the tiled layout.
PhosphorTiles::AutotileInsertPosition effectiveInsertPosition(const QString &screenId) const
bool isWindowFloatingInAutotile(const QString &windowId) const
Authoritative per-window autotile float state.
PhosphorTiles::TilingAlgorithm * currentAlgorithm() const
Get the current algorithm instance.
void setAlgorithm(const QString &algorithmId) override
Set the tiling algorithm.
AutotileEngine(PhosphorZones::LayoutRegistry *layoutManager, PhosphorEngine::IWindowTrackingService *windowTracker, PhosphorScreens::ScreenManager *screenManager, PhosphorTiles::ITileAlgorithmRegistry *algorithmRegistry, QObject *parent=nullptr)
void renumberDesktopsAfterRemoval(int removedDesktop) override
Shift every per-(screen, desktop, activity) state ABOVE removedDesktop down by one,...
QString dragInsertPreviewPriorScreenId() const override
The screen the previewed window sat on before begin adopted it.
Definition AutotileEngine.h:1309
void cancelDragInsertPreview(bool dragStillActive=false) override
Cancel the active drag-insert preview, restoring the original order.
void setAutotileScreens(const QSet< QString > &screens)
Set which screens use autotile (derived from layout assignments).
void setScrollingModeResolver(std::function< bool(const QString &screenId, int desktop, const QString &activity)> resolver)
INERT, kept for ABI: a scrolling-mode resolver that fed windowOpened's cross-screen tile-restore defe...
Definition AutotileEngine.h:631
void requestPostRetileFocus(const QString &screenId, const QString &windowId)
Request that a window is activated after the given screen's next applyTiling.
void demoteFromMaster(const QString &windowId)
Demote a window from the master area.
void setPersistenceDelegate(std::function< void()> saveFn, std::function< void()> loadFn)
Set persistence callbacks for save/load.
Definition AutotileEngine.h:497
void swapFocusedWithMaster() override
Swap the currently focused window with the master window.
QVariantMap perScreenOverrides(const QString &screenId) const override
qreal effectiveSplitRatioStep(const QString &screenId) const override
void setContextGapProvider(std::function< QVariantMap(const QString &screenId)> provider)
void handoffRelease(const QString &windowId) override
Release ownership of a window WITHOUT modifying its geometry.
void restoreFocusedWindow(const PhosphorEngine::NavigationContext &ctx) override
Restore the focused window out of its managed state.
QStringList allFloatingWindows() const
All windows currently floating in autotile across every tracked state.
void focusInDirection(const QString &direction, const PhosphorEngine::NavigationContext &ctx) override
Move keyboard focus to the adjacent window.
int stickyPinnedDesktopForScreen(const QString &screenId) const override
The desktop this engine has pinned this screen to, or 0.
Definition AutotileEngine.h:239
void clearCurrentDesktopForScreen(const QString &screenId) override
Drop a screen's per-output desktop, reverting it to m_context's global desktop.
void notifyAlgorithmWindowAdded(PhosphorTiles::TilingState *state, const QString &screenId, const QString &windowId)
Run the algorithm's onWindowAdded lifecycle hook for a just-inserted window.
PhosphorTiles::TilingAlgorithm * effectiveAlgorithm(const QString &screenId) const
const QString & currentActivity() const noexcept
Get the current activity tracked by the engine.
Definition AutotileEngine.h:409
void noteSplitRatioUserTuned(const QString &screenId)
int effectiveMaxWindows(const QString &screenId) const
LayoutSupport layoutSupport() const override
Autotile algorithms appear as cards in the layout picker / quick slots, so this engine is a placement...
Definition AutotileEngine.h:560
void onWindowResized(const QString &rawWindowId, const QRect &oldFrame, const QRect &newFrame, const QString &screenId) override
Reflow neighbors after a window was interactively resized.
void retile(const QString &screenId=QString()) override
Force retiling of windows.
std::optional< PhosphorEngine::WindowPlacement > capturePlacementForKey(const QString &windowId, const PhosphorEngine::TilingStateKey &key) const
capturePlacement against ONE of the window's contexts rather than its primary.
bool isModeSpecificFloated(const QString &windowId) const override
Definition AutotileEngine.h:243
void rotateWindows(bool clockwise, const PhosphorEngine::NavigationContext &ctx) override
Rotate all managed windows on the screen.
QString engineId() const override
Stable engine identity for HandoffContext.fromEngineId.
Definition AutotileEngine.h:565
void setContextModeResolver(ContextTilesResolver resolver)
Definition AutotileEngine.h:623
void setWindowRegistry(QObject *registry) override
Wire up the shared WindowRegistry.
void reapplyManagedWindowAppearance() override
Re-drive the compositor's per-window appearance (border, hidden title bar) for every window this engi...
void clearAutotileFloated(const QString &rawWindowId)
QRect lastManagedRect(const QString &rawWindowId) const override
The tile rect this engine last emitted for rawWindowId via applyTiling, remembered PAST the window's ...
bool readoptParked(const QString &windowId, const QString &parkedPhysicalId, const QString &returnedPhysicalId) override
Re-seat windowId's contexts parked under parkedPhysicalId on returnedPhysicalId as a re-statement (no...
bool claimCrossScreenReopen(const QString &windowId, const QString &openingScreenId, int minWidth, int minHeight) override
The reopen claim (see IPlacementEngine for the contract): only a FIFO record on another virtual scree...
void setFocusedWindow(const QString &windowId)
Notify the engine that a window has been focused.
QString screenForTrackedWindow(const QString &windowId) const override
Return the screen this engine considers the window to be on (any context), or empty if the window isn...
Definition AutotileEngine.h:571
const QSet< QString > & autotileScreens() const
Get the set of screens currently using autotile.
Definition AutotileEngine.h:268
void unfloatWindow(const QString &windowId)
Unfloat a specific window by its ID (convenience forwarder).
::PhosphorLayout::EdgeGaps effectiveOuterGaps(const QString &screenId) const
void windowClosed(const QString &windowId) override
Notify the engine that a window was closed.
void markModeSpecificFloated(const QString &windowId) override
Definition AutotileEngine.h:259
QString heldScreenForWindow(const QString &windowId) const override
OPTIONAL: the screen this engine genuinely HOLDS the window on IN THE SCREEN'S CURRENT CONTEXT — a ME...
void enabledChanged(bool enabled)
Emitted when the enabled state changes.
bool isAutotileScreen(const QString &screenId) const
Check if a specific screen uses autotile.
void setActiveScreenHint(const QString &screenId) override
Set the active screen hint for keyboard shortcut handlers.
bool isEnabled() const noexcept override
Check if any screen has autotile enabled.
std::optional< int > savedMaxWindowsForAlgorithm(const QString &algorithmId) const override
The user's saved per-algorithm max-windows tuning, if any.
friend class PerScreenConfigResolver
Definition AutotileEngine.h:77
QSize windowMinimumSize(const QString &windowId) const override
The window's client-reported minimum size as last known by this engine, or an UNKNOWN answer when it ...
void updateDragInsertPreview(int insertIndex)
Update the target insert index for the active drag preview.
std::function< bool(const QString &screenId, int desktop, const QString &activity)> ContextTilesResolver
Whether a (screenId, desktop, activity) context tiles, as the daemon resolves it (feature switch,...
Definition AutotileEngine.h:622
bool beginDragInsertPreview(const QString &rawWindowId, const QString &screenId) override
Begin a drag-insert preview on screenId, ADOPTING the window when necessary.
void updateDragInsertPreview(const DragInsertTarget &target) override
IPlacementEngine drop-target form: primary is the tiled-only insert index; secondary/newSlot are mean...
int runtimeMaxWindows() const override
Runtime max-windows limit.
std::optional< PhosphorEngine::WindowPlacement > capturePlacement(const QString &windowId) const override
Report windowId's CURRENT placement for persistence, or nullopt if this engine does not manage it.
void handoffReceive(const HandoffContext &ctx) override
Receive ownership of a window from another engine.
void clearPendingInitialOrder(const QString &screenId)
Drop a screen's initial-order seed: the order, its generation counter and its strict marker,...
QString effectiveAlgorithmId(const QString &screenId) const
QString activeScreen() const override
Get the last-focused screen (updated by onWindowFocused).
Definition AutotileEngine.h:277
bool hasParked(const QString &windowId, const QString &physicalScreenId) const override
Whether windowId has a context parked under physicalScreenId (any output when it is empty).
void swapFocusedInDirection(const QString &direction, const QString &action=QStringLiteral("move"))
Swap the focused window with the adjacent window in tiling order.
void setCurrentActivity(const QString &activity) override
Set the current activity for per-activity tiling state.
void pruneStatesForDesktop(int removedDesktop) override
Prune every TilingState of removedDesktop, releasing its windows.
int computeDragInsertIndexAtPoint(const QString &screenId, const QPoint &cursorPos) const
Compute the insert index for a cursor position on an autotile screen.
Handles navigation, focus cycling, and ratio/count adjustments.
Definition NavigationController.h:34
Resolves per-screen configuration overrides for autotiling.
Definition PerScreenConfigResolver.h:41
Abstract contract for a tiling-algorithm registry.
Definition ITileAlgorithmRegistry.h:41
Abstract base class for tiling algorithms.
Definition TilingAlgorithm.h:54
Tracks tiling state for a single screen.
Definition TilingState.h:40
Manual zone-layout registry + per-context assignment store.
Definition LayoutRegistry.h:87
Represents a collection of zones that form a layout.
Definition Layout.h:42
Definition DesktopRemap.h:12
PlacementStateKey TilingStateKey
Backwards-compatible spelling for autotile's existing sources.
Definition EngineTypes.h:60
StickyPinPhase
Which half of the sticky-screen pin pass to run.
Definition EngineTypes.h:323
std::function< bool(const QString &)> StickyPredicate
Answers whether a window is on all desktops.
Definition EngineTypes.h:247
std::function< DesktopSpan(const QString &)> DesktopSpanQuery
Answers a window's DesktopSpan.
Definition EngineTypes.h:292
Definition IWindowTrackingService.h:28
Definition AutotileConfig.h:13
Definition AutotileEngine.h:52
AutotileInsertPosition
Definition AutotileConstants.h:207
Definition IWindowTrackingService.h:24
The contexts a window occupies, as the per-desktop membership pass reads them: which desktops (x11 nu...
Definition EngineTypes.h:258
Where a drag-insert preview should place the dragged window, in the TARGET ENGINE's slot vocabulary.
Definition IPlacementEngine.h:538
Context for a cross-engine window handoff.
Definition IPlacementEngine.h:863
What a membership pass did, so the caller can drive the bookkeeping the engines cannot reach: the pla...
Definition EngineTypes.h:299
Target window + screen for a navigation or lifecycle operation.
Definition NavigationContext.h:18
Identity of a per-screen placement state: a window's placement is scoped to the (screen,...
Definition EngineTypes.h:25
static QLatin1String autotileEngineId()
Definition WindowPlacement.h:271
Per-side edge gap values (resolved, non-negative pixel values).
Definition EdgeGaps.h:27
Configuration for autotiling behavior.
Definition AutotileConfig.h:82