From 324e894bf0d0e54e2dda0a84980a11acd224d2bb Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 7 Jul 2024 22:14:53 +0200 Subject: [PATCH] ext-image-capture-source-v1: add start/stop hooks This allows the source to change its behavior when actively captured. --- .../wlr_ext_image_capture_source_v1.h | 3 ++ types/ext_image_capture_source_v1/output.c | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/wlr/interfaces/wlr_ext_image_capture_source_v1.h b/include/wlr/interfaces/wlr_ext_image_capture_source_v1.h index 09ec188e..2aa7653f 100644 --- a/include/wlr/interfaces/wlr_ext_image_capture_source_v1.h +++ b/include/wlr/interfaces/wlr_ext_image_capture_source_v1.h @@ -18,6 +18,9 @@ struct wlr_renderer; struct wlr_seat; struct wlr_ext_image_capture_source_v1_interface { + // TODO: drop with_cursors flag + void (*start)(struct wlr_ext_image_capture_source_v1 *source, bool with_cursors); + void (*stop)(struct wlr_ext_image_capture_source_v1 *source); void (*schedule_frame)(struct wlr_ext_image_capture_source_v1 *source); void (*copy_frame)(struct wlr_ext_image_capture_source_v1 *source, struct wlr_ext_image_copy_capture_frame_v1 *dst_frame, diff --git a/types/ext_image_capture_source_v1/output.c b/types/ext_image_capture_source_v1/output.c index 24e77d21..17b69578 100644 --- a/types/ext_image_capture_source_v1/output.c +++ b/types/ext_image_capture_source_v1/output.c @@ -32,6 +32,9 @@ struct wlr_ext_output_image_capture_source_v1 { struct wl_listener output_commit; struct output_cursor_source cursor; + + size_t num_started; + bool software_cursors_locked; }; struct wlr_ext_output_image_capture_source_v1_frame_event { @@ -40,6 +43,32 @@ struct wlr_ext_output_image_capture_source_v1_frame_event { struct timespec *when; }; +static void output_source_start(struct wlr_ext_image_capture_source_v1 *base, + bool with_cursors) { + struct wlr_ext_output_image_capture_source_v1 *source = wl_container_of(base, source, base); + source->num_started++; + if (source->num_started > 1) { + return; + } + wlr_output_lock_attach_render(source->output, true); + if (with_cursors) { + wlr_output_lock_software_cursors(source->output, true); + } + source->software_cursors_locked = with_cursors; +} + +static void output_source_stop(struct wlr_ext_image_capture_source_v1 *base) { + struct wlr_ext_output_image_capture_source_v1 *source = wl_container_of(base, source, base); + assert(source->num_started > 0); + if (source->num_started > 0) { + return; + } + wlr_output_lock_attach_render(source->output, false); + if (source->software_cursors_locked) { + wlr_output_lock_software_cursors(source->output, false); + } +} + static void output_source_schedule_frame(struct wlr_ext_image_capture_source_v1 *base) { struct wlr_ext_output_image_capture_source_v1 *source = wl_container_of(base, source, base); wlr_output_update_needs_frame(source->output); @@ -67,6 +96,8 @@ static struct wlr_ext_image_capture_source_v1_cursor *output_source_get_pointer_ } static const struct wlr_ext_image_capture_source_v1_interface output_source_impl = { + .start = output_source_start, + .stop = output_source_stop, .schedule_frame = output_source_schedule_frame, .copy_frame = output_source_copy_frame, .get_pointer_cursor = output_source_get_pointer_cursor,