Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
GeometryUtils.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <phosphorgeometry_export.h>
7
8#include <QRect>
9#include <QRectF>
10#include <QSize>
11#include <QString>
12#include <QVector>
13
15
16namespace GeometryDefaults {
17inline constexpr int MinRectSizePx = 50;
18} // namespace GeometryDefaults
19
20PHOSPHORGEOMETRY_EXPORT QRectF availableAreaToOverlayCoordinates(const QRectF& geometry, const QRect& overlayGeometry);
21
22PHOSPHORGEOMETRY_EXPORT QRect snapToRect(const QRectF& rf);
23
24// Grows zones to accommodate per-window minimum sizes by stealing surplus
25// from adjacent neighbors, then resolves any residual overlap.
26//
27// Vector tolerance (matches clampZonesToScreen): if minSizes is shorter than
28// zones, missing entries are treated as no minimum (zero size). Extra entries
29// past zones.size() are ignored. Empty minSizes is a no-op (nothing to enforce);
30// empty zones is also a no-op.
31PHOSPHORGEOMETRY_EXPORT void enforceMinSizes(QVector<QRect>& zones, const QVector<QSize>& minSizes, int gapThreshold,
32 int innerGap = 0);
33
34// Position-only bounds clamp. Shifts each zone so its effective rect (max of
35// the zone's own size and the corresponding window's declared minSize) stays
36// inside the screen. Sizes are preserved; only x/y move. Pass an empty or
37// zero-filled minSizes vector to clamp purely against the zone's own size —
38// unlike enforceMinSizes, an empty minSizes does NOT short-circuit the
39// function: the zone's own dimensions are still clamped against the screen.
40//
41// Vector tolerance (matches enforceMinSizes): if minSizes is shorter
42// than zones, missing entries are treated as no minimum (zero size). Extra
43// entries past zones.size() are ignored. Empty zones is a no-op; an invalid
44// screen (default-constructed QRect) is a no-op.
45//
46// Why position-only: this runs after enforceMinSizes, which is the only
47// path allowed to grow/shrink zones. For any algorithm where
48// producesOverlappingZones() is true (Deck, Stair, Cascade, Monocle, Paper,
49// Spread, horizontal-deck — and any future algo opting in)
50// enforceMinSizes is skipped because neighbor-stealing would destroy
51// intentional overlap; a pure position shift is the only safe correction in
52// that case. For non-overlapping algorithms a remaining overflow means the
53// constraint solver couldn't satisfy the layout — shifting accepts that
54// compromise rather than letting the window be pushed onto an adjacent
55// monitor by the compositor's min-size enforcement.
56PHOSPHORGEOMETRY_EXPORT void clampZonesToScreen(QVector<QRect>& zones, const QVector<QSize>& minSizes,
57 const QRect& screen);
58
59PHOSPHORGEOMETRY_EXPORT void removeRectOverlaps(QVector<QRect>& zones, const QVector<QSize>& minSizes = {},
60 int innerGap = 0);
61
62PHOSPHORGEOMETRY_EXPORT QString rectToJson(const QRect& rect);
63
64} // namespace PhosphorGeometry
constexpr int MinRectSizePx
Definition GeometryUtils.h:17
Definition GeometryUtils.h:14
PHOSPHORGEOMETRY_EXPORT QString rectToJson(const QRect &rect)
PHOSPHORGEOMETRY_EXPORT void enforceMinSizes(QVector< QRect > &zones, const QVector< QSize > &minSizes, int gapThreshold, int innerGap=0)
PHOSPHORGEOMETRY_EXPORT void removeRectOverlaps(QVector< QRect > &zones, const QVector< QSize > &minSizes={}, int innerGap=0)
PHOSPHORGEOMETRY_EXPORT QRectF availableAreaToOverlayCoordinates(const QRectF &geometry, const QRect &overlayGeometry)
PHOSPHORGEOMETRY_EXPORT void clampZonesToScreen(QVector< QRect > &zones, const QVector< QSize > &minSizes, const QRect &screen)