1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <unbox/ext-layer-shell/arrangement.hpp>
using unbox::ext_layer_shell::apply_exclusive;
using unbox::ext_layer_shell::Box;
using unbox::ext_layer_shell::Edge;
using unbox::ext_layer_shell::exclusive_edge;
using unbox::ext_layer_shell::SurfaceState;
namespace anchor = unbox::ext_layer_shell::anchor;
namespace {
// A 1920x1080 output at the layout origin, the canonical test stage.
constexpr Box kOutput{0, 0, 1920, 1080};
// Anchor a strip to a single edge plus both perpendicular edges (the common
// full-width panel anchoring).
constexpr std::uint32_t kTopStrip = anchor::top | anchor::left | anchor::right;
constexpr std::uint32_t kBottomStrip = anchor::bottom | anchor::left | anchor::right;
constexpr std::uint32_t kLeftStrip = anchor::left | anchor::top | anchor::bottom;
constexpr std::uint32_t kRightStrip = anchor::right | anchor::top | anchor::bottom;
} // namespace
// ---- exclusive_edge: anchoring -> reserved edge -----------------------------
TEST_CASE("non-positive exclusive zone reserves nothing") {
CHECK(exclusive_edge({.anchor = kTopStrip, .exclusive_zone = 0}) == Edge::none);
CHECK(exclusive_edge({.anchor = kTopStrip, .exclusive_zone = -1}) == Edge::none);
}
TEST_CASE("a full-width top strip reserves the top edge") {
CHECK(exclusive_edge({.anchor = kTopStrip, .exclusive_zone = 30}) == Edge::top);
}
TEST_CASE("each single-edge strip deduces its own edge") {
CHECK(exclusive_edge({.anchor = kTopStrip, .exclusive_zone = 1}) == Edge::top);
CHECK(exclusive_edge({.anchor = kBottomStrip, .exclusive_zone = 1}) == Edge::bottom);
CHECK(exclusive_edge({.anchor = kLeftStrip, .exclusive_zone = 1}) == Edge::left);
CHECK(exclusive_edge({.anchor = kRightStrip, .exclusive_zone = 1}) == Edge::right);
}
TEST_CASE("anchoring to a single bare edge reserves that edge") {
// Anchored only to top (no perpendicular edges) is still a meaningful strip.
CHECK(exclusive_edge({.anchor = anchor::top, .exclusive_zone = 5}) == Edge::top);
CHECK(exclusive_edge({.anchor = anchor::left, .exclusive_zone = 5}) == Edge::left);
}
TEST_CASE("anchoring to a bare corner reserves nothing (protocol rule)") {
CHECK(exclusive_edge({.anchor = anchor::top | anchor::left, .exclusive_zone = 9}) ==
Edge::none);
CHECK(exclusive_edge({.anchor = anchor::bottom | anchor::right, .exclusive_zone = 9}) ==
Edge::none);
}
TEST_CASE("anchoring to two PARALLEL edges reserves nothing") {
CHECK(exclusive_edge({.anchor = anchor::top | anchor::bottom, .exclusive_zone = 9}) ==
Edge::none);
CHECK(exclusive_edge({.anchor = anchor::left | anchor::right, .exclusive_zone = 9}) ==
Edge::none);
}
TEST_CASE("anchoring to all four edges reserves nothing") {
const std::uint32_t all = anchor::top | anchor::bottom | anchor::left | anchor::right;
CHECK(exclusive_edge({.anchor = all, .exclusive_zone = 9}) == Edge::none);
}
TEST_CASE("unanchored surface reserves nothing even with positive zone") {
CHECK(exclusive_edge({.anchor = 0, .exclusive_zone = 9}) == Edge::none);
}
// ---- exclusive_edge: explicit override (v5) ---------------------------------
TEST_CASE("explicit exclusive_edge disambiguates a corner anchor") {
// Bottom-right corner: ambiguous by deduction, but an explicit edge the
// surface is anchored to resolves it.
SurfaceState s{.anchor = anchor::bottom | anchor::right,
.exclusive_zone = 12,
.exclusive_edge = Edge::bottom};
CHECK(exclusive_edge(s) == Edge::bottom);
s.exclusive_edge = Edge::right;
CHECK(exclusive_edge(s) == Edge::right);
}
TEST_CASE("explicit exclusive_edge not among anchored edges is ignored") {
// Anchored top-left only; asking to reserve the bottom edge is invalid.
SurfaceState s{.anchor = anchor::top | anchor::left,
.exclusive_zone = 12,
.exclusive_edge = Edge::bottom};
CHECK(exclusive_edge(s) == Edge::none);
}
// ---- apply_exclusive: single surface ----------------------------------------
TEST_CASE("a non-reserving surface leaves the usable area untouched") {
const SurfaceState s{.anchor = kTopStrip, .exclusive_zone = 0};
CHECK(apply_exclusive(kOutput, s) == kOutput);
}
TEST_CASE("a top panel shrinks the usable area from the top") {
const SurfaceState s{.anchor = kTopStrip, .exclusive_zone = 30};
CHECK(apply_exclusive(kOutput, s) == Box{0, 30, 1920, 1050});
}
TEST_CASE("a bottom panel shrinks height but not the origin") {
const SurfaceState s{.anchor = kBottomStrip, .exclusive_zone = 40};
CHECK(apply_exclusive(kOutput, s) == Box{0, 0, 1920, 1040});
}
TEST_CASE("a left bar shifts x and shrinks width") {
const SurfaceState s{.anchor = kLeftStrip, .exclusive_zone = 50};
CHECK(apply_exclusive(kOutput, s) == Box{50, 0, 1870, 1080});
}
TEST_CASE("a right bar shrinks width but not the origin") {
const SurfaceState s{.anchor = kRightStrip, .exclusive_zone = 60};
CHECK(apply_exclusive(kOutput, s) == Box{0, 0, 1860, 1080});
}
TEST_CASE("the margin on the reserved edge adds to the reserved space") {
// Top panel with a 30px zone and a 10px top margin reserves 40px.
const SurfaceState s{
.anchor = kTopStrip, .exclusive_zone = 30, .margin_top = 10};
CHECK(apply_exclusive(kOutput, s) == Box{0, 40, 1920, 1040});
}
TEST_CASE("margins on non-reserved edges do not affect the usable area") {
const SurfaceState s{.anchor = kTopStrip,
.exclusive_zone = 30,
.margin_right = 100,
.margin_bottom = 100,
.margin_left = 100};
CHECK(apply_exclusive(kOutput, s) == Box{0, 30, 1920, 1050});
}
// ---- apply_exclusive: stacking several surfaces -----------------------------
TEST_CASE("two perpendicular panels stack into a corner-reduced area") {
Box usable = kOutput;
usable = apply_exclusive(usable, {.anchor = kTopStrip, .exclusive_zone = 30});
usable = apply_exclusive(usable, {.anchor = kLeftStrip, .exclusive_zone = 50});
CHECK(usable == Box{50, 30, 1870, 1050});
}
TEST_CASE("two opposite panels reduce both ends of an axis") {
Box usable = kOutput;
usable = apply_exclusive(usable, {.anchor = kTopStrip, .exclusive_zone = 30});
usable = apply_exclusive(usable, {.anchor = kBottomStrip, .exclusive_zone = 40});
CHECK(usable == Box{0, 30, 1920, 1010});
}
TEST_CASE("four panels box in the usable area on every side") {
Box usable = kOutput;
usable = apply_exclusive(usable, {.anchor = kTopStrip, .exclusive_zone = 24});
usable = apply_exclusive(usable, {.anchor = kBottomStrip, .exclusive_zone = 24});
usable = apply_exclusive(usable, {.anchor = kLeftStrip, .exclusive_zone = 48});
usable = apply_exclusive(usable, {.anchor = kRightStrip, .exclusive_zone = 48});
CHECK(usable == Box{48, 24, 1824, 1032});
}
TEST_CASE("two stacked top panels each carve from the running usable area") {
Box usable = kOutput;
usable = apply_exclusive(usable, {.anchor = kTopStrip, .exclusive_zone = 30});
usable = apply_exclusive(usable, {.anchor = kTopStrip, .exclusive_zone = 20});
// Origin pushed down twice; height reduced by the sum.
CHECK(usable == Box{0, 50, 1920, 1030});
}
// ---- apply_exclusive: clamping / degenerate cases ---------------------------
TEST_CASE("an over-large exclusive zone clamps the usable area to zero, not negative") {
const SurfaceState s{.anchor = kTopStrip, .exclusive_zone = 5000};
const Box out = apply_exclusive(kOutput, s);
CHECK(out.height == 0);
CHECK(out.width == 1920);
// y advanced by the full requested distance even though height clamped.
CHECK(out.y == 5000);
}
TEST_CASE("width clamps to zero on an over-large side reservation") {
const SurfaceState s{.anchor = kLeftStrip, .exclusive_zone = 5000};
const Box out = apply_exclusive(kOutput, s);
CHECK(out.width == 0);
CHECK(out.x == 5000);
}
TEST_CASE("a non-origin output box is reduced relative to its own origin") {
// Second monitor at x=1920.
const Box second{1920, 0, 1280, 1024};
const SurfaceState s{.anchor = kTopStrip, .exclusive_zone = 25};
CHECK(apply_exclusive(second, s) == Box{1920, 25, 1280, 999});
}
TEST_CASE("a -1 (stretch-over) surface never reduces the usable area") {
// Wallpaper/lockscreen anchored to all four with stretch-over zone.
const std::uint32_t all = anchor::top | anchor::bottom | anchor::left | anchor::right;
const SurfaceState s{.anchor = all, .exclusive_zone = -1};
CHECK(apply_exclusive(kOutput, s) == kOutput);
}
|