6#include <phosphortileengine_export.h>
91 Q_PROPERTY(
bool enabled READ isEnabled NOTIFY enabledChanged)
92 Q_PROPERTY(QString algorithm READ algorithm WRITE setAlgorithm NOTIFY algorithmChanged)
100 Phosphor::Screens::ScreenManager* screenManager,
101 PhosphorTiles::ITileAlgorithmRegistry* algorithmRegistry, QObject* parent =
nullptr);
107 return m_algorithmRegistry;
157 QSet<
int> desktopsWithActiveState() const override;
164 bool isAutotileScreen(const QString& screenId) const;
173 bool isWindowTracked(const QString& windowId)
const override
175 return m_windowToStateKey.contains(windowId);
199 return autotileScreens();
203 setAutotileScreens(screens);
207 return tiledWindowOrder(screenId);
211 return isAutotileFloated(windowId);
215 clearAutotileFloated(windowId);
219 return isWindowTiled(windowId);
227 markAutotileFloated(windowId);
236 return m_autotileScreens;
245 return m_activeScreen;
318 return m_currentDesktop;
326 return m_currentActivity;
346 void setAlgorithm(const QString& algorithmId) override;
368 PhosphorEngine::IPlacementState* stateForScreen(const QString& screenId) override;
369 const
PhosphorEngine::IPlacementState* stateForScreen(const QString& screenId) const override;
392 void saveState() override;
401 void loadState() override;
413 void setPersistenceDelegate(std::function<
void()> saveFn, std::function<
void()> loadFn)
415 m_persistSaveFn = std::move(saveFn);
416 m_persistLoadFn = std::move(loadFn);
426 m_isWindowFloatingFn = std::move(fn);
432 return QStringLiteral(
"autotile");
438 const auto it = m_windowToStateKey.constFind(canonicalizeForLookup(windowId));
439 return it == m_windowToStateKey.constEnd() ? QString() : it.value().screenId;
525 std::function<bool(
const QString& screenId,
int desktop,
const QString& activity)>;
539 m_shouldPersistRestorePredicate = std::move(predicate);
585 Q_INVOKABLE
void retile(
const QString& screenId = QString())
override;
593 Q_INVOKABLE
void swapWindows(
const QString& windowId1,
const QString& windowId2);
783 Q_INVOKABLE
void focusInDirection(
const QString& direction,
const QString& action = QStringLiteral(
"focus"));
818 void moveToPosition(
const QString& windowId,
int position,
const QString& screenId);
830 Q_INVOKABLE
void setWindowFloat(
const QString& windowId,
bool shouldFloat)
override;
905 using IPlacementEngine::windowOpened;
906 void windowOpened(
const QString& windowId,
const QString& screenId,
int minWidth,
int minHeight)
override;
939 void windowFocused(
const QString& windowId,
const QString& screenId)
override;
1014 return m_dragInsertPreview.has_value();
1022 return m_dragInsertPreview ? m_dragInsertPreview->windowId : QString();
1030 return m_dragInsertPreview ? m_dragInsertPreview->targetScreenId : QString();
1106 void onWindowZoneChanged(
const QString& windowId,
const QString& zoneId);
1107 void onWindowAdded(
const QString& windowId);
1108 void onWindowRemoved(
const QString& windowId);
1109 void onWindowFocused(
const QString& windowId);
1110 void onScreenGeometryChanged(
const QString& screenId);
1120 void connectSignals();
1121 bool insertWindow(
const QString& windowId,
const QString& screenId);
1122 void removeWindow(
const QString& windowId);
1123 void removeSavedFloatingEntry(
const QString& windowId);
1124 void pruneStaleRestores(
const QString& appId);
1125 bool storeWindowMinSize(
const QString& windowId,
int minWidth,
int minHeight);
1126 bool recalculateLayout(
const QString& screenId);
1127 void applyTiling(
const QString& screenId);
1128 bool shouldTileWindow(
const QString& windowId)
const;
1129 QString screenForWindow(
const QString& windowId)
const;
1130 QRect screenGeometry(
const QString& screenId)
const;
1135 bool isKnownScreen(
const QString& screenId)
const;
1147 auto it = m_screenDesktopOverride.constFind(screenId);
1148 int desktop = (it != m_screenDesktopOverride.constEnd()) ? it.value() : m_currentDesktop;
1174 void propagateGlobalSplitRatio();
1179 void propagateGlobalMasterCount();
1192 void backfillWindows();
1206 void retileScreen(
const QString& screenId);
1217 void scheduleRetileRetry(
const QString& screenId);
1222 void processRetileRetries();
1238 bool cleanupPendingOrderIfResolved(
const QString& screenId);
1247 void schedulePromoteSavedWindowOrders();
1256 void promoteSavedWindowOrders();
1264 bool warnIfEmptyWindowId(
const QString& windowId,
const char* operation)
const;
1281 QString canonicalizeWindowId(
const QString& rawWindowId);
1289 void cleanupCanonical(
const QString& anyWindowId);
1298 QString canonicalizeForLookup(
const QString& rawWindowId)
const;
1312 QString currentAppIdFor(
const QString& anyWindowId)
const;
1322 void syncShortcutAdjustmentToSettings();
1342 QSet<QString> m_autotileFloatedWindows;
1349 std::unique_ptr<AutotileConfig> m_config;
1350 std::unique_ptr<PerScreenConfigResolver> m_configResolver;
1351 std::unique_ptr<NavigationController> m_navigation;
1352 QTimer m_writeBackGuardTimer;
1353 QTimer m_settingsRetileTimer;
1356 std::function<void()> m_persistSaveFn;
1357 std::function<void()> m_persistLoadFn;
1358 std::function<bool(
const QString&)> m_isWindowFloatingFn;
1360 QSet<QString> m_autotileScreens;
1361 QString m_algorithmId;
1362 bool m_algorithmEverSet =
false;
1363 QString m_activeScreen;
1364 QHash<PhosphorEngine::TilingStateKey, PhosphorTiles::TilingState*> m_screenStates;
1366 QHash<QString, PhosphorEngine::TilingStateKey> m_windowToStateKey;
1367 QHash<QString, QSize> m_windowMinSizes;
1379 QHash<QString, QString> m_canonicalByInstance;
1384 int m_currentDesktop = 1;
1385 QString m_currentActivity;
1386 bool m_isDesktopContextSwitch =
false;
1394 QHash<QString, int> m_screenDesktopOverride;
1399 QHash<PhosphorEngine::TilingStateKey, QSet<QString>> m_savedFloatingWindows;
1405 QHash<QString, QStringList> m_pendingInitialOrders;
1406 QHash<QString, uint64_t> m_pendingOrderGeneration;
1417 QSet<QString> m_strictInitialOrderScreens;
1423 QHash<PhosphorEngine::TilingStateKey, QStringList> m_savedWindowOrders;
1429 QHash<QString, QList<PendingAutotileRestore>> m_pendingAutotileRestores;
1435 ShouldPersistRestorePredicate m_shouldPersistRestorePredicate{};
1441 QTimer m_promoteOrdersTimer;
1444 OverflowManager m_overflow;
1446 bool m_retiling =
false;
1452 QSet<QString> m_pendingRetileScreens;
1453 bool m_retilePending =
false;
1460 static constexpr int MaxRetileRetries = 3;
1461 static constexpr int RetileRetryIntervalMs = 150;
1462 QTimer m_retileRetryTimer;
1463 QSet<QString> m_retileRetryScreens;
1464 QHash<QString, int> m_retileRetryCount;
1469 QString m_pendingFocusWindowId;
1478 struct DragInsertPreview
1481 QString targetScreenId;
1482 int lastInsertIndex = -1;
1485 bool hadPriorState =
false;
1488 int priorRawIndex = -1;
1489 bool priorFloating =
false;
1490 bool priorSameScreen =
false;
1497 QString evictedWindowId;
1499 std::optional<DragInsertPreview> m_dragInsertPreview;
1507 void processPendingRetiles();
Definition IAutotileSettings.h:15
Definition IWindowRegistry.h:12
Definition IWindowTrackingService.h:33
Abstract base class for placement engines.
Definition PlacementEngineBase.h:37
Core engine for automatic window tiling.
Definition AutotileEngine.h:89
void snapAllWindows(const PhosphorEngine::NavigationContext &ctx) override
Snap every unmanaged window on the screen to the current layout.
void setGlobalMasterCount(int count)
Set master count globally (config + all per-screen states)
QSet< QString > activeScreens() const override
Definition AutotileEngine.h:197
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 windowMinSizeUpdated(const QString &windowId, int minWidth, int minHeight)
Update a window's minimum size at runtime.
void pruneStatesForActivities(const QStringList &validActivities) override
Prune PhosphorTiles::TilingState entries for activities not in the given set.
bool effectiveSmartGaps(const QString &screenId) const
void updateStickyScreenPins(const std::function< bool(const QString &)> &isWindowSticky) override
Pin screens where all autotiled windows are sticky (on all desktops)
void swapFocusedInDirection(const QString &direction, const PhosphorEngine::NavigationContext &ctx) override
Swap the focused window with the adjacent window.
void markAutotileFloated(const QString &windowId)
QString dragInsertPreviewWindowId() const
Get the window ID of the active drag-insert preview, or empty.
Definition AutotileEngine.h:1020
void clearModeSpecificFloatMarker(const QString &windowId) override
Definition AutotileEngine.h:213
void setFocusNewWindows(bool enabled)
QString algorithmId() const override
Definition AutotileEngine.h:221
int pruneExcludedPendingRestores(const QStringList &exclusionPatterns)
Drop pending-restore queues whose appId matches any exclusion pattern.
void retileAfterOperation(const QString &screenId, bool operationSucceeded)
Helper to retile a screen after a window operation.
void increaseMasterCount() override
Increase the number of master windows.
void onWindowUnfloated(const QString &windowId) override
void setGlobalSplitRatio(qreal ratio)
Set master ratio globally (config + all per-screen states)
bool isWindowTiled(const QString &windowId) const override
Check if a window is currently tiled (tracked AND not floating).
PhosphorEngine::IAutotileSettings * autotileSettings() const
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.
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.
void commitDragInsertPreview() override
Commit the active drag-insert preview.
QString dragInsertPreviewScreenId() const override
Get the target screen ID of the active drag-insert preview, or empty.
Definition AutotileEngine.h:1028
void moveFocusedToPosition(int position)
Move the focused window to a specific position in the tiling order.
QJsonArray serializeWindowOrders() const override
Serialize per-context autotile window orders to JSON.
void clearAllSavedFloating() override
Clear ALL saved floating state (used when autotile is disabled globally)
void setWindowFloat(const QString &windowId, bool shouldFloat) override
Set the floating state of a specific window.
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.
void clearSavedFloatingForWindows(const QStringList &windowIds) override
Clear saved floating state for windows that are actively zone-snapped.
bool isActiveOnScreen(const QString &screenId) const override
Whether this engine is active on the given screen.
void setSmartGaps(bool enabled)
void setOuterGap(int gap)
int currentDesktop() const noexcept
Get the current virtual desktop tracked by the engine.
Definition AutotileEngine.h:316
void windowOpened(const QString &windowId, const QString &screenId, int minWidth, int minHeight) override
A new window appeared on this engine's screen.
void windowsTiled(const QString &tileRequestsJson)
Emitted when a window's floating state changes due to a user action.
void rotateWindowOrder(bool clockwise=true)
Rotate all tiled windows by one position.
bool isAutotileFloated(const QString &windowId) const
void scheduleRetileForScreen(const QString &screenId) override
Schedule a deferred retile for a screen.
void onWindowClaimed(const QString &windowId) override
void onWindowReleased(const QString &windowId) override
void increaseMasterRatio(qreal delta=0.05) override
Increase the master area ratio.
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 setInnerGap(int gap)
void toggleFocusedFloat(const PhosphorEngine::NavigationContext &ctx) override
Toggle the focused window between managed and floating.
int effectiveOuterGap(const QString &screenId) const
QJsonObject serializePendingRestores() const override
Serialize pending autotile restore queues to JSON.
void focusPrevious()
Focus the previous tiled window.
void toggleWindowFloat(const QString &windowId, const QString &screenId) override
Toggle a specific window between tiled and floating states.
void updateDragInsertPreview(int insertIndex) override
Update the target insert index for the active drag preview.
bool hasDragInsertPreview() const override
Query whether a drag-insert preview is currently active.
Definition AutotileEngine.h:1012
void deserializeWindowOrders(const QJsonArray &orders) override
Deserialize per-context autotile window orders from JSON.
bool beginDragInsertPreview(const QString &windowId, const QString &screenId) override
Begin a drag-insert preview for a window already tiled on a screen.
QStringList managedWindowOrder(const QString &screenId) const override
Definition AutotileEngine.h:205
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 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 focusNext()
Focus the next tiled window.
void rotateWindows(bool clockwise, const QString &screenId)
int effectiveInnerGap(const QString &screenId) const
void floatWindow(const QString &windowId)
Float a specific window by its ID (convenience forwarder)
void setShouldPersistRestorePredicate(ShouldPersistRestorePredicate predicate)
Inject the persist-restore gate.
Definition AutotileEngine.h:537
QString algorithm() const noexcept
Get current algorithm ID.
void autotileScreensChanged(const QStringList &screenIds, bool isDesktopSwitch)
Emitted when the set of autotile screens changes.
void cancelDragInsertPreview() override
Cancel the active drag-insert preview, restoring the original order.
void focusInDirection(const QString &direction, const QString &action=QStringLiteral("focus"))
Focus the adjacent window in tiling order with OSD feedback.
bool isWindowManaged(const QString &windowId) const override
Whether the engine considers the window "managed" (eligible for layout operations).
Definition AutotileEngine.h:217
void updatePerScreenOverride(const QString &screenId, const QString &key, const QVariant &value)
int pruneStaleWindows(const QSet< QString > &aliveWindowIds) override
void setActiveScreens(const QSet< QString > &screens) override
Definition AutotileEngine.h:201
bool hasPerScreenOverride(const QString &screenId, const QString &key) const
void focusMaster() override
Focus the master window.
void decreaseMasterRatio(qreal delta=0.05) override
Decrease the master area ratio.
void setAutotileScreens(const QSet< QString > &screens)
Set which screens use autotile (derived from layout assignments)
void demoteFromMaster(const QString &windowId)
Demote a window from the master area.
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
int computeDragInsertIndexAtPoint(const QString &screenId, const QPoint &cursorPos) const override
Compute the insert index for a cursor position on an autotile screen.
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.
void moveToPosition(const QString &windowId, int position, const QString &screenId)
void focusInDirection(const QString &direction, const PhosphorEngine::NavigationContext &ctx) override
Move keyboard focus to the adjacent window.
PhosphorTiles::TilingAlgorithm * effectiveAlgorithm(const QString &screenId) const
const QString & currentActivity() const noexcept
Get the current activity tracked by the engine.
Definition AutotileEngine.h:324
void setIsWindowFloatingFn(std::function< bool(const QString &)> fn) override
Set callback to query daemon-side window floating state.
Definition AutotileEngine.h:424
int effectiveMaxWindows(const QString &screenId) const
void retile(const QString &screenId=QString()) override
Force retiling of windows.
bool isModeSpecificFloated(const QString &windowId) const override
Definition AutotileEngine.h:209
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:430
void setWindowRegistry(QObject *registry) override
Wire up the shared WindowRegistry.
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, or empty if the window isn't tracked by ...
Definition AutotileEngine.h:436
void deserializePendingRestores(const QJsonObject &obj) override
Deserialize pending autotile restore queues from JSON.
const QSet< QString > & autotileScreens() const
Get the set of screens currently using autotile.
Definition AutotileEngine.h:234
void swapInDirection(const QString &direction, const QString &action)
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:225
void enabledChanged(bool enabled)
Emitted when the enabled state changes.
void setActiveScreenHint(const QString &screenId) override
Set the active screen hint for keyboard shortcut handlers.
void clearAutotileFloated(const QString &windowId)
bool isEnabled() const noexcept override
Check if any screen has autotile enabled.
std::function< bool(const QString &screenId, int desktop, const QString &activity)> ShouldPersistRestorePredicate
Predicate consulted before persisting or honoring a pending restore.
Definition AutotileEngine.h:525
void onWindowFloated(const QString &windowId) override
int runtimeMaxWindows() const override
Runtime max-windows limit.
void handoffReceive(const HandoffContext &ctx) override
Receive ownership of a window from another engine.
QString effectiveAlgorithmId(const QString &screenId) const
QString activeScreen() const override
Get the last-focused screen (updated by onWindowFocused)
Definition AutotileEngine.h:243
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 PhosphorTiles::TilingState and saved floating entries for a removed desktop.
Handles navigation, focus cycling, and ratio/count adjustments.
Definition NavigationController.h:33
Resolves per-screen configuration overrides for autotiling.
Definition PerScreenConfigResolver.h:38
Abstract contract for a tiling-algorithm registry.
Definition ITileAlgorithmRegistry.h:41
Abstract base class for tiling algorithms.
Definition TilingAlgorithm.h:56
Tracks tiling state for a single screen.
Definition TilingState.h:40
Manual zone-layout registry + per-context assignment store.
Definition LayoutRegistry.h:48
Represents a collection of zones that form a layout.
Definition Layout.h:74
Centralized screen-topology service.
Definition Manager.h:75
Definition EngineTypes.h:13
constexpr QLatin1String LayoutRegistry("org.plasmazones.LayoutRegistry")
Definition AutotileConfig.h:14
constexpr int MaxPendingRestoresPerApp
Maximum pending restore entries per appId (prevents unbounded growth).
Definition AutotileEngine.h:59
Definition AutotileEngine.h:71
Definition IWindowTrackingService.h:22
Definition IWindowTrackingService.h:26
Definition IWindowTrackingService.h:26
Context for a cross-engine window handoff.
Definition IPlacementEngine.h:310
Target window + screen for a navigation or lifecycle operation.
Definition NavigationContext.h:18
Definition EngineTypes.h:16
Per-side edge gap values (resolved, non-negative pixel values)
Definition EdgeGaps.h:27
Configuration for autotiling behavior.
Definition AutotileConfig.h:81
Saved position for a window removed from autotile, keyed by appId.
Definition AutotileEngine.h:44
bool wasFloating
Whether the window was floating when removed.
Definition AutotileEngine.h:55
int position
Index in window order at time of removal.
Definition AutotileEngine.h:53
PendingAutotileRestore(int pos, PhosphorEngine::TilingStateKey ctx, bool floating)
Definition AutotileEngine.h:46
PhosphorEngine::TilingStateKey context
Screen/desktop/activity where the window was tiled.
Definition AutotileEngine.h:54
PendingAutotileRestore()=default