Directory: | ./ |
---|---|
File: | src/client/xdg_shell_positioner.cpp |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 100 | 131 | 76.3% |
Branches: | 47 | 94 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | SPDX-FileCopyrightText: 2021 Roman Gilg <subdiff@gmail.com> | ||
4 | |||
5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only | ||
6 | */ | ||
7 | #include "xdg_shell_positioner.h" | ||
8 | |||
9 | #include "wayland_pointer_p.h" | ||
10 | |||
11 | #include <wayland-xdg-shell-client-protocol.h> | ||
12 | |||
13 | namespace Wrapland::Client | ||
14 | { | ||
15 | |||
16 | 12 | class Q_DECL_HIDDEN xdg_shell_positioner::Private | |
17 | { | ||
18 | public: | ||
19 | 24 | virtual ~Private() = default; | |
20 | |||
21 | void setup(::xdg_positioner* positioner); | ||
22 | bool isValid() const; | ||
23 | |||
24 | xdg_shell_positioner_data data; | ||
25 | 12 | EventQueue* queue{nullptr}; | |
26 | |||
27 | WaylandPointer<::xdg_positioner, xdg_positioner_destroy> positioner_ptr; | ||
28 | }; | ||
29 | |||
30 | 12 | void xdg_shell_positioner::Private::setup(::xdg_positioner* positioner) | |
31 | { | ||
32 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | Q_ASSERT(positioner); |
33 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | Q_ASSERT(!positioner_ptr); |
34 | 12 | positioner_ptr.setup(positioner); | |
35 | 12 | } | |
36 | |||
37 | ✗ | bool xdg_shell_positioner::Private::isValid() const | |
38 | { | ||
39 | ✗ | return positioner_ptr.isValid(); | |
40 | } | ||
41 | |||
42 | 12 | xdg_shell_positioner::xdg_shell_positioner(QObject* parent) | |
43 | 12 | : QObject(parent) | |
44 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | , d_ptr(new Private) |
45 | 12 | { | |
46 | 12 | } | |
47 | |||
48 | 24 | xdg_shell_positioner::~xdg_shell_positioner() = default; | |
49 | |||
50 | 12 | void xdg_shell_positioner::setup(::xdg_positioner* positioner) | |
51 | { | ||
52 | 12 | d_ptr->setup(positioner); | |
53 | 12 | } | |
54 | |||
55 | ✗ | void xdg_shell_positioner::release() | |
56 | { | ||
57 | ✗ | d_ptr->positioner_ptr.release(); | |
58 | } | ||
59 | |||
60 | ✗ | void xdg_shell_positioner::setEventQueue(EventQueue* queue) | |
61 | { | ||
62 | ✗ | d_ptr->queue = queue; | |
63 | } | ||
64 | |||
65 | ✗ | EventQueue* xdg_shell_positioner::eventQueue() | |
66 | { | ||
67 | ✗ | return d_ptr->queue; | |
68 | } | ||
69 | |||
70 | 12 | xdg_shell_positioner::operator ::xdg_positioner*() | |
71 | { | ||
72 | 12 | return d_ptr->positioner_ptr; | |
73 | } | ||
74 | |||
75 | ✗ | xdg_shell_positioner::operator ::xdg_positioner*() const | |
76 | { | ||
77 | ✗ | return d_ptr->positioner_ptr; | |
78 | } | ||
79 | |||
80 | ✗ | bool xdg_shell_positioner::isValid() const | |
81 | { | ||
82 | ✗ | return d_ptr->isValid(); | |
83 | } | ||
84 | |||
85 | ✗ | xdg_shell_positioner_data const& xdg_shell_positioner::get_data() const | |
86 | { | ||
87 | ✗ | return d_ptr->data; | |
88 | } | ||
89 | |||
90 | 12 | void xdg_shell_positioner::set_data(xdg_shell_positioner_data data) | |
91 | { | ||
92 | 12 | d_ptr->data = data; | |
93 | |||
94 | 12 | auto anchorRect = data.anchor.rect; | |
95 | 24 | xdg_positioner_set_anchor_rect(d_ptr->positioner_ptr, | |
96 | 12 | anchorRect.x(), | |
97 | 12 | anchorRect.y(), | |
98 | 12 | anchorRect.width(), | |
99 | 12 | anchorRect.height()); | |
100 | |||
101 | 12 | xdg_positioner_set_size(d_ptr->positioner_ptr, data.size.width(), data.size.height()); | |
102 | |||
103 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
|
12 | if (auto anchorOffset = data.anchor.offset; !anchorOffset.isNull()) { |
104 | 1 | xdg_positioner_set_offset(d_ptr->positioner_ptr, anchorOffset.x(), anchorOffset.y()); | |
105 | 1 | } | |
106 | |||
107 | 12 | auto const edge_data = data.anchor.edge; | |
108 | 12 | uint32_t anchor = XDG_POSITIONER_ANCHOR_NONE; | |
109 | |||
110 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (edge_data.testFlag(Qt::TopEdge)) { |
111 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6 | if (edge_data.testFlag(Qt::LeftEdge) && ((edge_data & ~Qt::LeftEdge) == Qt::TopEdge)) { |
112 | ✗ | anchor = XDG_POSITIONER_ANCHOR_TOP_LEFT; | |
113 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | } else if (edge_data.testFlag(Qt::RightEdge) |
114 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | && ((edge_data & ~Qt::RightEdge) == Qt::TopEdge)) { |
115 | 6 | anchor = XDG_POSITIONER_ANCHOR_TOP_RIGHT; | |
116 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
6 | } else if ((edge_data & ~Qt::TopEdge) == Qt::Edges()) { |
117 | ✗ | anchor = XDG_POSITIONER_ANCHOR_TOP; | |
118 | } | ||
119 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
12 | } else if (edge_data.testFlag(Qt::BottomEdge)) { |
120 | ✗ | if (edge_data.testFlag(Qt::LeftEdge) && ((edge_data & ~Qt::LeftEdge) == Qt::BottomEdge)) { | |
121 | ✗ | anchor = XDG_POSITIONER_ANCHOR_BOTTOM_LEFT; | |
122 | ✗ | } else if (edge_data.testFlag(Qt::RightEdge) | |
123 | ✗ | && ((edge_data & ~Qt::RightEdge) == Qt::BottomEdge)) { | |
124 | ✗ | anchor = XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT; | |
125 | ✗ | } else if ((edge_data & ~Qt::BottomEdge) == Qt::Edges()) { | |
126 | ✗ | anchor = XDG_POSITIONER_ANCHOR_BOTTOM; | |
127 | } | ||
128 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6 | } else if (edge_data.testFlag(Qt::RightEdge) && ((edge_data & ~Qt::RightEdge) == Qt::Edges())) { |
129 | ✗ | anchor = XDG_POSITIONER_ANCHOR_RIGHT; | |
130 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6 | } else if (edge_data.testFlag(Qt::LeftEdge) && ((edge_data & ~Qt::LeftEdge) == Qt::Edges())) { |
131 | ✗ | anchor = XDG_POSITIONER_ANCHOR_LEFT; | |
132 | } | ||
133 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (anchor != 0) { |
134 | 6 | xdg_positioner_set_anchor(d_ptr->positioner_ptr, anchor); | |
135 | 6 | } | |
136 | |||
137 | 12 | auto const gravity_data = data.gravity; | |
138 | 12 | uint32_t gravity = XDG_POSITIONER_GRAVITY_NONE; | |
139 | |||
140 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
|
12 | if (gravity_data.testFlag(Qt::TopEdge)) { |
141 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
4 | if (gravity_data.testFlag(Qt::LeftEdge) |
142 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | && ((gravity_data & ~Qt::LeftEdge) == Qt::TopEdge)) { |
143 | ✗ | gravity = XDG_POSITIONER_GRAVITY_TOP_LEFT; | |
144 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (gravity_data.testFlag(Qt::RightEdge) |
145 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | && ((gravity_data & ~Qt::RightEdge) == Qt::TopEdge)) { |
146 | 4 | gravity = XDG_POSITIONER_GRAVITY_TOP_RIGHT; | |
147 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
4 | } else if ((gravity_data & ~Qt::TopEdge) == Qt::Edges()) { |
148 | ✗ | gravity = XDG_POSITIONER_GRAVITY_TOP; | |
149 | } | ||
150 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
|
12 | } else if (gravity_data.testFlag(Qt::BottomEdge)) { |
151 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
1 | if (gravity_data.testFlag(Qt::LeftEdge) |
152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | && ((gravity_data & ~Qt::LeftEdge) == Qt::BottomEdge)) { |
153 | ✗ | gravity = XDG_POSITIONER_GRAVITY_BOTTOM_LEFT; | |
154 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
1 | } else if (gravity_data.testFlag(Qt::RightEdge) |
155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | && ((gravity_data & ~Qt::RightEdge) == Qt::BottomEdge)) { |
156 | ✗ | gravity = XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT; | |
157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } else if ((gravity_data & ~Qt::BottomEdge) == Qt::Edges()) { |
158 | 1 | gravity = XDG_POSITIONER_GRAVITY_BOTTOM; | |
159 | 1 | } | |
160 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
8 | } else if (gravity_data.testFlag(Qt::RightEdge) |
161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | && ((gravity_data & ~Qt::RightEdge) == Qt::Edges())) { |
162 | ✗ | gravity = XDG_POSITIONER_GRAVITY_RIGHT; | |
163 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
7 | } else if (gravity_data.testFlag(Qt::LeftEdge) |
164 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | && ((gravity_data & ~Qt::LeftEdge) == Qt::Edges())) { |
165 | ✗ | gravity = XDG_POSITIONER_GRAVITY_LEFT; | |
166 | } | ||
167 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 5 times.
|
12 | if (gravity != 0) { |
168 | 5 | xdg_positioner_set_gravity(d_ptr->positioner_ptr, gravity); | |
169 | 5 | } | |
170 | |||
171 | 12 | auto const constraint_data = data.constraint_adjustments; | |
172 | 12 | uint32_t constraint = XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_NONE; | |
173 | |||
174 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | if (constraint_data.testFlag(xdg_shell_constraint_adjustment::slide_x)) { |
175 | 3 | constraint |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X; | |
176 | 3 | } | |
177 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | if (constraint_data.testFlag(xdg_shell_constraint_adjustment::slide_y)) { |
178 | 2 | constraint |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y; | |
179 | 2 | } | |
180 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | if (constraint_data.testFlag(xdg_shell_constraint_adjustment::flip_x)) { |
181 | 2 | constraint |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X; | |
182 | 2 | } | |
183 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | if (constraint_data.testFlag(xdg_shell_constraint_adjustment::flip_y)) { |
184 | 3 | constraint |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y; | |
185 | 3 | } | |
186 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | if (constraint_data.testFlag(xdg_shell_constraint_adjustment::resize_x)) { |
187 | 2 | constraint |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X; | |
188 | 2 | } | |
189 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | if (constraint_data.testFlag(xdg_shell_constraint_adjustment::resize_y)) { |
190 | 2 | constraint |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y; | |
191 | 2 | } | |
192 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | if (constraint != 0) { |
193 | 3 | xdg_positioner_set_constraint_adjustment(d_ptr->positioner_ptr, constraint); | |
194 | 3 | } | |
195 | |||
196 | 12 | xdg_positioner_set_parent_configure(d_ptr->positioner_ptr, data.parent.serial); | |
197 | |||
198 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
|
12 | if (data.is_reactive) { |
199 | 1 | xdg_positioner_set_reactive(d_ptr->positioner_ptr); | |
200 | 1 | } | |
201 | |||
202 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | if (auto psize = data.parent.size; psize.isValid()) { |
203 | 2 | xdg_positioner_set_parent_size(d_ptr->positioner_ptr, psize.width(), psize.height()); | |
204 | 2 | } | |
205 | 12 | } | |
206 | |||
207 | } | ||
208 |