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
M inc/wlr-screencopy-unstable-v1-client-protocol.h +108 -15
@@ 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 @@ extern "C" {
  * <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 @@ extern const struct wl_interface zwlr_sc
  *
  * 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 @@ extern const struct wl_interface zwlr_sc
  *
  * 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 @@ enum zwlr_screencopy_frame_v1_flags {
  */
 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 @@ struct zwlr_screencopy_frame_v1_listener
 	 */
 	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 @@ zwlr_screencopy_frame_v1_add_listener(st
 
 #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 @@ zwlr_screencopy_frame_v1_add_listener(st
  * @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 @@ zwlr_screencopy_frame_v1_add_listener(st
  * @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 @@ zwlr_screencopy_frame_v1_get_version(str
  * @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 @@ zwlr_screencopy_frame_v1_destroy(struct 
 	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

          
M proto/wlr-screencopy-unstable-v1-protocol.c +21 -15
@@ 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_buff
 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 @@ static const struct wl_interface *types[
 	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,
 };
 

          
M src/scpy_source.c +4 -1
@@ 250,7 250,10 @@ static void render(void* data, gs_effect
 		.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) {