Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 8906365

Browse files
author
Kirill Primak
committed
layer-shell: refactor configure/state flow
Same logic as xdg-toplevel.
1 parent 2e59002 commit 8906365

File tree

2 files changed

+56
-73
lines changed

2 files changed

+56
-73
lines changed

include/wlr/types/wlr_layer_shell_v1.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ struct wlr_layer_surface_v1_state {
5353
uint32_t desired_width, desired_height;
5454
uint32_t actual_width, actual_height;
5555
enum zwlr_layer_shell_v1_layer layer;
56+
uint32_t configure_serial;
5657
};
5758

5859
struct wlr_layer_surface_v1_configure {
5960
struct wl_list link; // wlr_layer_surface_v1::configure_list
6061
uint32_t serial;
61-
struct wlr_layer_surface_v1_state state;
62+
63+
uint32_t width, height;
6264
};
6365

6466
struct wlr_layer_surface_v1 {
@@ -71,15 +73,10 @@ struct wlr_layer_surface_v1 {
7173
char *namespace;
7274

7375
bool added, configured, mapped;
74-
uint32_t configure_serial;
7576
uint32_t configure_next_serial;
7677
struct wl_list configure_list;
7778

78-
struct wlr_layer_surface_v1_configure *acked_configure;
79-
80-
struct wlr_layer_surface_v1_state client_pending;
81-
struct wlr_layer_surface_v1_state server_pending;
82-
struct wlr_layer_surface_v1_state current;
79+
struct wlr_layer_surface_v1_state current, pending;
8380

8481
struct wl_listener surface_destroy;
8582

@@ -119,9 +116,9 @@ struct wlr_layer_shell_v1 *wlr_layer_shell_v1_create(struct wl_display *display)
119116
/**
120117
* Notifies the layer surface to configure itself with this width/height. The
121118
* layer_surface will signal its map event when the surface is ready to assume
122-
* this size.
119+
* this size. Returns the associated configure serial.
123120
*/
124-
void wlr_layer_surface_v1_configure(struct wlr_layer_surface_v1 *surface,
121+
uint32_t wlr_layer_surface_v1_configure(struct wlr_layer_surface_v1 *surface,
125122
uint32_t width, uint32_t height);
126123

127124
/**

types/wlr_layer_shell_v1.c

+50-64
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ static void layer_surface_handle_ack_configure(struct wl_client *client,
8787
layer_surface_configure_destroy(configure);
8888
}
8989

90-
if (surface->acked_configure) {
91-
layer_surface_configure_destroy(surface->acked_configure);
92-
}
93-
surface->acked_configure = configure;
94-
wl_list_remove(&configure->link);
95-
wl_list_init(&configure->link);
90+
surface->pending.configure_serial = configure->serial;
91+
surface->pending.actual_width = configure->width;
92+
surface->pending.actual_height = configure->height;
93+
94+
surface->configured = true;
95+
96+
layer_surface_configure_destroy(configure);
9697
}
9798

9899
static void layer_surface_handle_set_size(struct wl_client *client,
@@ -102,8 +103,8 @@ static void layer_surface_handle_set_size(struct wl_client *client,
102103
if (!surface) {
103104
return;
104105
}
105-
surface->client_pending.desired_width = width;
106-
surface->client_pending.desired_height = height;
106+
surface->pending.desired_width = width;
107+
surface->pending.desired_height = height;
107108
}
108109

109110
static void layer_surface_handle_set_anchor(struct wl_client *client,
@@ -123,7 +124,7 @@ static void layer_surface_handle_set_anchor(struct wl_client *client,
123124
if (!surface) {
124125
return;
125126
}
126-
surface->client_pending.anchor = anchor;
127+
surface->pending.anchor = anchor;
127128
}
128129

129130
static void layer_surface_handle_set_exclusive_zone(struct wl_client *client,
@@ -133,7 +134,7 @@ static void layer_surface_handle_set_exclusive_zone(struct wl_client *client,
133134
if (!surface) {
134135
return;
135136
}
136-
surface->client_pending.exclusive_zone = zone;
137+
surface->pending.exclusive_zone = zone;
137138
}
138139

139140
static void layer_surface_handle_set_margin(
@@ -144,10 +145,10 @@ static void layer_surface_handle_set_margin(
144145
if (!surface) {
145146
return;
146147
}
147-
surface->client_pending.margin.top = top;
148-
surface->client_pending.margin.right = right;
149-
surface->client_pending.margin.bottom = bottom;
150-
surface->client_pending.margin.left = left;
148+
surface->pending.margin.top = top;
149+
surface->pending.margin.right = right;
150+
surface->pending.margin.bottom = bottom;
151+
surface->pending.margin.left = left;
151152
}
152153

153154
static void layer_surface_handle_set_keyboard_interactivity(
@@ -160,14 +161,14 @@ static void layer_surface_handle_set_keyboard_interactivity(
160161
}
161162

162163
if (wl_resource_get_version(resource) < ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND_SINCE_VERSION) {
163-
surface->client_pending.keyboard_interactive = !!interactive;
164+
surface->pending.keyboard_interactive = !!interactive;
164165
} else {
165166
if (interactive > ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
166167
wl_resource_post_error(resource,
167168
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_KEYBOARD_INTERACTIVITY,
168169
"wrong keyboard interactivity value: %" PRIu32, interactive);
169170
} else {
170-
surface->client_pending.keyboard_interactive = interactive;
171+
surface->pending.keyboard_interactive = interactive;
171172
}
172173
}
173174
}
@@ -203,7 +204,7 @@ static void layer_surface_set_layer(struct wl_client *client,
203204
"Invalid layer %" PRIu32, layer);
204205
return;
205206
}
206-
surface->client_pending.layer = layer;
207+
surface->pending.layer = layer;
207208
}
208209

209210
static const struct zwlr_layer_surface_v1_interface layer_surface_implementation = {
@@ -233,8 +234,6 @@ static void layer_surface_unmap(struct wlr_layer_surface_v1 *surface) {
233234
}
234235

235236
surface->configured = surface->mapped = false;
236-
surface->configure_serial = 0;
237-
surface->configure_next_serial = 0;
238237
}
239238

240239
static void layer_surface_destroy(struct wlr_layer_surface_v1 *surface) {
@@ -257,49 +256,45 @@ static void layer_surface_resource_destroy(struct wl_resource *resource) {
257256
}
258257
}
259258

260-
static bool layer_surface_state_changed(struct wlr_layer_surface_v1 *surface) {
261-
struct wlr_layer_surface_v1_state *state;
259+
static bool layer_surface_state_changed(struct wlr_layer_surface_v1 *surface,
260+
uint32_t width, uint32_t height) {
261+
struct wlr_layer_surface_v1_configure last_acked;
262+
struct wlr_layer_surface_v1_configure *configure;
262263
if (wl_list_empty(&surface->configure_list)) {
263-
if (surface->acked_configure) {
264-
state = &surface->acked_configure->state;
265-
} else if (!surface->configured) {
266-
return true;
267-
} else {
268-
state = &surface->current;
269-
}
264+
last_acked.width = surface->pending.actual_width;
265+
last_acked.height = surface->pending.actual_height;
266+
configure = &last_acked;
270267
} else {
271-
struct wlr_layer_surface_v1_configure *configure =
272-
wl_container_of(surface->configure_list.prev, configure, link);
273-
state = &configure->state;
268+
configure = wl_container_of(surface->configure_list.prev,
269+
configure, link);
274270
}
275271

276-
bool changed = state->actual_width != surface->server_pending.actual_width
277-
|| state->actual_height != surface->server_pending.actual_height;
272+
bool changed = configure->width != width
273+
|| configure->height != height;
278274
return changed;
279275
}
280276

281-
void wlr_layer_surface_v1_configure(struct wlr_layer_surface_v1 *surface,
277+
uint32_t wlr_layer_surface_v1_configure(struct wlr_layer_surface_v1 *surface,
282278
uint32_t width, uint32_t height) {
283-
surface->server_pending.actual_width = width;
284-
surface->server_pending.actual_height = height;
285-
if (layer_surface_state_changed(surface)) {
279+
if (layer_surface_state_changed(surface, width, height)) {
286280
struct wl_display *display =
287281
wl_client_get_display(wl_resource_get_client(surface->resource));
288282
struct wlr_layer_surface_v1_configure *configure =
289283
calloc(1, sizeof(struct wlr_layer_surface_v1_configure));
290284
if (configure == NULL) {
291285
wl_client_post_no_memory(wl_resource_get_client(surface->resource));
292-
return;
286+
return surface->configure_next_serial;
293287
}
294288
surface->configure_next_serial = wl_display_next_serial(display);
295289
wl_list_insert(surface->configure_list.prev, &configure->link);
296-
configure->state.actual_width = width;
297-
configure->state.actual_height = height;
290+
configure->width = width;
291+
configure->height = height;
298292
configure->serial = surface->configure_next_serial;
299293
zwlr_layer_surface_v1_send_configure(surface->resource,
300-
configure->serial, configure->state.actual_width,
301-
configure->state.actual_height);
294+
configure->serial, configure->width,
295+
configure->height);
302296
}
297+
return surface->configure_next_serial;
303298
}
304299

305300
void wlr_layer_surface_v1_destroy(struct wlr_layer_surface_v1 *surface) {
@@ -316,8 +311,8 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
316311

317312
const uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
318313
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
319-
if (surface->client_pending.desired_width == 0 &&
320-
(surface->client_pending.anchor & horiz) != horiz) {
314+
if (surface->pending.desired_width == 0 &&
315+
(surface->pending.anchor & horiz) != horiz) {
321316
wl_resource_post_error(surface->resource,
322317
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE,
323318
"width 0 requested without setting left and right anchors");
@@ -326,24 +321,15 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
326321

327322
const uint32_t vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
328323
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
329-
if (surface->client_pending.desired_height == 0 &&
330-
(surface->client_pending.anchor & vert) != vert) {
324+
if (surface->pending.desired_height == 0 &&
325+
(surface->pending.anchor & vert) != vert) {
331326
wl_resource_post_error(surface->resource,
332327
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE,
333328
"height 0 requested without setting top and bottom anchors");
334329
return;
335330
}
336331

337-
if (surface->acked_configure) {
338-
struct wlr_layer_surface_v1_configure *configure =
339-
surface->acked_configure;
340-
surface->configured = true;
341-
surface->configure_serial = configure->serial;
342-
surface->current.actual_width = configure->state.actual_width;
343-
surface->current.actual_height = configure->state.actual_height;
344-
layer_surface_configure_destroy(configure);
345-
surface->acked_configure = NULL;
346-
}
332+
surface->current = surface->pending;
347333

348334
if (wlr_surface_has_buffer(surface->surface) && !surface->configured) {
349335
wl_resource_post_error(surface->resource,
@@ -352,14 +338,14 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
352338
return;
353339
}
354340

355-
surface->current.anchor = surface->client_pending.anchor;
356-
surface->current.exclusive_zone = surface->client_pending.exclusive_zone;
357-
surface->current.margin = surface->client_pending.margin;
341+
surface->current.anchor = surface->pending.anchor;
342+
surface->current.exclusive_zone = surface->pending.exclusive_zone;
343+
surface->current.margin = surface->pending.margin;
358344
surface->current.keyboard_interactive =
359-
surface->client_pending.keyboard_interactive;
360-
surface->current.desired_width = surface->client_pending.desired_width;
361-
surface->current.desired_height = surface->client_pending.desired_height;
362-
surface->current.layer = surface->client_pending.layer;
345+
surface->pending.keyboard_interactive;
346+
surface->current.desired_width = surface->pending.desired_width;
347+
surface->current.desired_height = surface->pending.desired_height;
348+
surface->current.layer = surface->pending.layer;
363349

364350
if (!surface->added) {
365351
surface->added = true;
@@ -422,7 +408,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client,
422408
if (output_resource) {
423409
surface->output = wlr_output_from_resource(output_resource);
424410
}
425-
surface->current.layer = surface->client_pending.layer = layer;
411+
surface->current.layer = surface->pending.layer = layer;
426412
if (layer > ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) {
427413
free(surface);
428414
wl_resource_post_error(client_resource,

0 commit comments

Comments
 (0)