From 95d976288e01d1f5cab03b00e806f39e686aaba5 Mon Sep 17 00:00:00 2001 From: columbarius Date: Fri, 9 Jul 2021 11:13:13 +0200 Subject: [PATCH] screencast: add cropping via wlroots capture_output_region --- include/screencast_common.h | 7 +++++++ src/screencast/pipewire_screencast.c | 2 +- src/screencast/wlr_screencast.c | 13 +++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/screencast_common.h b/include/screencast_common.h index ecce4283..81fb55bc 100644 --- a/include/screencast_common.h +++ b/include/screencast_common.h @@ -63,6 +63,12 @@ struct xdpw_frame_crop { uint32_t height; }; +enum xdpw_cropmode { + XDPW_CROP_NONE, + XDPW_CROP_WLROOTS, + XDPW_CROP_PIPEWIRE, +}; + struct xdpw_frame { bool y_invert; uint64_t tv_sec; @@ -150,6 +156,7 @@ struct xdpw_screencast_instance { enum xdpw_frame_state frame_state; struct wl_list buffer_list; bool avoid_dmabufs; + enum xdpw_cropmode cropmode; // pipewire struct pw_stream *stream; diff --git a/src/screencast/pipewire_screencast.c b/src/screencast/pipewire_screencast.c index 67568830..2a0a737c 100644 --- a/src/screencast/pipewire_screencast.c +++ b/src/screencast/pipewire_screencast.c @@ -436,7 +436,7 @@ void xdpw_pwr_enqueue_buffer(struct xdpw_screencast_instance *cast) { } struct spa_meta_region *crop; - if ((crop = spa_buffer_find_meta_data(spa_buf, SPA_META_VideoCrop, sizeof(*crop)))) { + if (cast->cropmode == XDPW_CROP_PIPEWIRE && (crop = spa_buffer_find_meta_data(spa_buf, SPA_META_VideoCrop, sizeof(*crop)))) { crop->region.position.x = cast->current_frame.crop.x; crop->region.position.y = cast->current_frame.crop.y; crop->region.size.width = cast->current_frame.crop.width; diff --git a/src/screencast/wlr_screencast.c b/src/screencast/wlr_screencast.c index 69f0251f..53aba4d5 100644 --- a/src/screencast/wlr_screencast.c +++ b/src/screencast/wlr_screencast.c @@ -248,8 +248,17 @@ static const struct zwlr_screencopy_frame_v1_listener wlr_frame_listener = { }; void xdpw_wlr_register_cb(struct xdpw_screencast_instance *cast) { - cast->frame_callback = zwlr_screencopy_manager_v1_capture_output( - cast->ctx->screencopy_manager, cast->with_cursor, cast->target_output->output); + switch (cast->cropmode) { + case XDPW_CROP_WLROOTS: + cast->frame_callback = zwlr_screencopy_manager_v1_capture_output_region( + cast->ctx->screencopy_manager, cast->with_cursor, cast->target_output->output, + cast->current_frame.crop.x, cast->current_frame.crop.y, + cast->current_frame.crop.width, cast->current_frame.crop.height); + break; + default: + cast->frame_callback = zwlr_screencopy_manager_v1_capture_output( + cast->ctx->screencopy_manager, cast->with_cursor, cast->target_output->output); + } zwlr_screencopy_frame_v1_add_listener(cast->frame_callback, &wlr_frame_listener, cast);