~emersion/grim-dev

Allow to force screen capture protocol v1 PROPOSED

=?UTF-8?q?Guido=20G=C3=BCnther?=: 1
 Allow to force screen capture protocol

 2 files changed, 35 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/grim-dev/patches/57325/mbox | git am -3
Learn more about email & git

[PATCH] Allow to force screen capture protocol Export this patch

From: Simon Ser <contact@emersion.fr>

This can be useful for compositor testing and debugging broken
implementations.
---
 doc/grim.1.scd |  4 ++++
 main.c         | 34 +++++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/doc/grim.1.scd b/doc/grim.1.scd
index bd9c588..c3dfb93 100644
--- a/doc/grim.1.scd
+++ b/doc/grim.1.scd
@@ -56,6 +56,10 @@ output instead.
*-c*
	Include cursors in the screenshot.

*-p*
	Force the given protocol for capturing. Valid values are
	_ext-image-copy-capture-v1_ or _wlr-screencopy-unstable-v1_

# AUTHORS

Maintained by Simon Ser <contact@emersion.fr>, who is assisted by other
diff --git a/main.c b/main.c
index ed19e36..a4b6cae 100644
--- a/main.c
+++ b/main.c
@@ -25,6 +25,12 @@
#include "wlr-screencopy-unstable-v1-protocol.h"
#include "xdg-output-unstable-v1-protocol.h"

enum grim_capture_protocol {
	GRIM_PROTO_ANY,
	GRIM_PROTO_EXT_IMAGE_COPY_CAPTURE_V1,
	GRIM_PROTO_WLR_SCREENCOPY_UNSTABLE_V1,
};

static void screencopy_frame_handle_buffer(void *data,
		struct zwlr_screencopy_frame_v1 *frame, uint32_t format, uint32_t width,
		uint32_t height, uint32_t stride) {
@@ -460,7 +466,8 @@ static const char usage[] =
	"  -q <quality>    Set the JPEG filetype quality 0-100. Defaults to 80.\n"
	"  -l <level>      Set the PNG filetype compression level 0-9. Defaults to 6.\n"
	"  -o <output>     Set the output name to capture.\n"
	"  -c              Include cursors in the screenshot.\n";
	"  -c              Include cursors in the screenshot.\n"
	"  -p <protocol>   Set capturing protocol to use.\n";

int main(int argc, char *argv[]) {
	double scale = 1.0;
@@ -471,8 +478,9 @@ int main(int argc, char *argv[]) {
	int jpeg_quality = 80;
	int png_level = 6; // current default png/zlib compression level
	bool with_cursor = false;
	enum grim_capture_protocol capture_proto = GRIM_PROTO_ANY;
	int opt;
	while ((opt = getopt(argc, argv, "hs:g:t:q:l:o:c")) != -1) {
	while ((opt = getopt(argc, argv, "hs:g:t:q:l:o:cp:")) != -1) {
		switch (opt) {
		case 'h':
			printf("%s", usage);
@@ -568,6 +576,16 @@ int main(int argc, char *argv[]) {
		case 'c':
			with_cursor = true;
			break;
		case 'p':
			if (strcmp(optarg, "ext-image-copy-capture-v1") == 0) {
				capture_proto = GRIM_PROTO_EXT_IMAGE_COPY_CAPTURE_V1;
			} else if (strcmp(optarg, "wlr-screencopy-unstable-v1") == 0) {
				capture_proto = GRIM_PROTO_WLR_SCREENCOPY_UNSTABLE_V1;
			} else {
				fprintf(stderr, "invalid protocol\n");
				return EXIT_FAILURE;
			}
			break;
		default:
			return EXIT_FAILURE;
		}
@@ -625,6 +643,15 @@ int main(int argc, char *argv[]) {
		fprintf(stderr, "compositor doesn't support the screencopy protocol\n");
		return EXIT_FAILURE;
	}
	if (capture_proto == GRIM_PROTO_EXT_IMAGE_COPY_CAPTURE_V1 && (state.ext_output_image_capture_source_manager == NULL ||
			state.ext_image_copy_capture_manager == NULL)) {
		fprintf(stderr, "compositor doesn't support the ext-image-copy-capture-v1 protocol\n");
		return EXIT_FAILURE;
	}
	if (capture_proto == GRIM_PROTO_WLR_SCREENCOPY_UNSTABLE_V1 && state.screencopy_manager == NULL) {
		fprintf(stderr, "compositor doesn't support the wlr-screencopy-unstable protocol\n");
		return EXIT_FAILURE;
	}
	if (wl_list_empty(&state.outputs)) {
		fprintf(stderr, "no wl_output\n");
		return EXIT_FAILURE;
@@ -681,7 +708,8 @@ int main(int argc, char *argv[]) {
			scale = output->logical_scale;
		}

		if (state.ext_output_image_capture_source_manager != NULL) {
		if (state.ext_output_image_capture_source_manager != NULL &&
				(capture_proto == GRIM_PROTO_EXT_IMAGE_COPY_CAPTURE_V1 || capture_proto == GRIM_PROTO_ANY)) {
			uint32_t options = 0;
			if (with_cursor) {
				options |= EXT_IMAGE_COPY_CAPTURE_MANAGER_V1_OPTIONS_PAINT_CURSORS;
-- 
2.47.2
Thanks for the patch!

I'd like to eventually drop support for the older wlroots protocol,
so could we make it clear that the flag is not stable API and will
go away eventually?

Nit: not sure the enum is really necessary here, a simple bool would
be less boilerplate.