aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-06-23 19:06:10 +0100
committeremersion <contact@emersion.fr>2018-06-30 22:18:04 +0100
commitdbb01cbcd01d191e406d99d2837c84a9d73d34a0 (patch)
treef834c0ba0adffbee5a353d2f38dcbd9e37ed0fa4
parent9aaa9ba477f98f0eb827969f80bb845cfef2dd4b (diff)
screencopy: listen to buffer destroy
-rw-r--r--include/wlr/types/wlr_screencopy_v1.h1
-rw-r--r--types/wlr_screencopy_v1.c14
2 files changed, 13 insertions, 2 deletions
diff --git a/include/wlr/types/wlr_screencopy_v1.h b/include/wlr/types/wlr_screencopy_v1.h
index 69f62437..892687aa 100644
--- a/include/wlr/types/wlr_screencopy_v1.h
+++ b/include/wlr/types/wlr_screencopy_v1.h
@@ -23,6 +23,7 @@ struct wlr_screencopy_frame_v1 {
int stride;
struct wl_shm_buffer *buffer;
+ struct wl_listener buffer_destroy;
struct wlr_output *output;
struct wl_listener output_swap_buffers;
diff --git a/types/wlr_screencopy_v1.c b/types/wlr_screencopy_v1.c
index c897e41e..0760eaaf 100644
--- a/types/wlr_screencopy_v1.c
+++ b/types/wlr_screencopy_v1.c
@@ -23,6 +23,7 @@ static void frame_destroy(struct wlr_screencopy_frame_v1 *frame) {
}
wl_list_remove(&frame->link);
wl_list_remove(&frame->output_swap_buffers.link);
+ wl_list_remove(&frame->buffer_destroy.link);
// Make the frame resource inert
wl_resource_set_user_data(frame->resource, NULL);
free(frame);
@@ -73,6 +74,14 @@ static void frame_handle_output_swap_buffers(struct wl_listener *listener,
frame_destroy(frame);
}
+static void frame_handle_buffer_destroy(struct wl_listener *listener,
+ void *data) {
+ struct wlr_screencopy_frame_v1 *frame =
+ wl_container_of(listener, frame, buffer_destroy);
+ zwlr_screencopy_frame_v1_send_failed(frame->resource);
+ frame_destroy(frame);
+}
+
static void frame_handle_copy(struct wl_client *client,
struct wl_resource *frame_resource,
struct wl_resource *buffer_resource) {
@@ -116,11 +125,12 @@ static void frame_handle_copy(struct wl_client *client,
wl_signal_add(&output->events.swap_buffers, &frame->output_swap_buffers);
frame->output_swap_buffers.notify = frame_handle_output_swap_buffers;
+ wl_resource_add_destroy_listener(buffer_resource, &frame->buffer_destroy);
+ frame->buffer_destroy.notify = frame_handle_buffer_destroy;
+
// Schedule a buffer swap
output->needs_swap = true;
wlr_output_schedule_frame(output);
-
- // TODO: listen to buffer destroy
}
static void frame_handle_destroy(struct wl_client *client,