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

Commit 69f68fd

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

File tree

2 files changed

+56
-69
lines changed

2 files changed

+56
-69
lines changed

include/wlr/types/wlr_layer_shell_v1.h

+7-7
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,13 @@ struct wlr_layer_surface_v1 {
7173
char *namespace;
7274

7375
bool added, configured, mapped;
74-
uint32_t configure_serial;
75-
uint32_t configure_next_serial;
7676
struct wl_list configure_list;
7777

78-
struct wlr_layer_surface_v1_configure *acked_configure;
78+
struct wlr_layer_surface_v1_state current, pending;
7979

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;
80+
// Properties to be sent to the client in the next configure event.
81+
struct wlr_layer_surface_v1_configure scheduled;
82+
struct wlr_layer_surface_v1_configure last_acked;
8383

8484
struct wl_listener surface_destroy;
8585

types/wlr_layer_shell_v1.c

+49-62
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,17 @@ 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->last_acked.serial = configure->serial;
91+
surface->last_acked.width = configure->width;
92+
surface->last_acked.height = configure->height;
93+
94+
surface->pending.configure_serial = configure->serial;
95+
surface->pending.actual_width = configure->width;
96+
surface->pending.actual_height = configure->height;
97+
98+
surface->configured = true;
99+
100+
layer_surface_configure_destroy(configure);
96101
}
97102

98103
static void layer_surface_handle_set_size(struct wl_client *client,
@@ -102,8 +107,8 @@ static void layer_surface_handle_set_size(struct wl_client *client,
102107
if (!surface) {
103108
return;
104109
}
105-
surface->client_pending.desired_width = width;
106-
surface->client_pending.desired_height = height;
110+
surface->pending.desired_width = width;
111+
surface->pending.desired_height = height;
107112
}
108113

109114
static void layer_surface_handle_set_anchor(struct wl_client *client,
@@ -123,7 +128,7 @@ static void layer_surface_handle_set_anchor(struct wl_client *client,
123128
if (!surface) {
124129
return;
125130
}
126-
surface->client_pending.anchor = anchor;
131+
surface->pending.anchor = anchor;
127132
}
128133

129134
static void layer_surface_handle_set_exclusive_zone(struct wl_client *client,
@@ -133,7 +138,7 @@ static void layer_surface_handle_set_exclusive_zone(struct wl_client *client,
133138
if (!surface) {
134139
return;
135140
}
136-
surface->client_pending.exclusive_zone = zone;
141+
surface->pending.exclusive_zone = zone;
137142
}
138143

139144
static void layer_surface_handle_set_margin(
@@ -144,10 +149,10 @@ static void layer_surface_handle_set_margin(
144149
if (!surface) {
145150
return;
146151
}
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;
152+
surface->pending.margin.top = top;
153+
surface->pending.margin.right = right;
154+
surface->pending.margin.bottom = bottom;
155+
surface->pending.margin.left = left;
151156
}
152157

153158
static void layer_surface_handle_set_keyboard_interactivity(
@@ -160,14 +165,14 @@ static void layer_surface_handle_set_keyboard_interactivity(
160165
}
161166

162167
if (wl_resource_get_version(resource) < ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND_SINCE_VERSION) {
163-
surface->client_pending.keyboard_interactive = !!interactive;
168+
surface->pending.keyboard_interactive = !!interactive;
164169
} else {
165170
if (interactive > ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
166171
wl_resource_post_error(resource,
167172
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_KEYBOARD_INTERACTIVITY,
168173
"wrong keyboard interactivity value: %" PRIu32, interactive);
169174
} else {
170-
surface->client_pending.keyboard_interactive = interactive;
175+
surface->pending.keyboard_interactive = interactive;
171176
}
172177
}
173178
}
@@ -203,7 +208,7 @@ static void layer_surface_set_layer(struct wl_client *client,
203208
"Invalid layer %" PRIu32, layer);
204209
return;
205210
}
206-
surface->client_pending.layer = layer;
211+
surface->pending.layer = layer;
207212
}
208213

209214
static const struct zwlr_layer_surface_v1_interface layer_surface_implementation = {
@@ -233,8 +238,6 @@ static void layer_surface_unmap(struct wlr_layer_surface_v1 *surface) {
233238
}
234239

235240
surface->configured = surface->mapped = false;
236-
surface->configure_serial = 0;
237-
surface->configure_next_serial = 0;
238241
}
239242

240243
static void layer_surface_destroy(struct wlr_layer_surface_v1 *surface) {
@@ -258,30 +261,23 @@ static void layer_surface_resource_destroy(struct wl_resource *resource) {
258261
}
259262

260263
static bool layer_surface_state_changed(struct wlr_layer_surface_v1 *surface) {
261-
struct wlr_layer_surface_v1_state *state;
264+
struct wlr_layer_surface_v1_configure *configure;
262265
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-
}
266+
configure = &surface->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 != surface->scheduled.width
273+
|| configure->height != surface->scheduled.height;
278274
return changed;
279275
}
280276

281277
void 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;
279+
surface->scheduled.width = width;
280+
surface->scheduled.height = height;
285281
if (layer_surface_state_changed(surface)) {
286282
struct wl_display *display =
287283
wl_client_get_display(wl_resource_get_client(surface->resource));
@@ -291,14 +287,14 @@ void wlr_layer_surface_v1_configure(struct wlr_layer_surface_v1 *surface,
291287
wl_client_post_no_memory(wl_resource_get_client(surface->resource));
292288
return;
293289
}
294-
surface->configure_next_serial = wl_display_next_serial(display);
290+
surface->scheduled.serial = wl_display_next_serial(display);
295291
wl_list_insert(surface->configure_list.prev, &configure->link);
296-
configure->state.actual_width = width;
297-
configure->state.actual_height = height;
298-
configure->serial = surface->configure_next_serial;
292+
configure->width = width;
293+
configure->height = height;
294+
configure->serial = surface->scheduled.serial;
299295
zwlr_layer_surface_v1_send_configure(surface->resource,
300-
configure->serial, configure->state.actual_width,
301-
configure->state.actual_height);
296+
configure->serial, configure->width,
297+
configure->height);
302298
}
303299
}
304300

@@ -316,8 +312,8 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
316312

317313
const uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
318314
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
319-
if (surface->client_pending.desired_width == 0 &&
320-
(surface->client_pending.anchor & horiz) != horiz) {
315+
if (surface->pending.desired_width == 0 &&
316+
(surface->pending.anchor & horiz) != horiz) {
321317
wl_resource_post_error(surface->resource,
322318
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE,
323319
"width 0 requested without setting left and right anchors");
@@ -326,24 +322,15 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
326322

327323
const uint32_t vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
328324
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
329-
if (surface->client_pending.desired_height == 0 &&
330-
(surface->client_pending.anchor & vert) != vert) {
325+
if (surface->pending.desired_height == 0 &&
326+
(surface->pending.anchor & vert) != vert) {
331327
wl_resource_post_error(surface->resource,
332328
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE,
333329
"height 0 requested without setting top and bottom anchors");
334330
return;
335331
}
336332

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-
}
333+
surface->current = surface->pending;
347334

348335
if (wlr_surface_has_buffer(surface->surface) && !surface->configured) {
349336
wl_resource_post_error(surface->resource,
@@ -352,14 +339,14 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
352339
return;
353340
}
354341

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;
342+
surface->current.anchor = surface->pending.anchor;
343+
surface->current.exclusive_zone = surface->pending.exclusive_zone;
344+
surface->current.margin = surface->pending.margin;
358345
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;
346+
surface->pending.keyboard_interactive;
347+
surface->current.desired_width = surface->pending.desired_width;
348+
surface->current.desired_height = surface->pending.desired_height;
349+
surface->current.layer = surface->pending.layer;
363350

364351
if (!surface->added) {
365352
surface->added = true;
@@ -422,7 +409,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client,
422409
if (output_resource) {
423410
surface->output = wlr_output_from_resource(output_resource);
424411
}
425-
surface->current.layer = surface->client_pending.layer = layer;
412+
surface->current.layer = surface->pending.layer = layer;
426413
if (layer > ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) {
427414
free(surface);
428415
wl_resource_post_error(client_resource,

0 commit comments

Comments
 (0)