Tracks tiling state for a single screen. More...
#include <phosphor-tiles/include/PhosphorTiles/TilingState.h>
Signals | |
| void | windowCountChanged () |
| Emitted when window count changes (add/remove) | |
| void | windowOrderChanged () |
| Emitted when window order changes (move/swap) | |
| void | masterCountChanged () |
| Emitted when master count changes. | |
| void | splitRatioChanged () |
| Emitted when split ratio changes. | |
| void | floatingChanged (const QString &windowId, bool floating) |
| Emitted when a window's floating state changes. | |
| void | focusedWindowChanged () |
| Emitted when focused window changes. | |
| void | stateChanged () |
| Emitted when any state change requires retiling. | |
Public Member Functions | |
| TilingState (const QString &screenId, QObject *parent=nullptr) | |
| Construct a TilingState for a specific screen. | |
| ~TilingState () override | |
| TilingState (const TilingState &)=delete | |
| TilingState & | operator= (const TilingState &)=delete |
| QString | screenId () const override |
| Get the screen ID this state belongs to. | |
| int | windowCount () const override |
| Get total number of tracked windows (including floating) | |
| int | tiledWindowCount () const override |
| Get number of tiled windows (excluding floating) | |
| QStringList | windowOrder () const |
| Get the ordered list of window IDs. | |
| QStringList | tiledWindows () const |
| Get only tiled (non-floating) windows in order. | |
| bool | addWindow (const QString &windowId, int position=-1) |
| Add a window to the tiling. | |
| bool | removeWindow (const QString &windowId) |
| Remove a window from the tiling. | |
| bool | moveWindow (int fromIndex, int toIndex) |
| Move a window to a different position. | |
| bool | swapWindows (int index1, int index2) |
| Swap two windows' positions. | |
| bool | swapWindowsById (const QString &windowId1, const QString &windowId2) |
| Swap two windows by their IDs. | |
| int | windowIndex (const QString &windowId) const |
| Get the index of a window. | |
| bool | containsWindow (const QString &windowId) const override |
| Check if a window is tracked. | |
| int | masterCount () const override |
| Get number of windows in master area. | |
| void | setMasterCount (int count) |
| Set number of windows in master area. | |
| bool | isMaster (const QString &windowId) const |
| Check if a window is in the master area. | |
| QStringList | masterWindows () const |
| Get windows currently in master area. | |
| QStringList | stackWindows () const |
| Get windows currently in stack area. | |
| bool | promoteToMaster (const QString &windowId) |
| Promote a window to master (move to position 0) | |
| bool | moveToFront (const QString &windowId) |
| Move a window to the front (alias for promoteToMaster) | |
| bool | insertAfterFocused (const QString &windowId) |
| Insert a window after the currently focused window. | |
| bool | moveToPosition (const QString &windowId, int position) |
| Move a window to a specific position by its ID. | |
| int | windowPosition (const QString &windowId) const |
| Get the position of a window (alias for windowIndex) | |
| int | tiledWindowIndex (const QString &windowId) const |
| Get the index of a window within the tiled-only list. | |
| bool | moveToTiledPosition (const QString &windowId, int tiledPosition) |
| Move a window to a specific position in the tiled-only list. | |
| bool | rotateWindows (bool clockwise=true) |
| Rotate all windows by one position. | |
| qreal | splitRatio () const |
| Get the master/stack split ratio. | |
| void | setSplitRatio (qreal ratio) |
| Set the master/stack split ratio. | |
| void | increaseSplitRatio (qreal delta=0.05) |
| Increase split ratio by delta. | |
| void | decreaseSplitRatio (qreal delta=0.05) |
| Decrease split ratio by delta. | |
| bool | isFloating (const QString &windowId) const override |
| Check if a window is floating (excluded from tiling) | |
| void | setFloating (const QString &windowId, bool floating) |
| Set a window's floating state. | |
| bool | toggleFloating (const QString &windowId) |
| Toggle a window's floating state. | |
| QStringList | floatingWindows () const override |
| Get list of floating windows. | |
| QStringList | managedWindows () const override |
| All windows managed by this state (tiled + floating). | |
| QString | placementIdForWindow (const QString &windowId) const override |
| Opaque placement identifier for the window's current slot. | |
| QString | focusedWindow () const |
| Get the currently focused window. | |
| void | setFocusedWindow (const QString &windowId) |
| Set the focused window. | |
| int | focusedTiledIndex () const |
| Get index of focused window in tiled list. | |
| bool | floatingHasFocus () const |
| Whether the float layer holds focus right now (derived) | |
| void | clear () |
| Clear all state (remove all windows, reset to defaults) | |
| void | setCalculatedZones (const QVector< QRect > &zones) |
| Store calculated zone geometries. | |
| QVector< QRect > | calculatedZones () const |
| Get stored calculated zone geometries. | |
| SplitTree * | splitTree () const |
| Get the persistent split tree (may be null) | |
| void | setSplitTree (std::unique_ptr< SplitTree > tree) |
| Set or replace the split tree. | |
| void | clearSplitTree () |
| Clear the split tree (e.g., on algorithm switch) | |
| std::unique_ptr< SplitTree > | takeSplitTree () |
| Hand the split tree to the caller, leaving this state without one. | |
| void | rebuildSplitTree () |
| Rebuild the split tree from the current tiled window order. | |
| QJsonObject | scriptState () const |
| Get the persistent per-algorithm script-state bag. | |
| void | setScriptState (const QJsonObject &state) |
| Replace the script-state bag wholesale. | |
| QString | lastTiledFocus () const |
| Layer-side focus memory for switch-focus-between-floating-and-tiling. | |
| QString | lastFloatingFocus () const |
Public Member Functions inherited from PhosphorEngine::IPlacementState | |
| virtual | ~IPlacementState ()=default |
Static Public Member Functions | |
| static QJsonObject | sanitizeScriptState (const QJsonObject &state) |
| Validate and bound a script-written state bag at the trust boundary. | |
Tracks tiling state for a single screen.
TilingState maintains all the mutable state needed for autotiling:
This class is used by AutotileEngine to track state and by TilingAlgorithm implementations to calculate zone geometries.
Note: Window IDs are KWin's internal resource names (QString).
|
explicit |
Construct a TilingState for a specific screen.
| screenId | Unique identifier for the screen |
| parent | Parent QObject |
|
override |
|
delete |
| bool PhosphorTiles::TilingState::addWindow | ( | const QString & | windowId, |
| int | position = -1 |
||
| ) |
Add a window to the tiling.
| windowId | Window identifier |
| position | Insert position (-1 = end, 0 = beginning/master) |
| QVector< QRect > PhosphorTiles::TilingState::calculatedZones | ( | ) | const |
Get stored calculated zone geometries.
| void PhosphorTiles::TilingState::clear | ( | ) |
Clear all state (remove all windows, reset to defaults)
| void PhosphorTiles::TilingState::clearSplitTree | ( | ) |
Clear the split tree (e.g., on algorithm switch)
|
overridevirtual |
Check if a window is tracked.
Implements PhosphorEngine::IPlacementState.
| void PhosphorTiles::TilingState::decreaseSplitRatio | ( | qreal | delta = 0.05 | ) |
Decrease split ratio by delta.
| delta | Amount to decrease (default 0.05) |
|
signal |
Emitted when a window's floating state changes.
| windowId | Affected window |
| floating | New floating state |
| bool PhosphorTiles::TilingState::floatingHasFocus | ( | ) | const |
Whether the float layer holds focus right now (derived)
Derived from m_focusedWindow's membership in the float set rather than stored: autotile funnels every focus report through setFocusedWindow and has no self-activation echo filter swallowing reports, so for focus reports naming windows in THIS state the derivation cannot go stale the way a stored flag could. A state whose screen does not hold focus keeps its last m_focusedWindow by design (nothing clears focus on the losing screen), so the answer is only meaningful on the screen the report came from.
|
overridevirtual |
Get list of floating windows.
Implements PhosphorEngine::IPlacementState.
| int PhosphorTiles::TilingState::focusedTiledIndex | ( | ) | const |
Get index of focused window in tiled list.
| QString PhosphorTiles::TilingState::focusedWindow | ( | ) | const |
Get the currently focused window.
|
signal |
Emitted when focused window changes.
| void PhosphorTiles::TilingState::increaseSplitRatio | ( | qreal | delta = 0.05 | ) |
Increase split ratio by delta.
| delta | Amount to increase (default 0.05) |
| bool PhosphorTiles::TilingState::insertAfterFocused | ( | const QString & | windowId | ) |
Insert a window after the currently focused window.
| windowId | Window to insert |
|
overridevirtual |
Check if a window is floating (excluded from tiling)
Implements PhosphorEngine::IPlacementState.
| bool PhosphorTiles::TilingState::isMaster | ( | const QString & | windowId | ) | const |
Check if a window is in the master area.
| QString PhosphorTiles::TilingState::lastFloatingFocus | ( | ) | const |
| QString PhosphorTiles::TilingState::lastTiledFocus | ( | ) | const |
Layer-side focus memory for switch-focus-between-floating-and-tiling.
m_focusedWindow is a single slot shared by tiles and floats, so a float taking focus erases the answer to "which tile do I return to". These remember the last focus PER LAYER: written by setFocusedWindow (classified against the float set) and by setFloating when the FOCUSED window changes layer with no focus report coming (the layer moved under the focus, mirroring the scroll engine's floatWindowInternal active-tile arm — the new side inherits, the old side drops). A NON-focused window's layer change leaves the memories alone: they are advisory, validated at every read, and retention is what lets engine-internal transient floats (drag-eviction, overflow churn) round-trip without erasing the remembered tile. Cleared when the remembered window leaves the state (removeWindow, clear). Not serialized — focus history dies with the session. Consumers validate before use (the switch verb's eligibility filter), so a stale value is a fallback-scan, never a wrong activation.
|
overridevirtual |
All windows managed by this state (tiled + floating).
Implements PhosphorEngine::IPlacementState.
|
overridevirtual |
Get number of windows in master area.
Reimplemented from PhosphorEngine::IPlacementState.
|
signal |
Emitted when master count changes.
| QStringList PhosphorTiles::TilingState::masterWindows | ( | ) | const |
Get windows currently in master area.
| bool PhosphorTiles::TilingState::moveToFront | ( | const QString & | windowId | ) |
Move a window to the front (alias for promoteToMaster)
| windowId | Window to move |
| bool PhosphorTiles::TilingState::moveToPosition | ( | const QString & | windowId, |
| int | position | ||
| ) |
Move a window to a specific position by its ID.
| windowId | Window to move |
| position | Target position |
| bool PhosphorTiles::TilingState::moveToTiledPosition | ( | const QString & | windowId, |
| int | tiledPosition | ||
| ) |
Move a window to a specific position in the tiled-only list.
| windowId | Window to move |
| tiledPosition | Target position in tiled list (skipping floating) |
| bool PhosphorTiles::TilingState::moveWindow | ( | int | fromIndex, |
| int | toIndex | ||
| ) |
Move a window to a different position.
| fromIndex | Current position |
| toIndex | Target position |
|
delete |
|
overridevirtual |
Opaque placement identifier for the window's current slot.
Snap mode: zone UUID. Autotile mode: tiling-order index as string. Empty if the window is floating or unassigned.
NO in-tree caller today — the three implementations are reached only from their own tests. Kept because it is the one piece of this interface that answers "where is this window" in a form comparable ACROSS modes, which is what a cross-mode restore or a support bundle would need, and each implementation is a handful of lines over state it already holds. Anyone auditing for dead code has now found this note rather than the silence; delete it if the answer is still no consumer.
Implements PhosphorEngine::IPlacementState.
| bool PhosphorTiles::TilingState::promoteToMaster | ( | const QString & | windowId | ) |
Promote a window to master (move to position 0)
| windowId | Window to promote |
| void PhosphorTiles::TilingState::rebuildSplitTree | ( | ) |
Rebuild the split tree from the current tiled window order.
Used after operations that reorder windows (move, promote, rotate) to preserve the tree's existence while matching the new order. Split ratios are preserved positionally where possible, so DwindleMemoryAlgorithm doesn't fall back to stateless mode.
| bool PhosphorTiles::TilingState::removeWindow | ( | const QString & | windowId | ) |
Remove a window from the tiling.
| windowId | Window to remove |
| bool PhosphorTiles::TilingState::rotateWindows | ( | bool | clockwise = true | ) |
Rotate all windows by one position.
Clockwise: each window moves to the next position, last becomes first Counterclockwise: each window moves to the previous position, first becomes last
| clockwise | Direction of rotation |
|
static |
Validate and bound a script-written state bag at the trust boundary.
Enforces the AutotileDefaults::ScriptState* limits (compact-JSON byte cap, nesting depth, total key count) and strips non-finite numbers. Returns the sanitized object, or an empty object if the bag exceeds the byte cap and can't be safely stored. Applied on the scripted-algorithm write-back path, which is the only place an UNTRUSTED bag originates. The engine's stash hands back a bag that went through here on its way in.
|
overridevirtual |
Get the screen ID this state belongs to.
Implements PhosphorEngine::IPlacementState.
| QJsonObject PhosphorTiles::TilingState::scriptState | ( | ) | const |
Get the persistent per-algorithm script-state bag.
An opaque JSON object that scripted algorithms read (exposed as ctx.state) and write back (via the onWindowResized hook return) to remember layout adjustments — e.g. an aligned grid's column widths — across retiles. Empty by default. The engine never interprets it.
| void PhosphorTiles::TilingState::setCalculatedZones | ( | const QVector< QRect > & | zones | ) |
Store calculated zone geometries.
Called by AutotileEngine after algorithm computes zones. Stored for later application to windows.
| zones | Calculated zone geometries (one per tiled window) |
| void PhosphorTiles::TilingState::setFloating | ( | const QString & | windowId, |
| bool | floating | ||
| ) |
Set a window's floating state.
| windowId | Window to modify |
| floating | true to exclude from tiling |
| void PhosphorTiles::TilingState::setFocusedWindow | ( | const QString & | windowId | ) |
Set the focused window.
| windowId | Window that received focus |
| void PhosphorTiles::TilingState::setMasterCount | ( | int | count | ) |
Set number of windows in master area.
| count | New master count (clamped to AutotileDefaults:: MinMasterCount..MaxMasterCount; algorithms clamp operationally against the window count) |
| void PhosphorTiles::TilingState::setScriptState | ( | const QJsonObject & | state | ) |
Replace the script-state bag wholesale.
Callers must pass already-sanitized JSON (see sanitizeScriptState in tilingstatedata.cpp). No NOTIFY signal: this is internal state, not a UI-observable property, and writing it must never schedule a retile (that would risk a resize→retile→resize loop).
| void PhosphorTiles::TilingState::setSplitRatio | ( | qreal | ratio | ) |
Set the master/stack split ratio.
| ratio | New ratio (clamped to 0.1..0.9) |
| void PhosphorTiles::TilingState::setSplitTree | ( | std::unique_ptr< SplitTree > | tree | ) |
Set or replace the split tree.
| tree | Ownership transferred to TilingState |
| qreal PhosphorTiles::TilingState::splitRatio | ( | ) | const |
Get the master/stack split ratio.
|
signal |
Emitted when split ratio changes.
| SplitTree * PhosphorTiles::TilingState::splitTree | ( | ) | const |
Get the persistent split tree (may be null)
Used by DwindleMemoryAlgorithm to read the tree structure. Returns nullptr if no split tree has been created for this state.
| QStringList PhosphorTiles::TilingState::stackWindows | ( | ) | const |
Get windows currently in stack area.
|
signal |
Emitted when any state change requires retiling.
| bool PhosphorTiles::TilingState::swapWindows | ( | int | index1, |
| int | index2 | ||
| ) |
Swap two windows' positions.
| index1 | First window position |
| index2 | Second window position |
| bool PhosphorTiles::TilingState::swapWindowsById | ( | const QString & | windowId1, |
| const QString & | windowId2 | ||
| ) |
Swap two windows by their IDs.
| windowId1 | First window ID |
| windowId2 | Second window ID |
| std::unique_ptr< SplitTree > PhosphorTiles::TilingState::takeSplitTree | ( | ) |
Hand the split tree to the caller, leaving this state without one.
For rescuing a tree out of a state that is about to be destroyed. Returns null when there is no tree. Unlike splitTree() this transfers ownership, so the tree outlives the state rather than being serialized to survive it.
|
overridevirtual |
Get number of tiled windows (excluding floating)
Reimplemented from PhosphorEngine::IPlacementState.
| int PhosphorTiles::TilingState::tiledWindowIndex | ( | const QString & | windowId | ) | const |
Get the index of a window within the tiled-only list.
| windowId | Window to find |
| QStringList PhosphorTiles::TilingState::tiledWindows | ( | ) | const |
Get only tiled (non-floating) windows in order.
| bool PhosphorTiles::TilingState::toggleFloating | ( | const QString & | windowId | ) |
Toggle a window's floating state.
| windowId | Window to toggle |
|
overridevirtual |
Get total number of tracked windows (including floating)
Implements PhosphorEngine::IPlacementState.
|
signal |
Emitted when window count changes (add/remove)
| int PhosphorTiles::TilingState::windowIndex | ( | const QString & | windowId | ) | const |
Get the index of a window.
| windowId | Window to find |
| QStringList PhosphorTiles::TilingState::windowOrder | ( | ) | const |
Get the ordered list of window IDs.
|
signal |
Emitted when window order changes (move/swap)
| int PhosphorTiles::TilingState::windowPosition | ( | const QString & | windowId | ) | const |
Get the position of a window (alias for windowIndex)
| windowId | Window to find |