Add wlr_layer_surface_configure

This commit is contained in:
Drew DeVault 2018-03-17 21:06:54 -04:00
parent 4a8c0c0784
commit 1628730b09
2 changed files with 95 additions and 2 deletions

View file

@ -7,6 +7,18 @@
#include <wlr/types/wlr_surface.h>
#include "wlr-layer-shell-unstable-v1-protocol.h"
/**
* wlr_layer_shell allows clients to arrange themselves in "layers" on the
* desktop in accordance with the wlr-layer-shell protocol. When a client is
* added, the new_surface signal will be raised and passed a reference to our
* wlr_layer_surface. At this time, the client will have configured the surface
* as it desires, including information like desired anchors and margins. The
* compositor should use this information to decide how to arrange the layer
* on-screen, then determine the dimensions of the layer and call
* wlr_layer_surface_configure. The client will then attach a buffer and commit
* the surface, at which point the wlr_layer_surface map signal is raised and
* the compositor should begin rendering the surface.
*/
struct wlr_layer_shell {
struct wl_global *wl_global;
struct wl_list clients;
@ -30,11 +42,14 @@ struct wlr_layer_client {
};
struct wlr_layer_surface_state {
// Client
uint32_t anchor;
uint32_t exclusive_zone;
struct {
uint32_t top, right, bottom, left;
} margin;
// Server
uint32_t width, height;
};
struct wlr_layer_surface_configure {
@ -76,4 +91,12 @@ struct wlr_layer_surface {
struct wlr_layer_shell *wlr_layer_shell_create(struct wl_display *display);
void wlr_layer_shell_destroy(struct wlr_layer_shell *layer_shell);
/**
* Notifies the layer surface to configure itself with this width/height. The
* layer_surface will signal its map event when the surface is ready to assume
* this size.
*/
void wlr_layer_surface_configure(struct wlr_layer_surface *surface,
uint32_t width, uint32_t height);
#endif

View file

@ -151,6 +151,76 @@ static void layer_surface_resource_destroy(struct wl_resource *resource) {
}
}
static bool wlr_layer_surface_state_changed(struct wlr_layer_surface *surface) {
if (!surface->configured) {
return false;
}
struct wlr_layer_surface_state *state;
if (wl_list_empty(&surface->configure_list)) {
state = &surface->current;
} else {
struct wlr_layer_surface_configure *configure =
wl_container_of(surface->configure_list.prev, configure, link);
state = &configure->state;
}
return !memcmp(state, &surface->pending,
sizeof(struct wlr_layer_surface_state));
}
static void wlr_layer_surface_send_configure(void *user_data) {
struct wlr_layer_surface *surface = user_data;
surface->configure_idle = NULL;
struct wlr_layer_surface_configure *configure =
calloc(1, sizeof(struct wlr_layer_surface_configure));
if (configure == NULL) {
wl_client_post_no_memory(surface->client->client);
return;
}
wl_list_insert(surface->configure_list.prev, &configure->link);
configure->serial = surface->configure_next_serial;
configure->state = surface->pending;
zwlr_layer_surface_v1_send_configure(surface->resource,
configure->serial, configure->state.width, configure->state.height);
}
static uint32_t wlr_layer_surface_schedule_configure(
struct wlr_layer_surface *surface) {
struct wl_display *display = wl_client_get_display(surface->client->client);
struct wl_event_loop *loop = wl_display_get_event_loop(display);
bool changed = wlr_layer_surface_state_changed(surface);
if (surface->configure_idle != NULL) {
if (changed) {
// configure request already scheduled
return surface->configure_next_serial;
}
// configure request not necessary anymore
wl_event_source_remove(surface->configure_idle);
surface->configure_idle = NULL;
return 0;
} else {
if (!changed) {
// configure request not necessary
return 0;
}
surface->configure_next_serial = wl_display_next_serial(display);
surface->configure_idle = wl_event_loop_add_idle(loop,
wlr_layer_surface_send_configure, surface);
return surface->configure_next_serial;
}
}
void wlr_layer_surface_configure(struct wlr_layer_surface *surface,
uint32_t width, uint32_t height) {
surface->pending.width = width;
surface->pending.height = height;
wlr_layer_surface_schedule_configure(surface);
}
static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
void *role_data) {
struct wlr_layer_surface *surface = role_data;
@ -163,8 +233,8 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
}
if (!surface->added) {
surface->added = true;
wlr_signal_emit_safe(
&surface->client->shell->events.new_surface, surface);
wlr_signal_emit_safe(&surface->client->shell->events.new_surface,
surface);
}
if (surface->configured && wlr_surface_has_buffer(surface->surface) &&
!surface->mapped) {