Skip to content

Commit

Permalink
screencast: add cropping via wlroots capture_output_region
Browse files Browse the repository at this point in the history
  • Loading branch information
columbarius committed Jul 9, 2021
1 parent 92c493b commit 28f75f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/screencast_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ struct xdpw_frame_crop {
uint32_t height;
};

enum xdpw_cropmode {
XDPW_CROP_NONE,
XDPW_CROP_WLROOTS,
XDPW_CROP_PIPEWIRE,
};

struct xdpw_frame {
uint32_t size;
uint32_t stride;
Expand Down Expand Up @@ -97,6 +103,7 @@ struct xdpw_screencast_instance {
struct xdpw_screencast_context *ctx;
bool initialized;
struct xdpw_frame simple_frame;
enum xdpw_cropmode cropmode;

// pipewire
struct pw_stream *stream;
Expand Down
2 changes: 1 addition & 1 deletion src/screencast/pipewire_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void xdpw_pwr_export_buffer(struct xdpw_screencast_instance *cast) {
damage->region.size.height = cast->simple_frame.damage.height;
}

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->simple_frame.crop.x;
crop->region.position.y = cast->simple_frame.crop.y;
crop->region.size.width = cast->simple_frame.crop.width;
Expand Down
13 changes: 11 additions & 2 deletions src/screencast/wlr_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,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->simple_frame.crop.x, cast->simple_frame.crop.y,
cast->simple_frame.crop.width, cast->simple_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);
Expand Down

0 comments on commit 28f75f2

Please sign in to comment.