session-lock-v1: use wlr_surface_synced

master
Simon Ser 12 months ago
parent aa32d1a127
commit 0ea6b6e2cc

@ -12,6 +12,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
struct wlr_session_lock_manager_v1 { struct wlr_session_lock_manager_v1 {
struct wl_global *global; struct wl_global *global;
@ -80,6 +81,8 @@ struct wlr_session_lock_surface_v1 {
// private state // private state
struct wlr_surface_synced synced;
struct wl_listener output_destroy; struct wl_listener output_destroy;
}; };

@ -38,7 +38,7 @@ static void lock_surface_destroy(struct wlr_session_lock_surface_v1 *lock_surfac
assert(wl_list_empty(&lock_surface->events.destroy.listener_list)); assert(wl_list_empty(&lock_surface->events.destroy.listener_list));
wl_list_remove(&lock_surface->output_destroy.link); wl_list_remove(&lock_surface->output_destroy.link);
wlr_surface_synced_finish(&lock_surface->synced);
wl_resource_set_user_data(lock_surface->resource, NULL); wl_resource_set_user_data(lock_surface->resource, NULL);
free(lock_surface); free(lock_surface);
} }
@ -149,14 +149,14 @@ static const struct ext_session_lock_surface_v1_interface lock_surface_implement
.ack_configure = lock_surface_handle_ack_configure, .ack_configure = lock_surface_handle_ack_configure,
}; };
static void lock_surface_role_commit(struct wlr_surface *surface) { static void lock_surface_role_client_commit(struct wlr_surface *surface) {
struct wlr_session_lock_surface_v1 *lock_surface = struct wlr_session_lock_surface_v1 *lock_surface =
wlr_session_lock_surface_v1_try_from_wlr_surface(surface); wlr_session_lock_surface_v1_try_from_wlr_surface(surface);
if (lock_surface == NULL) { if (lock_surface == NULL) {
return; return;
} }
if (!wlr_surface_has_buffer(surface)) { if (!wlr_surface_state_has_buffer(&surface->pending)) {
wl_resource_post_error(lock_surface->resource, wl_resource_post_error(lock_surface->resource,
EXT_SESSION_LOCK_SURFACE_V1_ERROR_NULL_BUFFER, EXT_SESSION_LOCK_SURFACE_V1_ERROR_NULL_BUFFER,
"session lock surface is committed with a null buffer"); "session lock surface is committed with a null buffer");
@ -170,15 +170,21 @@ static void lock_surface_role_commit(struct wlr_surface *surface) {
return; return;
} }
if ((uint32_t)surface->current.width != lock_surface->pending.width || if ((uint32_t)surface->pending.width != lock_surface->pending.width ||
(uint32_t)surface->current.height != lock_surface->pending.height) { (uint32_t)surface->pending.height != lock_surface->pending.height) {
wl_resource_post_error(lock_surface->resource, wl_resource_post_error(lock_surface->resource,
EXT_SESSION_LOCK_SURFACE_V1_ERROR_DIMENSIONS_MISMATCH, EXT_SESSION_LOCK_SURFACE_V1_ERROR_DIMENSIONS_MISMATCH,
"committed surface dimensions do not match last acked configure"); "committed surface dimensions do not match last acked configure");
return; return;
} }
}
lock_surface->current = lock_surface->pending; static void lock_surface_role_commit(struct wlr_surface *surface) {
struct wlr_session_lock_surface_v1 *lock_surface =
wlr_session_lock_surface_v1_try_from_wlr_surface(surface);
if (lock_surface == NULL) {
return;
}
wlr_surface_map(surface); wlr_surface_map(surface);
} }
@ -194,10 +200,15 @@ static void lock_surface_role_destroy(struct wlr_surface *surface) {
static const struct wlr_surface_role lock_surface_role = { static const struct wlr_surface_role lock_surface_role = {
.name = "ext_session_lock_surface_v1", .name = "ext_session_lock_surface_v1",
.client_commit = lock_surface_role_client_commit,
.commit = lock_surface_role_commit, .commit = lock_surface_role_commit,
.destroy = lock_surface_role_destroy, .destroy = lock_surface_role_destroy,
}; };
static const struct wlr_surface_synced_impl surface_synced_impl = {
.state_size = sizeof(struct wlr_session_lock_surface_v1_state),
};
static void lock_surface_handle_output_destroy(struct wl_listener *listener, static void lock_surface_handle_output_destroy(struct wl_listener *listener,
void *data) { void *data) {
struct wlr_session_lock_surface_v1 *lock_surface = struct wlr_session_lock_surface_v1 *lock_surface =
@ -268,6 +279,13 @@ static void lock_handle_get_lock_surface(struct wl_client *client,
return; return;
} }
if (!wlr_surface_synced_init(&lock_surface->synced, surface,
&surface_synced_impl, &lock_surface->pending, &lock_surface->current)) {
free(lock_surface);
wl_client_post_no_memory(client);
return;
}
lock_surface->resource = lock_surface_resource; lock_surface->resource = lock_surface_resource;
wl_resource_set_user_data(lock_surface_resource, lock_surface); wl_resource_set_user_data(lock_surface_resource, lock_surface);

Loading…
Cancel
Save