6#include <phosphortileengine_export.h>
37class NavigationController;
38class PerScreenConfigResolver;
67 Q_PROPERTY(
bool enabled READ isEnabled NOTIFY enabledChanged)
68 Q_PROPERTY(QString algorithm READ algorithm WRITE setAlgorithm NOTIFY algorithmChanged)
77 PhosphorTiles::ITileAlgorithmRegistry* algorithmRegistry, QObject* parent =
nullptr);
83 return m_algorithmRegistry;
139 QSet<
int> desktopsWithActiveState() const override;
146 bool isAutotileScreen(const QString& screenId) const;
155 bool isWindowTracked(const QString& windowId)
const override
157 return m_windowToStateKey.contains(windowId);
204 return autotileScreens();
208 setAutotileScreens(screens);
212 return tiledWindowOrder(screenId);
216 return isAutotileFloated(windowId);
220 clearAutotileFloated(windowId);
224 return isWindowTiled(windowId);
232 markAutotileFloated(windowId);
241 return m_autotileScreens;
250 return m_activeScreen;
302 m_crossSurfaceResolver = resolver;
353 return m_currentDesktop;
361 return m_currentActivity;
381 void setAlgorithm(const QString& algorithmId) override;
403 PhosphorEngine::IPlacementState* stateForScreen(const QString& screenId) override;
404 const
PhosphorEngine::IPlacementState* stateForScreen(const QString& screenId) const override;
425 void saveState() override;
435 void loadState() override;
447 void setPersistenceDelegate(std::function<
void()> saveFn, std::function<
void()> loadFn)
449 m_persistSaveFn = std::move(saveFn);
450 m_persistLoadFn = std::move(loadFn);
471 m_restorePositionPredicate = std::move(predicate);
486 m_floatPredicate = std::move(predicate);
492 return QStringLiteral(
"autotile");
498 const auto it = m_windowToStateKey.constFind(canonicalizeForLookup(windowId));
499 return it == m_windowToStateKey.constEnd() ? QString() : it.value().screenId;
521 void onWindowResized(
const QString& rawWindowId,
const QRect& oldFrame,
const QRect& newFrame,
522 const QString& screenId)
override;
579 Q_INVOKABLE
void retile(
const QString& screenId = QString())
override;
587 Q_INVOKABLE
void swapWindows(
const QString& windowId1,
const QString& windowId2);
777 Q_INVOKABLE
void focusInDirection(
const QString& direction,
const QString& action = QStringLiteral(
"focus"));
814 std::optional<PhosphorEngine::WindowPlacement>
capturePlacement(
const QString& windowId)
const override;
825 void moveToPosition(
const QString& windowId,
int position,
const QString& screenId);
837 Q_INVOKABLE
void setWindowFloat(
const QString& windowId,
bool shouldFloat)
override;
895 using IPlacementEngine::windowOpened;
896 void windowOpened(
const QString& windowId,
const QString& screenId,
int minWidth,
int minHeight)
override;
929 void windowFocused(
const QString& windowId,
const QString& screenId)
override;
1008 return m_dragInsertPreview.has_value();
1016 return m_dragInsertPreview ? m_dragInsertPreview->windowId : QString();
1024 return m_dragInsertPreview ? m_dragInsertPreview->targetScreenId : QString();
1107 void onWindowZoneChanged(
const QString& windowId,
const QString& zoneId);
1108 void onWindowAdded(
const QString& windowId);
1109 void onWindowRemoved(
const QString& windowId);
1110 void onWindowFocused(
const QString& windowId);
1111 void onScreenGeometryChanged(
const QString& screenId);
1115 void connectSignals();
1116 bool insertWindow(
const QString& windowId,
const QString& screenId);
1121 void emitInsertFloatStateSync(
const QString& windowId,
const QString& screenId);
1126 void removeWindow(
const QString& windowId);
1133 QString removeTrackedWindowNoRetile(
const QString& windowId);
1139 void dropClosedWindowFromDragPreview(
const QString& windowId);
1140 bool storeWindowMinSize(
const QString& windowId,
int minWidth,
int minHeight);
1141 bool recalculateLayout(
const QString& screenId);
1142 void applyTiling(
const QString& screenId);
1154 const QRect& newFrame,
const QString& screenId);
1155 bool shouldTileWindow(
const QString& windowId)
const;
1156 QString screenForWindow(
const QString& windowId)
const;
1157 QRect screenGeometry(
const QString& screenId)
const;
1162 bool isKnownScreen(
const QString& screenId)
const;
1182 QStringList& releasedWindows,
bool drainOverflow =
true);
1195 const QString& newScreenId);
1207 void revalidateWindowContext(
const QString& windowId,
const QString& screenId);
1226 int desktop = m_currentDesktop;
1227 if (
auto perOut = m_screenCurrentDesktop.constFind(screenId); perOut != m_screenCurrentDesktop.constEnd()) {
1228 desktop = perOut.value();
1230 if (
auto pin = m_screenDesktopOverride.constFind(screenId); pin != m_screenDesktopOverride.constEnd()) {
1231 desktop = pin.value();
1258 void propagateGlobalSplitRatio();
1263 void propagateGlobalMasterCount();
1276 void backfillWindows();
1290 void retileScreen(
const QString& screenId);
1301 void scheduleRetileRetry(
const QString& screenId);
1306 void processRetileRetries();
1322 bool cleanupPendingOrderIfResolved(
const QString& screenId);
1330 bool warnIfEmptyWindowId(
const QString& windowId,
const char* operation)
const;
1347 QString canonicalizeWindowId(
const QString& rawWindowId);
1355 void cleanupCanonical(
const QString& anyWindowId);
1364 QString canonicalizeForLookup(
const QString& rawWindowId)
const;
1378 QString currentAppIdFor(
const QString& anyWindowId)
const;
1398 QSet<QString> m_autotileFloatedWindows;
1409 std::unique_ptr<AutotileConfig> m_config;
1410 std::unique_ptr<PerScreenConfigResolver> m_configResolver;
1411 std::unique_ptr<NavigationController> m_navigation;
1412 QTimer m_writeBackGuardTimer;
1413 QTimer m_settingsRetileTimer;
1416 std::function<void()> m_persistSaveFn;
1417 std::function<void()> m_persistLoadFn;
1422 RestorePositionPredicate m_restorePositionPredicate{};
1426 FloatPredicate m_floatPredicate{};
1428 QSet<QString> m_autotileScreens;
1429 QString m_algorithmId;
1430 bool m_algorithmEverSet =
false;
1431 QString m_activeScreen;
1432 QHash<PhosphorEngine::TilingStateKey, PhosphorTiles::TilingState*> m_screenStates;
1443 QSet<PhosphorEngine::TilingStateKey> m_userTunedSplitRatio;
1444 QSet<PhosphorEngine::TilingStateKey> m_userTunedMasterCount;
1446 QHash<QString, PhosphorEngine::TilingStateKey> m_windowToStateKey;
1447 QHash<QString, QSize> m_windowMinSizes;
1459 QHash<QString, QString> m_canonicalByInstance;
1464 int m_currentDesktop = 1;
1465 QString m_currentActivity;
1466 bool m_isDesktopContextSwitch =
false;
1472 bool m_desktopContextEverSet =
false;
1477 bool m_activityContextEverSet =
false;
1485 QHash<QString, int> m_screenDesktopOverride;
1494 QHash<QString, int> m_screenCurrentDesktop;
1500 QHash<QString, QStringList> m_pendingInitialOrders;
1501 QHash<QString, uint64_t> m_pendingOrderGeneration;
1513 QSet<QString> m_strictInitialOrderScreens;
1516 OverflowManager m_overflow;
1518 bool m_retiling =
false;
1524 QSet<QString> m_pendingRetileScreens;
1525 bool m_retilePending =
false;
1532 static constexpr int MaxRetileRetries = 3;
1533 static constexpr int RetileRetryIntervalMs = 150;
1534 QTimer m_retileRetryTimer;
1535 QSet<QString> m_retileRetryScreens;
1536 QHash<QString, int> m_retileRetryCount;
1541 QString m_pendingFocusWindowId;
1550 struct DragInsertPreview
1553 QString targetScreenId;
1554 int lastInsertIndex = -1;
1557 bool hadPriorState =
false;
1560 int priorRawIndex = -1;
1561 bool priorFloating =
false;
1562 bool priorSameScreen =
false;
1569 QString evictedWindowId;
1571 std::optional<DragInsertPreview> m_dragInsertPreview;
1579 void processPendingRetiles();
Definition IAutotileSettings.h:15
Resolves the neighbouring surface — output or virtual desktop — in a direction, for cross-surface win...
Definition ICrossSurfaceResolver.h:21
Definition IWindowRegistry.h:12
Definition IWindowTrackingService.h:34
Abstract base class for placement engines.
Definition PlacementEngineBase.h:30
Centralized screen-topology service.
Definition Manager.h:75
Core engine for automatic window tiling.
Definition AutotileEngine.h:65
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:202
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.
QString dragInsertPreviewWindowId() const
Get the window ID of the active drag-insert preview, or empty.
Definition AutotileEngine.h:1014
void clearModeSpecificFloatMarker(const QString &windowId) override
Definition AutotileEngine.h:218
void setFocusNewWindows(bool enabled)
QString algorithmId() const override
Definition AutotileEngine.h:226
void retileAfterOperation(const QString &screenId, bool operationSucceeded)
Helper to retile a screen after a window operation.
void setRestorePositionPredicate(RestorePositionPredicate predicate)
Inject the floated-position-restore gate.
Definition AutotileEngine.h:469
std::function< bool(const QString &windowId)> FloatPredicate
Predicate deciding whether an opening window should start FLOATING because a "Float this app" window ...
Definition AutotileEngine.h:482
void increaseMasterCount() override
Increase the number of master windows.
void setGlobalSplitRatio(qreal ratio)
Set master ratio globally (config + all per-screen states)
PhosphorEngine::IAutotileSettings * autotileSettings() const
void setFloatPredicate(FloatPredicate predicate)
Definition AutotileEngine.h:484
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.
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:1022
void moveFocusedToPosition(int position)
Move the focused window to a specific position in the tiling order.
void markAutotileFloated(const QString &rawWindowId)
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.
bool isActiveOnScreen(const QString &screenId) const override
Whether this engine is active on the given screen.
void setSmartGaps(bool enabled)
void setCrossSurfaceResolver(PhosphorEngine::ICrossSurfaceResolver *resolver) override
Inject the cross-surface resolver (neighbouring output / desktop lookup) used by directional navigati...
Definition AutotileEngine.h:300
void setOuterGap(int gap)
int currentDesktop() const noexcept
Get the current virtual desktop tracked by the engine.
Definition AutotileEngine.h:351
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 a window's floating state changes due to a user action.
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 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
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 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:1006
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:210
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 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)
std::function< bool(const QString &windowId)> RestorePositionPredicate
Predicate consulted on reopen to decide whether a FLOATED (untiled) window should have its previous g...
Definition AutotileEngine.h:465
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)
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:222
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 setActiveScreens(const QSet< QString > &screens) override
Definition AutotileEngine.h:206
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 hasPerScreenOverride(const QString &screenId, const QString &key) const
void focusMaster() override
Focus the master window.
bool isWindowFloatingInAutotile(const QString &windowId) const
Authoritative per-window autotile float state.
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
void setContextGapProvider(std::function< QVariantMap(const QString &screenId)> provider)
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)
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.
void clearCurrentDesktopForScreen(const QString &screenId) override
Drop a screen's per-output desktop, reverting it to the global m_currentDesktop.
PhosphorTiles::TilingAlgorithm * effectiveAlgorithm(const QString &screenId) const
const QString & currentActivity() const noexcept
Get the current activity tracked by the engine.
Definition AutotileEngine.h:359
void noteSplitRatioUserTuned(const QString &screenId)
int effectiveMaxWindows(const QString &screenId) const
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.
bool isModeSpecificFloated(const QString &windowId) const override
Definition AutotileEngine.h:214
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:490
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)
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:496
const QSet< QString > & autotileScreens() const
Get the set of screens currently using autotile.
Definition AutotileEngine.h:239
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:230
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.
bool isEnabled() const noexcept override
Check if any screen has autotile enabled.
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.
QString effectiveAlgorithmId(const QString &screenId) const
QString activeScreen() const override
Get the last-focused screen (updated by onWindowFocused)
Definition AutotileEngine.h:248
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:34
Resolves per-screen configuration overrides for autotiling.
Definition PerScreenConfigResolver.h:40
Abstract contract for a tiling-algorithm registry.
Definition ITileAlgorithmRegistry.h:41
Abstract base class for tiling algorithms.
Definition TilingAlgorithm.h:51
Tracks tiling state for a single screen.
Definition TilingState.h:40
Manual zone-layout registry + per-context assignment store.
Definition LayoutRegistry.h:78
Represents a collection of zones that form a layout.
Definition Layout.h:40
Definition EngineTypes.h:13
constexpr QLatin1String LayoutRegistry("org.plasmazones.LayoutRegistry")
Definition IWindowTrackingService.h:27
Definition AutotileConfig.h:13
Definition AutotileEngine.h:46
Definition IWindowTrackingService.h:23
Context for a cross-engine window handoff.
Definition IPlacementEngine.h:385
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:80