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

Commit 136e388

Browse files
author
Kirill Primak
committed
layer-shell: implement configure scheduling
This commit puts wlr_layer_surface_v1.scheduled in use and implements configure scheduling mechanism used by xdg-surface, unifying the API.
1 parent 6cb6ea5 commit 136e388

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

include/wlr/types/wlr_layer_shell_v1.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct wlr_layer_surface_v1 {
7979

8080
// Properties to be sent to the client in the next configure event.
8181
struct wlr_layer_surface_v1_configure scheduled;
82+
struct wl_event_source *configure_idle;
8283

8384
struct wl_listener surface_destroy;
8485

@@ -118,9 +119,9 @@ struct wlr_layer_shell_v1 *wlr_layer_shell_v1_create(struct wl_display *display)
118119
/**
119120
* Notifies the layer surface to configure itself with this width/height. The
120121
* layer_surface will signal its map event when the surface is ready to assume
121-
* this size.
122+
* this size. Returns the associated configure serial.
122123
*/
123-
void wlr_layer_surface_v1_configure(struct wlr_layer_surface_v1 *surface,
124+
uint32_t wlr_layer_surface_v1_set_size(struct wlr_layer_surface_v1 *surface,
124125
uint32_t width, uint32_t height);
125126

126127
/**

types/wlr_layer_shell_v1.c

+39-32
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ static void layer_surface_unmap(struct wlr_layer_surface_v1 *surface) {
234234
}
235235

236236
surface->configured = surface->mapped = false;
237+
if (surface->configure_idle) {
238+
wl_event_source_remove(surface->configure_idle);
239+
surface->configure_idle = NULL;
240+
}
237241
}
238242

239243
static void layer_surface_destroy(struct wlr_layer_surface_v1 *surface) {
@@ -256,45 +260,48 @@ static void layer_surface_resource_destroy(struct wl_resource *resource) {
256260
}
257261
}
258262

259-
static bool layer_surface_state_changed(struct wlr_layer_surface_v1 *surface) {
260-
struct wlr_layer_surface_v1_configure last_acked;
261-
struct wlr_layer_surface_v1_configure *configure;
262-
if (wl_list_empty(&surface->configure_list)) {
263-
last_acked.width = surface->pending.actual_width;
264-
last_acked.height = surface->pending.actual_height;
265-
configure = &last_acked;
266-
} else {
267-
configure = wl_container_of(surface->configure_list.prev,
268-
configure, link);
263+
static void surface_send_configure(void *data) {
264+
struct wlr_layer_surface_v1 *surface = data;
265+
266+
surface->configure_idle = NULL;
267+
268+
struct wlr_layer_surface_v1_configure *configure =
269+
calloc(1, sizeof(*configure));
270+
if (configure == NULL) {
271+
wl_resource_post_no_memory(surface->resource);
272+
return;
269273
}
270274

271-
bool changed = configure->width != surface->scheduled.width
272-
|| configure->height != surface->scheduled.height;
273-
return changed;
275+
wl_list_insert(surface->configure_list.prev, &configure->link);
276+
configure->serial = surface->scheduled.serial;
277+
configure->width = surface->scheduled.width;
278+
configure->height = surface->scheduled.height;
279+
280+
zwlr_layer_surface_v1_send_configure(surface->resource,
281+
configure->serial, configure->width, configure->height);
282+
}
283+
284+
static uint32_t schedule_configure(struct wlr_layer_surface_v1 *surface) {
285+
struct wl_client *client = wl_resource_get_client(surface->resource);
286+
struct wl_display *display = wl_client_get_display(client);
287+
struct wl_event_loop *loop = wl_display_get_event_loop(display);
288+
289+
if (surface->configure_idle == NULL) {
290+
surface->scheduled.serial = wl_display_next_serial(display);
291+
surface->configure_idle = wl_event_loop_add_idle(loop,
292+
surface_send_configure, surface);
293+
if (surface->configure_idle == NULL) {
294+
wl_client_post_no_memory(client);
295+
}
296+
}
297+
return surface->scheduled.serial;
274298
}
275299

276-
void wlr_layer_surface_v1_configure(struct wlr_layer_surface_v1 *surface,
300+
uint32_t wlr_layer_surface_v1_set_size(struct wlr_layer_surface_v1 *surface,
277301
uint32_t width, uint32_t height) {
278302
surface->scheduled.width = width;
279303
surface->scheduled.height = height;
280-
if (layer_surface_state_changed(surface)) {
281-
struct wl_display *display =
282-
wl_client_get_display(wl_resource_get_client(surface->resource));
283-
struct wlr_layer_surface_v1_configure *configure =
284-
calloc(1, sizeof(struct wlr_layer_surface_v1_configure));
285-
if (configure == NULL) {
286-
wl_client_post_no_memory(wl_resource_get_client(surface->resource));
287-
return;
288-
}
289-
surface->scheduled.serial = wl_display_next_serial(display);
290-
wl_list_insert(surface->configure_list.prev, &configure->link);
291-
configure->width = width;
292-
configure->height = height;
293-
configure->serial = surface->scheduled.serial;
294-
zwlr_layer_surface_v1_send_configure(surface->resource,
295-
configure->serial, configure->width,
296-
configure->height);
297-
}
304+
return schedule_configure(surface);
298305
}
299306

300307
void wlr_layer_surface_v1_destroy(struct wlr_layer_surface_v1 *surface) {

0 commit comments

Comments
 (0)