Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
PhosphorGeometry Namespace Reference

Namespaces

namespace  GeometryDefaults
 
namespace  JsonKeys
 

Enumerations

enum class  Direction { Left , Right , Up , Down }
 Cardinal navigation direction in screen space (y grows downward). More...
 

Functions

PHOSPHORGEOMETRY_EXPORT std::optional< DirectiondirectionFromString (QStringView token)
 Parse a lower-case direction token ("left"/"right"/"up"/"down") into a Direction.
 
constexpr Direction opposite (Direction direction)
 The reverse of direction.
 
PHOSPHORGEOMETRY_EXPORT int edgeMostRect (const QList< QRectF > &candidates, Direction edge)
 Index of the candidate whose edge-facing side is most extreme toward that edge.
 
PHOSPHORGEOMETRY_EXPORT int directionalNeighbor (const QRectF &focus, const QList< QRectF > &candidates, Direction direction, bool requireOverlap=false)
 Pick the spatial neighbour of focus among candidates in direction.
 
PHOSPHORGEOMETRY_EXPORT int neighborDesktopInDirection (int currentDesktop, int desktopCount, int rows, Direction direction)
 The virtual desktop reached by stepping direction from currentDesktop on a rows-high desktop grid.
 
PHOSPHORGEOMETRY_EXPORT QRectF availableAreaToOverlayCoordinates (const QRectF &geometry, const QRect &overlayGeometry)
 
PHOSPHORGEOMETRY_EXPORT QRect snapToRect (const QRectF &rf)
 
PHOSPHORGEOMETRY_EXPORT void enforceMinSizes (QVector< QRect > &zones, const QVector< QSize > &minSizes, int gapThreshold, int innerGap=0)
 
PHOSPHORGEOMETRY_EXPORT void clampZonesToScreen (QVector< QRect > &zones, const QVector< QSize > &minSizes, const QRect &screen)
 
PHOSPHORGEOMETRY_EXPORT void removeRectOverlaps (QVector< QRect > &zones, const QVector< QSize > &minSizes={}, int innerGap=0)
 
PHOSPHORGEOMETRY_EXPORT QString rectToJson (const QRect &rect)
 
PHOSPHORGEOMETRY_EXPORT QRect insetRect (const QRect &rect, int inset)
 

Enumeration Type Documentation

◆ Direction

enum class PhosphorGeometry::Direction
strong

Cardinal navigation direction in screen space (y grows downward).

Enumerator
Left 
Right 
Up 
Down 

Function Documentation

◆ availableAreaToOverlayCoordinates()

PHOSPHORGEOMETRY_EXPORT QRectF PhosphorGeometry::availableAreaToOverlayCoordinates ( const QRectF &  geometry,
const QRect &  overlayGeometry 
)

◆ clampZonesToScreen()

PHOSPHORGEOMETRY_EXPORT void PhosphorGeometry::clampZonesToScreen ( QVector< QRect > &  zones,
const QVector< QSize > &  minSizes,
const QRect &  screen 
)

◆ directionalNeighbor()

PHOSPHORGEOMETRY_EXPORT int PhosphorGeometry::directionalNeighbor ( const QRectF &  focus,
const QList< QRectF > &  candidates,
Direction  direction,
bool  requireOverlap = false 
)

Pick the spatial neighbour of focus among candidates in direction.

Selection, in priority order:

  1. In-direction filter — a candidate qualifies only if it lies on the direction side of focus (its centre is past focus's centre on the travel axis).
  2. Perpendicular-overlap preference — qualifying candidates whose span on the axis orthogonal to travel overlaps focus's span (genuinely side-by-side) beat any candidate that does not overlap. This is what makes "right" from a top-left tile pick the top-right tile, never the bottom-right one, regardless of insertion order.
  3. Nearest along the travel axis — within the preferred tier, the smallest edge gap toward direction wins.
  4. Perpendicular-centre tie-break — equal gaps break by the smaller orthogonal centre distance.
  5. Travel-axis-centre tie-break — equal gaps AND equal perpendicular distances break by the smaller centre distance along the travel axis. A stack of mutually overlapping zones all clamps to edge gap zero, so this tier is what makes such stacks step to the nearest zone one at a time in BOTH directions instead of resolving by candidate order. The result is deterministic for a given candidate list; two candidates identical on every tier resolve to the lower index.

Coordinate-system agnostic: focus and every entry of candidates must live in one shared space (absolute pixels, normalized [0,1], etc.).

Parameters
requireOverlapwhen true, candidates that do not overlap focus on the perpendicular axis (i.e. purely diagonal ones) are rejected outright rather than used as a last-resort fallback. Window navigation wants this: a diagonal tile is not a real left/right/up/down neighbour, so the move should hit the layout boundary (and cross to the next output) instead of swapping with a window that's offset away. Cross-output move-picking wants it too: a side-by-side monitor whose centre sits below the source must not resolve as the "down" output. All other callers leave it false (default) so an offset-but-present neighbour still resolves: zone adjacency and virtual-screen swap target whatever occupies that direction, diagonal or not, and the cross-output entry-window pick wants a best-effort landing target rather than an arbitrary fallback.
Returns
index into candidates, or -1 when no candidate lies in direction. Candidates sharing focus's centre are skipped.

◆ directionFromString()

PHOSPHORGEOMETRY_EXPORT std::optional< Direction > PhosphorGeometry::directionFromString ( QStringView  token)

Parse a lower-case direction token ("left"/"right"/"up"/"down") into a Direction.

Returns std::nullopt for any other token so callers reject unknown input rather than silently defaulting to a cardinal direction.

◆ edgeMostRect()

PHOSPHORGEOMETRY_EXPORT int PhosphorGeometry::edgeMostRect ( const QList< QRectF > &  candidates,
Direction  edge 
)

Index of the candidate whose edge-facing side is most extreme toward that edge.

Ranks by the EDGE coordinate, not the rect origin: Left → smallest left(), Right → largest right(), Up → smallest top(), Down → largest bottom(), so with unequal-sized candidates the rect actually touching (or reaching furthest toward) that side wins. Rects tying on the edge break by the FAR side nearest the edge — a tile confined to the edge beats one merely spanning to it (in a master-stack layout, an "up" crossing enters the bottom stack tile, not the full-height master that also touches the bottom edge). Remaining ties resolve to the lowest index. This is the shared cross-output "entry" pick — the first zone / entry tile on the edge a crossing arrives at. Both engines feed it the ENTRY edge: autotile flips the travel direction via opposite() at its call site, snap's caller flips one layer up (oppositeCrossingDirection) before the direction token reaches the zone adaptor.

Returns
index into candidates, or -1 when the list is empty.

◆ enforceMinSizes()

PHOSPHORGEOMETRY_EXPORT void PhosphorGeometry::enforceMinSizes ( QVector< QRect > &  zones,
const QVector< QSize > &  minSizes,
int  gapThreshold,
int  innerGap = 0 
)

◆ insetRect()

PHOSPHORGEOMETRY_EXPORT QRect PhosphorGeometry::insetRect ( const QRect &  rect,
int  inset 
)

◆ neighborDesktopInDirection()

PHOSPHORGEOMETRY_EXPORT int PhosphorGeometry::neighborDesktopInDirection ( int  currentDesktop,
int  desktopCount,
int  rows,
Direction  direction 
)

The virtual desktop reached by stepping direction from currentDesktop on a rows-high desktop grid.

Desktops are 1-based and laid out row-major across ceil(desktopCount/rows) columns, matching KWin's DEFAULT (horizontal-fill) desktop-grid layout. KWin can also be configured to fill the grid column-first; that orientation is not expressible through rows alone and is not modelled here — under it the Up/Down vs Left/Right mapping would differ. A step that leaves the grid — past an edge, into a missing cell on a partial last row, or a horizontal move that would wrap onto another row — returns 0 (no neighbour) rather than wrapping, so callers can treat 0 as "no desktop that way; try another axis".

Parameters
rowsgrid height; values < 1 are clamped to 1 (a single-row grid).
Returns
the 1-based target desktop, or 0 when there is no neighbour in direction (including for out-of-range inputs).

◆ opposite()

constexpr Direction PhosphorGeometry::opposite ( Direction  direction)
constexpr

The reverse of direction.

A crossing travelling direction enters the target surface at its opposite edge (moving "right" lands on the neighbour's LEFT edge), so cross-output entry pickers pair this with edgeMostRect().

◆ rectToJson()

PHOSPHORGEOMETRY_EXPORT QString PhosphorGeometry::rectToJson ( const QRect &  rect)

◆ removeRectOverlaps()

PHOSPHORGEOMETRY_EXPORT void PhosphorGeometry::removeRectOverlaps ( QVector< QRect > &  zones,
const QVector< QSize > &  minSizes = {},
int  innerGap = 0 
)

◆ snapToRect()

PHOSPHORGEOMETRY_EXPORT QRect PhosphorGeometry::snapToRect ( const QRectF &  rf)