~scoopta/wlrobs

Support v3 of wlr-screencopy-unstable-v1 v1 PROPOSED

Quantum
Quantum: 1
 Support v3 of wlr-screencopy-unstable-v1

 3 files changed, 133 insertions(+), 31 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/~scoopta/wlrobs/patches/11314/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Support v3 of wlr-screencopy-unstable-v1 Export this patch

Quantum
# HG changeset patch
# User Quantum <me@quantum2.xyz>
# Date 1592867889 14400
#      Mon Jun 22 19:18:09 2020 -0400
# Node ID 3293e89a3d205fa16df2e7e75de9a2c78d601968
# Parent  ee7200c605742e4c4cb75870066b98b78e6ee340
Support v3 of wlr-screencopy-unstable-v1

This commit adds support for newer libwlroots, after the merger of
https://github.com/swaywm/wlroots/pull/2133

diff --git a/inc/wlr-screencopy-unstable-v1-client-protocol.h b/inc/wlr-screencopy-unstable-v1-client-protocol.h
--- a/inc/wlr-screencopy-unstable-v1-client-protocol.h
+++ b/inc/wlr-screencopy-unstable-v1-client-protocol.h
@@ -1,4 +1,4 @@
/* Generated by wayland-scanner 1.16.0 */
/* Generated by wayland-scanner 1.18.0 */

#ifndef WLR_SCREENCOPY_UNSTABLE_V1_CLIENT_PROTOCOL_H
#define WLR_SCREENCOPY_UNSTABLE_V1_CLIENT_PROTOCOL_H
@@ -36,6 +36,7 @@
 * <pre>
 *
 * Copyright © 2018 Simon Ser
 * Copyright © 2019 Andri Yngvason
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
@@ -84,9 +85,14 @@
 *
 * This object represents a single frame.
 *
 * When created, a "buffer" event will be sent. The client will then be able
 * to send a "copy" request. If the capture is successful, the compositor
 * will send a "flags" followed by a "ready" event.
 * When created, a series of buffer events will be sent, each representing a
 * supported buffer type. The "buffer_done" event is sent afterwards to
 * indicate that all supported buffer types have been enumerated. The client
 * will then be able to send a "copy" request. If the capture is successful,
 * the compositor will send a "flags" followed by a "ready" event.
 *
 * For objects version 2 or lower, wl_shm buffers are always supported, ie.
 * the "buffer" event is guaranteed to be sent.
 *
 * If the capture failed, the "failed" event is sent. This can happen anytime
 * before the "ready" event.
@@ -101,9 +107,14 @@
 *
 * This object represents a single frame.
 *
 * When created, a "buffer" event will be sent. The client will then be able
 * to send a "copy" request. If the capture is successful, the compositor
 * will send a "flags" followed by a "ready" event.
 * When created, a series of buffer events will be sent, each representing a
 * supported buffer type. The "buffer_done" event is sent afterwards to
 * indicate that all supported buffer types have been enumerated. The client
 * will then be able to send a "copy" request. If the capture is successful,
 * the compositor will send a "flags" followed by a "ready" event.
 *
 * For objects version 2 or lower, wl_shm buffers are always supported, ie.
 * the "buffer" event is guaranteed to be sent.
 *
 * If the capture failed, the "failed" event is sent. This can happen anytime
 * before the "ready" event.
@@ -232,13 +243,11 @@
 */
struct zwlr_screencopy_frame_v1_listener {
	/**
	 * buffer information
	 * wl_shm buffer information
	 *
	 * Provides information about the frame's buffer. This event is
	 * sent once as soon as the frame is created.
	 *
	 * The client should then create a buffer with the provided
	 * attributes, and send a "copy" request.
	 * Provides information about wl_shm buffer parameters that need
	 * to be used for this frame. This event is sent once after the
	 * frame is created if wl_shm buffers are supported.
	 * @param format buffer format
	 * @param width buffer width
	 * @param height buffer height
@@ -296,6 +305,60 @@
	 */
	void (*failed)(void *data,
		       struct zwlr_screencopy_frame_v1 *zwlr_screencopy_frame_v1);
	/**
	 * carries the coordinates of the damaged region
	 *
	 * This event is sent right before the ready event when
	 * copy_with_damage is requested. It may be generated multiple
	 * times for each copy_with_damage request.
	 *
	 * The arguments describe a box around an area that has changed
	 * since the last copy request that was derived from the current
	 * screencopy manager instance.
	 *
	 * The union of all regions received between the call to
	 * copy_with_damage and a ready event is the total damage since the
	 * prior ready event.
	 * @param x damaged x coordinates
	 * @param y damaged y coordinates
	 * @param width current width
	 * @param height current height
	 * @since 2
	 */
	void (*damage)(void *data,
		       struct zwlr_screencopy_frame_v1 *zwlr_screencopy_frame_v1,
		       uint32_t x,
		       uint32_t y,
		       uint32_t width,
		       uint32_t height);
	/**
	 * linux-dmabuf buffer information
	 *
	 * Provides information about linux-dmabuf buffer parameters that
	 * need to be used for this frame. This event is sent once after
	 * the frame is created if linux-dmabuf buffers are supported.
	 * @param format fourcc pixel format
	 * @param width buffer width
	 * @param height buffer height
	 * @since 3
	 */
	void (*linux_dmabuf)(void *data,
			     struct zwlr_screencopy_frame_v1 *zwlr_screencopy_frame_v1,
			     uint32_t format,
			     uint32_t width,
			     uint32_t height);
	/**
	 * all buffer types reported
	 *
	 * This event is sent once after all buffer events have been
	 * sent.
	 *
	 * The client should proceed to create a buffer of one of the
	 * supported types, and send a "copy" request.
	 * @since 3
	 */
	void (*buffer_done)(void *data,
			    struct zwlr_screencopy_frame_v1 *zwlr_screencopy_frame_v1);
};

/**
@@ -311,6 +374,7 @@

#define ZWLR_SCREENCOPY_FRAME_V1_COPY 0
#define ZWLR_SCREENCOPY_FRAME_V1_DESTROY 1
#define ZWLR_SCREENCOPY_FRAME_V1_COPY_WITH_DAMAGE 2

/**
 * @ingroup iface_zwlr_screencopy_frame_v1
@@ -328,6 +392,18 @@
 * @ingroup iface_zwlr_screencopy_frame_v1
 */
#define ZWLR_SCREENCOPY_FRAME_V1_FAILED_SINCE_VERSION 1
/**
 * @ingroup iface_zwlr_screencopy_frame_v1
 */
#define ZWLR_SCREENCOPY_FRAME_V1_DAMAGE_SINCE_VERSION 2
/**
 * @ingroup iface_zwlr_screencopy_frame_v1
 */
#define ZWLR_SCREENCOPY_FRAME_V1_LINUX_DMABUF_SINCE_VERSION 3
/**
 * @ingroup iface_zwlr_screencopy_frame_v1
 */
#define ZWLR_SCREENCOPY_FRAME_V1_BUFFER_DONE_SINCE_VERSION 3

/**
 * @ingroup iface_zwlr_screencopy_frame_v1
@@ -337,6 +413,10 @@
 * @ingroup iface_zwlr_screencopy_frame_v1
 */
#define ZWLR_SCREENCOPY_FRAME_V1_DESTROY_SINCE_VERSION 1
/**
 * @ingroup iface_zwlr_screencopy_frame_v1
 */
#define ZWLR_SCREENCOPY_FRAME_V1_COPY_WITH_DAMAGE_SINCE_VERSION 2

/** @ingroup iface_zwlr_screencopy_frame_v1 */
static inline void
@@ -362,8 +442,9 @@
 * @ingroup iface_zwlr_screencopy_frame_v1
 *
 * Copy the frame to the supplied buffer. The buffer must have a the
 * correct size, see zwlr_screencopy_frame_v1.buffer. The buffer needs to
 * have a supported format.
 * correct size, see zwlr_screencopy_frame_v1.buffer and
 * zwlr_screencopy_frame_v1.linux_dmabuf. The buffer needs to have a
 * supported format.
 *
 * If the frame is successfully copied, a "flags" and a "ready" events are
 * sent. Otherwise, a "failed" event is sent.
@@ -389,6 +470,18 @@
	wl_proxy_destroy((struct wl_proxy *) zwlr_screencopy_frame_v1);
}

/**
 * @ingroup iface_zwlr_screencopy_frame_v1
 *
 * Same as copy, except it waits until there is damage to copy.
 */
static inline void
zwlr_screencopy_frame_v1_copy_with_damage(struct zwlr_screencopy_frame_v1 *zwlr_screencopy_frame_v1, struct wl_buffer *buffer)
{
	wl_proxy_marshal((struct wl_proxy *) zwlr_screencopy_frame_v1,
			 ZWLR_SCREENCOPY_FRAME_V1_COPY_WITH_DAMAGE, buffer);
}

#ifdef  __cplusplus
}
#endif
diff --git a/proto/wlr-screencopy-unstable-v1-protocol.c b/proto/wlr-screencopy-unstable-v1-protocol.c
--- a/proto/wlr-screencopy-unstable-v1-protocol.c
+++ b/proto/wlr-screencopy-unstable-v1-protocol.c
@@ -1,7 +1,8 @@
/* Generated by wayland-scanner 1.16.0 */
/* Generated by wayland-scanner 1.18.0 */

/*
 * Copyright © 2018 Simon Ser
 * Copyright © 2019 Andri Yngvason
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
@@ -41,7 +42,7 @@
extern const struct wl_interface wl_output_interface;
extern const struct wl_interface zwlr_screencopy_frame_v1_interface;

static const struct wl_interface *types[] = {
static const struct wl_interface *wlr_screencopy_unstable_v1_types[] = {
	NULL,
	NULL,
	NULL,
@@ -57,35 +58,40 @@
	NULL,
	NULL,
	&wl_buffer_interface,
	&wl_buffer_interface,
};

static const struct wl_message zwlr_screencopy_manager_v1_requests[] = {
	{ "capture_output", "nio", types + 4 },
	{ "capture_output_region", "nioiiii", types + 7 },
	{ "destroy", "", types + 0 },
	{ "capture_output", "nio", wlr_screencopy_unstable_v1_types + 4 },
	{ "capture_output_region", "nioiiii", wlr_screencopy_unstable_v1_types + 7 },
	{ "destroy", "", wlr_screencopy_unstable_v1_types + 0 },
};

WL_PRIVATE const struct wl_interface zwlr_screencopy_manager_v1_interface = {
	"zwlr_screencopy_manager_v1", 1,
	"zwlr_screencopy_manager_v1", 3,
	3, zwlr_screencopy_manager_v1_requests,
	0, NULL,
};

static const struct wl_message zwlr_screencopy_frame_v1_requests[] = {
	{ "copy", "o", types + 14 },
	{ "destroy", "", types + 0 },
	{ "copy", "o", wlr_screencopy_unstable_v1_types + 14 },
	{ "destroy", "", wlr_screencopy_unstable_v1_types + 0 },
	{ "copy_with_damage", "2o", wlr_screencopy_unstable_v1_types + 15 },
};

static const struct wl_message zwlr_screencopy_frame_v1_events[] = {
	{ "buffer", "uuuu", types + 0 },
	{ "flags", "u", types + 0 },
	{ "ready", "uuu", types + 0 },
	{ "failed", "", types + 0 },
	{ "buffer", "uuuu", wlr_screencopy_unstable_v1_types + 0 },
	{ "flags", "u", wlr_screencopy_unstable_v1_types + 0 },
	{ "ready", "uuu", wlr_screencopy_unstable_v1_types + 0 },
	{ "failed", "", wlr_screencopy_unstable_v1_types + 0 },
	{ "damage", "2uuuu", wlr_screencopy_unstable_v1_types + 0 },
	{ "linux_dmabuf", "3uuu", wlr_screencopy_unstable_v1_types + 0 },
	{ "buffer_done", "3", wlr_screencopy_unstable_v1_types + 0 },
};

WL_PRIVATE const struct wl_interface zwlr_screencopy_frame_v1_interface = {
	"zwlr_screencopy_frame_v1", 1,
	2, zwlr_screencopy_frame_v1_requests,
	4, zwlr_screencopy_frame_v1_events,
	"zwlr_screencopy_frame_v1", 3,
	3, zwlr_screencopy_frame_v1_requests,
	7, zwlr_screencopy_frame_v1_events,
};

diff --git a/src/scpy_source.c b/src/scpy_source.c
--- a/src/scpy_source.c
+++ b/src/scpy_source.c
@@ -250,7 +250,10 @@
		.buffer = buffer,
		.flags = nop,
		.ready = ready,
		.failed = failed
		.failed = failed,
		.damage = nop,
		.linux_dmabuf = nop,
		.buffer_done = nop,
	};
	zwlr_screencopy_frame_v1_add_listener(frame, &listener, this);
	while(this->waiting) {
Scoopta
Looks good, it's been pushed