diff --git a/README.md b/README.md
index 5dfcaa2..144ed62 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# dulcepan
-A screenshot tool for Wayland compositors. Requires wlr-screencopy-unstable-v1
-support.
+A screenshot tool for Wayland compositors. Requires ext-image-capture-source-v1
+and ext-image-copy-capture-v1 support.
Discuss in [#eclairs on Libera.Chat].
diff --git a/meson.build b/meson.build
index 6934cf5..ad28018 100644
--- a/meson.build
+++ b/meson.build
@@ -43,7 +43,7 @@ add_project_arguments(cc.get_supported_arguments([
m = cc.find_library('m')
wayland_client = dependency('wayland-client')
-wayland_protos = dependency('wayland-protocols')
+wayland_protos = dependency('wayland-protocols', version: '>=1.37')
cairo = dependency('cairo')
pixman = dependency('pixman-1')
diff --git a/protocols/meson.build b/protocols/meson.build
index c3df6da..8d3ef82 100644
--- a/protocols/meson.build
+++ b/protocols/meson.build
@@ -14,12 +14,17 @@ wayland_scanner_client = generator(
)
client_protocols = [
- wl_protocol_dir / 'stable/tablet/tablet-v2.xml', # cursor-shape dependency
+ # cursor-shape-v1 dependency
+ wl_protocol_dir / 'stable/tablet/tablet-v2.xml',
wl_protocol_dir / 'stable/viewporter/viewporter.xml',
- wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml', # layer-shell dependency
+ # wlr-layer-shell-unstable-v1 dependency
+ wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml',
wl_protocol_dir / 'staging/cursor-shape/cursor-shape-v1.xml',
+ # ext-image-capture-source-v1 dependency
+ wl_protocol_dir / 'staging/ext-foreign-toplevel-list/ext-foreign-toplevel-list-v1.xml',
+ wl_protocol_dir / 'staging/ext-image-capture-source/ext-image-capture-source-v1.xml',
+ wl_protocol_dir / 'staging/ext-image-copy-capture/ext-image-copy-capture-v1.xml',
'wlr-layer-shell-unstable-v1.xml',
- 'wlr-screencopy-unstable-v1.xml',
]
client_protos_src = []
diff --git a/protocols/wlr-screencopy-unstable-v1.xml b/protocols/wlr-screencopy-unstable-v1.xml
deleted file mode 100644
index 50b1b7d..0000000
--- a/protocols/wlr-screencopy-unstable-v1.xml
+++ /dev/null
@@ -1,232 +0,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"),
- to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublicense,
- and/or sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice (including the next
- paragraph) shall be included in all copies or substantial portions of the
- Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
-
-
-
- This protocol allows clients to ask the compositor to copy part of the
- screen content to a client buffer.
-
- Warning! The protocol described in this file is experimental and
- backward incompatible changes may be made. Backward compatible changes
- may be added together with the corresponding interface version bump.
- Backward incompatible changes are done by bumping the version number in
- the protocol and interface names and resetting the interface version.
- Once the protocol is to be declared stable, the 'z' prefix and the
- version number in the protocol and interface names are removed and the
- interface version number is reset.
-
-
-
-
- This object is a manager which offers requests to start capturing from a
- source.
-
-
-
-
- Capture the next frame of an entire output.
-
-
-
-
-
-
-
-
- Capture the next frame of an output's region.
-
- The region is given in output logical coordinates, see
- xdg_output.logical_size. The region will be clipped to the output's
- extents.
-
-
-
-
-
-
-
-
-
-
-
-
- All objects created by the manager will still remain valid, until their
- appropriate destroy request has been called.
-
-
-
-
-
-
- This object represents a single frame.
-
- 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.
-
- Once either a "ready" or a "failed" event is received, the client should
- destroy the frame.
-
-
-
-
- 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.
-
-
-
-
-
-
-
-
-
- Copy the frame to the supplied buffer. The buffer must have a the
- 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.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Provides flags about the frame. This event is sent once before the
- "ready" event.
-
-
-
-
-
-
- Called as soon as the frame is copied, indicating it is available
- for reading. This event includes the time at which presentation happened
- at.
-
- The timestamp is expressed as tv_sec_hi, tv_sec_lo, tv_nsec triples,
- each component being an unsigned 32-bit value. Whole seconds are in
- tv_sec which is a 64-bit value combined from tv_sec_hi and tv_sec_lo,
- and the additional fractional part in tv_nsec as nanoseconds. Hence,
- for valid timestamps tv_nsec must be in [0, 999999999]. The seconds part
- may have an arbitrary offset at start.
-
- After receiving this event, the client should destroy the object.
-
-
-
-
-
-
-
-
- This event indicates that the attempted frame copy has failed.
-
- After receiving this event, the client should destroy the object.
-
-
-
-
-
- Destroys the frame. This request can be sent at any time by the client.
-
-
-
-
-
-
- Same as copy, except it waits until there is damage to copy.
-
-
-
-
-
-
- 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.
-
-
-
-
-
-
-
-
-
-
- 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.
-
-
-
-
-
-
-
-
- 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.
-
-
-
-
diff --git a/src/dulcepan.h b/src/dulcepan.h
index 63d6e90..4b0222b 100644
--- a/src/dulcepan.h
+++ b/src/dulcepan.h
@@ -6,6 +6,7 @@
#include
#include
#include
+#include
#include
#include
@@ -60,17 +61,19 @@ struct dp_output {
struct wl_callback *redraw_callback;
bool needs_redraw;
- struct zwlr_screencopy_frame_v1 *frame;
- bool has_frame;
- // XXX: this is completely untested
- bool y_invert;
+ struct ext_image_capture_source_v1 *source;
+ struct ext_image_copy_capture_session_v1 *session;
+
+ struct ext_image_copy_capture_frame_v1 *frame;
+ enum wl_shm_format frame_format;
+ bool has_frame_format;
struct wl_buffer *frame_buffer;
- int32_t frame_stride;
- uint32_t frame_format;
void *frame_data;
size_t frame_size;
+ bool captured;
+
// wl_buffer is NULL if uninitialized
struct dp_buffer swapchain[DP_SWAPCHAIN_LEN];
@@ -186,7 +189,9 @@ struct dp_state {
struct wp_viewporter *viewporter;
struct wl_shm *shm;
struct zwlr_layer_shell_v1 *layer_shell;
- struct zwlr_screencopy_manager_v1 *screencopy_manager;
+
+ struct ext_output_image_capture_source_manager_v1 *output_image_capture_source_manager;
+ struct ext_image_copy_capture_manager_v1 *image_copy_capture_manager;
// Optional
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
@@ -242,6 +247,8 @@ void dp_select_notify_pointer_position(
void dp_select_toggle_whole(struct dp_selection *selection, struct dp_output *output);
+bool dp_format_supported(enum wl_shm_format format);
+
void dp_save(struct dp_state *state);
void dp_log_error(const char *fmt, ...);
diff --git a/src/main.c b/src/main.c
index 7e55949..651dbc7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -8,9 +8,10 @@
#include "cursor-shape-v1-protocol.h"
#include "dulcepan.h"
+#include "ext-image-capture-source-v1-protocol.h"
+#include "ext-image-copy-capture-v1-protocol.h"
#include "viewporter-protocol.h"
#include "wlr-layer-shell-unstable-v1-protocol.h"
-#include "wlr-screencopy-unstable-v1-protocol.h"
static void registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version) {
@@ -27,9 +28,12 @@ static void registry_handle_global(void *data, struct wl_registry *registry, uin
state->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
state->layer_shell = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
- } else if (strcmp(interface, zwlr_screencopy_manager_v1_interface.name) == 0) {
- state->screencopy_manager =
- wl_registry_bind(registry, name, &zwlr_screencopy_manager_v1_interface, 1);
+ } else if (strcmp(interface, ext_output_image_capture_source_manager_v1_interface.name) == 0) {
+ state->output_image_capture_source_manager = wl_registry_bind(
+ registry, name, &ext_output_image_capture_source_manager_v1_interface, 1);
+ } else if (strcmp(interface, ext_image_copy_capture_manager_v1_interface.name) == 0) {
+ state->image_copy_capture_manager =
+ wl_registry_bind(registry, name, &ext_image_copy_capture_manager_v1_interface, 1);
} else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
state->cursor_shape_manager =
wl_registry_bind(registry, name, &wp_cursor_shape_manager_v1_interface, 1);
@@ -88,8 +92,10 @@ static void run(struct dp_state *state) {
dp_log_fatal("The compositor has no wl_shm");
} else if (state->layer_shell == NULL) {
dp_log_fatal("The compositor has no zwlr_layer_shell_v1");
- } else if (state->screencopy_manager == NULL) {
- dp_log_fatal("The compositor has no zwlr_screencopy_manager_v1");
+ } else if (state->output_image_capture_source_manager == NULL) {
+ dp_log_fatal("The compositor has no ext_output_image_capture_source_manager_v1");
+ } else if (state->image_copy_capture_manager == NULL) {
+ dp_log_fatal("The compositor has no ext_image_copy_capture_manager_v1");
}
if (wl_list_empty(&state->outputs)) {
@@ -148,7 +154,9 @@ static void run(struct dp_state *state) {
wp_viewporter_destroy(state->viewporter);
wl_shm_destroy(state->shm);
zwlr_layer_shell_v1_destroy(state->layer_shell);
- zwlr_screencopy_manager_v1_destroy(state->screencopy_manager);
+
+ ext_output_image_capture_source_manager_v1_destroy(state->output_image_capture_source_manager);
+ ext_image_copy_capture_manager_v1_destroy(state->image_copy_capture_manager);
if (state->cursor_shape_manager) {
wp_cursor_shape_manager_v1_destroy(state->cursor_shape_manager);
diff --git a/src/output.c b/src/output.c
index 806eb88..9fce636 100644
--- a/src/output.c
+++ b/src/output.c
@@ -5,14 +5,17 @@
#include
#include "dulcepan.h"
+#include "ext-image-capture-source-v1-protocol.h"
+#include "ext-image-copy-capture-v1-protocol.h"
#include "viewporter-protocol.h"
#include "wlr-layer-shell-unstable-v1-protocol.h"
-#include "wlr-screencopy-unstable-v1-protocol.h"
// Initialiation flow:
-// - Wait for mode+transform info
-// - Wait for done, compute transformed size
-// - Prepare surfaces, get a frame, wait for it to be ready
+// - Wait for the output configuration, compute transformed size
+// - Create a source, a session, and a frame
+// - Create and prepare surfaces
+// - Wait for the session information, capture the frame
+// - Wait for the frame
// - Commit the main surface, wait for a configure event
// - Save effective size, put the frame buffer on the main surface
// - The output is initialized
@@ -21,7 +24,7 @@ static void layer_surface_handle_configure(void *data, struct zwlr_layer_surface
uint32_t serial, uint32_t width, uint32_t height) {
struct dp_output *output = data;
- if (!output->has_frame) {
+ if (!output->captured) {
// Ignore configures that came too early
return;
}
@@ -51,10 +54,6 @@ static void layer_surface_handle_configure(void *data, struct zwlr_layer_surface
wp_viewport_set_destination(
output->select_viewport, output->effective_width, output->effective_height);
- if (output->y_invert) {
- wl_surface_set_buffer_transform(output->main_surface, WL_OUTPUT_TRANSFORM_FLIPPED_180);
- }
-
wl_surface_attach(output->main_surface, output->frame_buffer, 0, 0);
wl_surface_commit(output->main_surface);
@@ -71,54 +70,100 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
.closed = layer_surface_handle_closed,
};
-static void frame_handle_buffer(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t format,
- uint32_t width, uint32_t height, uint32_t stride) {
+static void session_handle_buffer_size(void *data,
+ struct ext_image_copy_capture_session_v1 *session, uint32_t width, uint32_t height) {
struct dp_output *output = data;
-
- if (output->frame_buffer != NULL) {
- wl_buffer_destroy(output->frame_buffer);
- }
-
if ((int32_t)width != output->width || (int32_t)height != output->height) {
dp_log_fatal("Output/buffer size mismatch: mode=%" PRIi32 "x%" PRIi32 ", buffer=%" PRIu32
"x%" PRIu32,
output->width, output->height, width, height);
}
-
- output->frame_format = format;
- output->frame_stride = (int)stride;
- output->frame_buffer = dp_buffer_create(output->state, output->width, output->height,
- output->frame_stride, output->frame_format, &output->frame_data, &output->frame_size);
- zwlr_screencopy_frame_v1_copy(output->frame, output->frame_buffer);
}
-static void frame_handle_flags(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t flags) {
+static void session_handle_shm_format(
+ void *data, struct ext_image_copy_capture_session_v1 *session, uint32_t format) {
struct dp_output *output = data;
- if ((flags & ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT) != 0) {
- output->y_invert = true;
+ if (!output->has_frame_format && dp_format_supported(format)) {
+ output->frame_format = format;
+ output->has_frame_format = true;
}
}
-static void frame_handle_ready(void *data, struct zwlr_screencopy_frame_v1 *frame,
- uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec) {
+static void session_handle_dmabuf_device(
+ void *data, struct ext_image_copy_capture_session_v1 *session, struct wl_array *device) {
+ // Ignored
+}
+
+static void session_handle_dmabuf_format(void *data,
+ struct ext_image_copy_capture_session_v1 *session, uint32_t format,
+ struct wl_array *modifiers) {
+ // Ignored
+}
+
+static void session_handle_done(void *data, struct ext_image_copy_capture_session_v1 *session) {
+ struct dp_output *output = data;
+ if (!output->has_frame_format) {
+ dp_log_fatal("Output %s: no suitable SHM format", output->name);
+ }
+
+ output->frame_buffer = dp_buffer_create(output->state, output->width, output->height,
+ output->width * 4, output->frame_format, &output->frame_data, &output->frame_size);
+
+ ext_image_copy_capture_frame_v1_attach_buffer(output->frame, output->frame_buffer);
+ ext_image_copy_capture_frame_v1_capture(output->frame);
+}
+
+static void session_handle_stopped(void *data, struct ext_image_copy_capture_session_v1 *session) {
+ // Ignored
+}
+
+static const struct ext_image_copy_capture_session_v1_listener session_listener = {
+ .buffer_size = session_handle_buffer_size,
+ .shm_format = session_handle_shm_format,
+ .dmabuf_device = session_handle_dmabuf_device,
+ .dmabuf_format = session_handle_dmabuf_format,
+ .done = session_handle_done,
+ .stopped = session_handle_stopped,
+};
+
+static void frame_handle_transform(
+ void *data, struct ext_image_copy_capture_frame_v1 *frame, uint32_t transform) {
+ // Ignored
+}
+
+static void frame_handle_damage(void *data, struct ext_image_copy_capture_frame_v1 *frame,
+ int32_t x, int32_t y, int32_t width, int32_t height) {
+ // Ignored
+}
+
+static void frame_handle_presentation_time(void *data,
+ struct ext_image_copy_capture_frame_v1 *frame, uint32_t tv_sec_hi, uint32_t tv_sec_lo,
+ uint32_t tv_nsec) {
+ // Ignored
+}
+
+static void frame_handle_ready(void *data, struct ext_image_copy_capture_frame_v1 *frame) {
struct dp_output *output = data;
- zwlr_screencopy_frame_v1_destroy(output->frame);
+ ext_image_copy_capture_frame_v1_destroy(output->frame);
output->frame = NULL;
- output->has_frame = true;
+ output->captured = true;
wl_surface_commit(output->main_surface);
}
-static void frame_handle_failed(void *data, struct zwlr_screencopy_frame_v1 *frame) {
+static void frame_handle_failed(
+ void *data, struct ext_image_copy_capture_frame_v1 *frame, uint32_t reason) {
+ // Shouldn't happen?
struct dp_output *output = data;
- dp_log_fatal("Output %s: failed to copy a frame", output->name);
+ dp_log_fatal("Output %s: failed to capture a frame, reason %" PRIu32, output->name, reason);
}
-static const struct zwlr_screencopy_frame_v1_listener frame_listener = {
- .buffer = frame_handle_buffer,
- .flags = frame_handle_flags,
+static const struct ext_image_copy_capture_frame_v1_listener frame_listener = {
+ .transform = frame_handle_transform,
+ .damage = frame_handle_damage,
+ .presentation_time = frame_handle_presentation_time,
.ready = frame_handle_ready,
.failed = frame_handle_failed,
};
@@ -201,9 +246,16 @@ static void output_handle_done(void *data, struct wl_output *wl_output) {
struct dp_state *state = output->state;
- output->frame = zwlr_screencopy_manager_v1_capture_output(
- state->screencopy_manager, state->show_cursors, output->wl_output);
- zwlr_screencopy_frame_v1_add_listener(output->frame, &frame_listener, output);
+ output->source = ext_output_image_capture_source_manager_v1_create_source(
+ state->output_image_capture_source_manager, output->wl_output);
+
+ output->session =
+ ext_image_copy_capture_manager_v1_create_session(state->image_copy_capture_manager,
+ output->source, EXT_IMAGE_COPY_CAPTURE_MANAGER_V1_OPTIONS_PAINT_CURSORS);
+ ext_image_copy_capture_session_v1_add_listener(output->session, &session_listener, output);
+
+ output->frame = ext_image_copy_capture_session_v1_create_frame(output->session);
+ ext_image_copy_capture_frame_v1_add_listener(output->frame, &frame_listener, output);
output->main_surface = wl_compositor_create_surface(state->compositor);
output->main_layer_surface = zwlr_layer_shell_v1_get_layer_surface(state->layer_shell,
@@ -459,6 +511,9 @@ void dp_output_destroy(struct dp_output *output) {
}
}
+ ext_image_copy_capture_session_v1_destroy(output->session);
+ ext_image_capture_source_v1_destroy(output->source);
+
wl_subsurface_destroy(output->select_subsurface);
wp_viewport_destroy(output->select_viewport);
wl_surface_destroy(output->select_surface);
diff --git a/src/save.c b/src/save.c
index 00d5dd7..fe14b37 100644
--- a/src/save.c
+++ b/src/save.c
@@ -58,7 +58,7 @@ static pixman_format_code_t shm_to_pixman(enum wl_shm_format shm_format) {
return formats[i].pixman;
}
}
- dp_log_fatal("failed to get a matching Pixman format for wl_shm format");
+ return 0;
}
static void write_png(FILE *fp, pixman_image_t *image, int width, int height, int level) {
@@ -106,6 +106,10 @@ static void write_ppm(FILE *fp, pixman_image_t *image, int width, int height) {
}
}
+bool dp_format_supported(enum wl_shm_format format) {
+ return shm_to_pixman(format) != 0;
+}
+
void dp_save(struct dp_state *state) {
struct dp_selection *selection = &state->selection;
struct dp_output *output = selection->output;
@@ -117,14 +121,14 @@ void dp_save(struct dp_state *state) {
pixman_format_code_t pixman_format = shm_to_pixman(output->frame_format);
pixman_image_t *frame_image = pixman_image_create_bits(
- pixman_format, output->width, output->height, output->frame_data, output->frame_stride);
+ pixman_format, output->width, output->height, output->frame_data, output->width * 4);
static const pixman_fixed_t cosines[] = {pixman_fixed_1, 0, -pixman_fixed_1, 0};
pixman_fixed_t scale_x = (output->transform & WL_OUTPUT_TRANSFORM_FLIPPED) != 0
? -pixman_fixed_1
: pixman_fixed_1;
- pixman_fixed_t scale_y = output->y_invert ? -pixman_fixed_1 : pixman_fixed_1;
+ pixman_fixed_t scale_y = pixman_fixed_1;
struct pixman_transform frame_transform;
pixman_transform_init_identity(&frame_transform);