Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
PhosphorTiles::TilingState Class Reference

Tracks tiling state for a single screen. More...

#include <phosphor-tiles/include/PhosphorTiles/TilingState.h>

Inheritance diagram for PhosphorTiles::TilingState:
[legend]

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
 
TilingStateoperator= (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.
 
QJsonObject toJson () const override
 Serialize state to JSON.
 
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.
 
SplitTreesplitTree () 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)
 
void rebuildSplitTree ()
 Rebuild the split tree from the current tiled window order.
 
- Public Member Functions inherited from PhosphorEngine::IPlacementState
virtual ~IPlacementState ()=default
 

Static Public Member Functions

static TilingStatefromJson (const QJsonObject &json, QObject *parent=nullptr)
 Deserialize state from JSON.
 

Detailed Description

Tracks tiling state for a single screen.

TilingState maintains all the mutable state needed for autotiling:

  • Window order (insertion order determines tiling position)
  • Master window count (how many windows in master area)
  • Split ratio (master vs stack area ratio)
  • Per-window floating state (excluded from tiling)

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).

Constructor & Destructor Documentation

◆ TilingState() [1/2]

PhosphorTiles::TilingState::TilingState ( const QString &  screenId,
QObject *  parent = nullptr 
)
explicit

Construct a TilingState for a specific screen.

Parameters
screenIdUnique identifier for the screen
parentParent QObject

◆ ~TilingState()

PhosphorTiles::TilingState::~TilingState ( )
override

◆ TilingState() [2/2]

PhosphorTiles::TilingState::TilingState ( const TilingState )
delete

Member Function Documentation

◆ addWindow()

bool PhosphorTiles::TilingState::addWindow ( const QString &  windowId,
int  position = -1 
)

Add a window to the tiling.

Parameters
windowIdWindow identifier
positionInsert position (-1 = end, 0 = beginning/master)
Returns
true if window was added, false if already tracked or invalid

◆ calculatedZones()

QVector< QRect > PhosphorTiles::TilingState::calculatedZones ( ) const

Get stored calculated zone geometries.

Returns
Zone geometries from last calculation

◆ clear()

void PhosphorTiles::TilingState::clear ( )

Clear all state (remove all windows, reset to defaults)

◆ clearSplitTree()

void PhosphorTiles::TilingState::clearSplitTree ( )

Clear the split tree (e.g., on algorithm switch)

◆ containsWindow()

bool PhosphorTiles::TilingState::containsWindow ( const QString &  windowId) const
overridevirtual

Check if a window is tracked.

Implements PhosphorEngine::IPlacementState.

◆ decreaseSplitRatio()

void PhosphorTiles::TilingState::decreaseSplitRatio ( qreal  delta = 0.05)

Decrease split ratio by delta.

Parameters
deltaAmount to decrease (default 0.05)

◆ floatingChanged

void PhosphorTiles::TilingState::floatingChanged ( const QString &  windowId,
bool  floating 
)
signal

Emitted when a window's floating state changes.

Parameters
windowIdAffected window
floatingNew floating state
Note
Also emitted with floating=false when a floating window is removed via removeWindow(), to ensure listeners clean up any floating-specific state. Check containsWindow() if needed.

◆ floatingWindows()

QStringList PhosphorTiles::TilingState::floatingWindows ( ) const
overridevirtual

Get list of floating windows.

Implements PhosphorEngine::IPlacementState.

◆ focusedTiledIndex()

int PhosphorTiles::TilingState::focusedTiledIndex ( ) const

Get index of focused window in tiled list.

Returns
Index or -1 if no focused window

◆ focusedWindow()

QString PhosphorTiles::TilingState::focusedWindow ( ) const

Get the currently focused window.

◆ focusedWindowChanged

void PhosphorTiles::TilingState::focusedWindowChanged ( )
signal

Emitted when focused window changes.

◆ fromJson()

static TilingState * PhosphorTiles::TilingState::fromJson ( const QJsonObject &  json,
QObject *  parent = nullptr 
)
static

Deserialize state from JSON.

Parameters
jsonSerialized state
parentParent QObject
Returns
New TilingState or nullptr on error

Ownership: caller takes ownership (Qt parent set if provided)

◆ increaseSplitRatio()

void PhosphorTiles::TilingState::increaseSplitRatio ( qreal  delta = 0.05)

Increase split ratio by delta.

Parameters
deltaAmount to increase (default 0.05)

◆ insertAfterFocused()

bool PhosphorTiles::TilingState::insertAfterFocused ( const QString &  windowId)

Insert a window after the currently focused window.

Parameters
windowIdWindow to insert
Returns
true if inserted successfully

◆ isFloating()

bool PhosphorTiles::TilingState::isFloating ( const QString &  windowId) const
overridevirtual

Check if a window is floating (excluded from tiling)

Implements PhosphorEngine::IPlacementState.

◆ isMaster()

bool PhosphorTiles::TilingState::isMaster ( const QString &  windowId) const

Check if a window is in the master area.

◆ managedWindows()

QStringList PhosphorTiles::TilingState::managedWindows ( ) const
overridevirtual

All windows managed by this state (tiled + floating).

Implements PhosphorEngine::IPlacementState.

◆ masterCount()

int PhosphorTiles::TilingState::masterCount ( ) const
overridevirtual

Get number of windows in master area.

Reimplemented from PhosphorEngine::IPlacementState.

◆ masterCountChanged

void PhosphorTiles::TilingState::masterCountChanged ( )
signal

Emitted when master count changes.

◆ masterWindows()

QStringList PhosphorTiles::TilingState::masterWindows ( ) const

Get windows currently in master area.

◆ moveToFront()

bool PhosphorTiles::TilingState::moveToFront ( const QString &  windowId)

Move a window to the front (alias for promoteToMaster)

Parameters
windowIdWindow to move
Returns
true if window found and moved

◆ moveToPosition()

bool PhosphorTiles::TilingState::moveToPosition ( const QString &  windowId,
int  position 
)

Move a window to a specific position by its ID.

Parameters
windowIdWindow to move
positionTarget position
Returns
true if move was successful

◆ moveToTiledPosition()

bool PhosphorTiles::TilingState::moveToTiledPosition ( const QString &  windowId,
int  tiledPosition 
)

Move a window to a specific position in the tiled-only list.

Parameters
windowIdWindow to move
tiledPositionTarget position in tiled list (skipping floating)
Returns
true if move was successful

◆ moveWindow()

bool PhosphorTiles::TilingState::moveWindow ( int  fromIndex,
int  toIndex 
)

Move a window to a different position.

Parameters
fromIndexCurrent position
toIndexTarget position
Returns
true if move was successful

◆ operator=()

TilingState & PhosphorTiles::TilingState::operator= ( const TilingState )
delete

◆ placementIdForWindow()

QString PhosphorTiles::TilingState::placementIdForWindow ( const QString &  windowId) const
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.

Implements PhosphorEngine::IPlacementState.

◆ promoteToMaster()

bool PhosphorTiles::TilingState::promoteToMaster ( const QString &  windowId)

Promote a window to master (move to position 0)

Parameters
windowIdWindow to promote
Returns
true if window found and promoted

◆ rebuildSplitTree()

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.

◆ removeWindow()

bool PhosphorTiles::TilingState::removeWindow ( const QString &  windowId)

Remove a window from the tiling.

Parameters
windowIdWindow to remove
Returns
true if window was found and removed

◆ rotateWindows()

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

Parameters
clockwiseDirection of rotation
Returns
true if rotation was performed (at least 2 windows)

◆ screenId()

QString PhosphorTiles::TilingState::screenId ( ) const
overridevirtual

Get the screen ID this state belongs to.

Implements PhosphorEngine::IPlacementState.

◆ setCalculatedZones()

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.

Parameters
zonesCalculated zone geometries (one per tiled window)

◆ setFloating()

void PhosphorTiles::TilingState::setFloating ( const QString &  windowId,
bool  floating 
)

Set a window's floating state.

Parameters
windowIdWindow to modify
floatingtrue to exclude from tiling

◆ setFocusedWindow()

void PhosphorTiles::TilingState::setFocusedWindow ( const QString &  windowId)

Set the focused window.

Parameters
windowIdWindow that received focus

◆ setMasterCount()

void PhosphorTiles::TilingState::setMasterCount ( int  count)

Set number of windows in master area.

Parameters
countNew master count (clamped to 1..windowCount)

◆ setSplitRatio()

void PhosphorTiles::TilingState::setSplitRatio ( qreal  ratio)

Set the master/stack split ratio.

Parameters
ratioNew ratio (clamped to 0.1..0.9)

◆ setSplitTree()

void PhosphorTiles::TilingState::setSplitTree ( std::unique_ptr< SplitTree tree)

Set or replace the split tree.

Parameters
treeOwnership transferred to TilingState

◆ splitRatio()

qreal PhosphorTiles::TilingState::splitRatio ( ) const

Get the master/stack split ratio.

Returns
Ratio where 0.6 = master gets 60% of width

◆ splitRatioChanged

void PhosphorTiles::TilingState::splitRatioChanged ( )
signal

Emitted when split ratio changes.

◆ splitTree()

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.

◆ stackWindows()

QStringList PhosphorTiles::TilingState::stackWindows ( ) const

Get windows currently in stack area.

◆ stateChanged

void PhosphorTiles::TilingState::stateChanged ( )
signal

Emitted when any state change requires retiling.

◆ swapWindows()

bool PhosphorTiles::TilingState::swapWindows ( int  index1,
int  index2 
)

Swap two windows' positions.

Parameters
index1First window position
index2Second window position
Returns
true if swap was successful

◆ swapWindowsById()

bool PhosphorTiles::TilingState::swapWindowsById ( const QString &  windowId1,
const QString &  windowId2 
)

Swap two windows by their IDs.

Parameters
windowId1First window ID
windowId2Second window ID
Returns
true if both windows found and swapped

◆ tiledWindowCount()

int PhosphorTiles::TilingState::tiledWindowCount ( ) const
overridevirtual

Get number of tiled windows (excluding floating)

Reimplemented from PhosphorEngine::IPlacementState.

◆ tiledWindowIndex()

int PhosphorTiles::TilingState::tiledWindowIndex ( const QString &  windowId) const

Get the index of a window within the tiled-only list.

Parameters
windowIdWindow to find
Returns
Index in tiled window list (skipping floating), or -1 if not found

◆ tiledWindows()

QStringList PhosphorTiles::TilingState::tiledWindows ( ) const

Get only tiled (non-floating) windows in order.

◆ toggleFloating()

bool PhosphorTiles::TilingState::toggleFloating ( const QString &  windowId)

Toggle a window's floating state.

Parameters
windowIdWindow to toggle
Returns
Current floating state after toggle (unchanged if window not tracked)

◆ toJson()

QJsonObject PhosphorTiles::TilingState::toJson ( ) const
overridevirtual

Serialize state to JSON.

Implements PhosphorEngine::IPlacementState.

◆ windowCount()

int PhosphorTiles::TilingState::windowCount ( ) const
overridevirtual

Get total number of tracked windows (including floating)

Implements PhosphorEngine::IPlacementState.

◆ windowCountChanged

void PhosphorTiles::TilingState::windowCountChanged ( )
signal

Emitted when window count changes (add/remove)

◆ windowIndex()

int PhosphorTiles::TilingState::windowIndex ( const QString &  windowId) const

Get the index of a window.

Parameters
windowIdWindow to find
Returns
Index in window order, or -1 if not found

◆ windowOrder()

QStringList PhosphorTiles::TilingState::windowOrder ( ) const

Get the ordered list of window IDs.

Returns
Window IDs in tiling order (first = master, rest = stack)

◆ windowOrderChanged

void PhosphorTiles::TilingState::windowOrderChanged ( )
signal

Emitted when window order changes (move/swap)

◆ windowPosition()

int PhosphorTiles::TilingState::windowPosition ( const QString &  windowId) const

Get the position of a window (alias for windowIndex)

Parameters
windowIdWindow to find
Returns
Position in tiled list, or -1 if not found

The documentation for this class was generated from the following file: