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 Jun 1, 2022
1 parent 671d79d commit 95d9762
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 @@ -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;
Expand Down Expand Up @@ -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;
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 @@ -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;
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 @@ -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);
Expand Down

0 comments on commit 95d9762

Please sign in to comment.