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 Nov 7, 2021
1 parent bb00eb6 commit 4296495
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 @@ -55,6 +55,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 @@ -105,6 +111,7 @@ struct xdpw_screencast_instance {
bool initialized;
struct xdpw_frame current_frame;
enum xdpw_frame_state frame_state;
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 @@ -256,7 +256,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;
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 @@ -216,8 +216,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);
Expand Down

0 comments on commit 4296495

Please sign in to comment.