screenshooter: Grab pixel data directly before buffer swap
diff --git a/clients/screenshot.c b/clients/screenshot.c
index 086ddd9..328d106 100644
--- a/clients/screenshot.c
+++ b/clients/screenshot.c
@@ -41,6 +41,7 @@
static struct wl_shm *shm;
static struct screenshooter *screenshooter;
static struct wl_list output_list;
+int buffer_copy_done;
struct screenshooter_output {
struct wl_output *output;
@@ -94,6 +95,16 @@
};
static void
+screenshot_done(void *data, struct screenshooter *screenshooter)
+{
+ buffer_copy_done = 1;
+}
+
+static const struct screenshooter_listener screenshooter_listener = {
+ screenshot_done
+};
+
+static void
handle_global(struct wl_display *display, uint32_t id,
const char *interface, uint32_t version, void *data)
{
@@ -188,6 +199,9 @@
return -1;
}
+ screenshooter_add_listener(screenshooter, &screenshooter_listener, screenshooter);
+
+
wl_list_for_each(output, &output_list, link) {
width = MAX(width, output->offset_x + output->width);
height = MAX(height, output->offset_y + output->height);
@@ -197,11 +211,12 @@
wl_list_for_each_safe(output, next, &output_list, link) {
screenshooter_shoot(screenshooter, output->output, buffer);
+ buffer_copy_done = 0;
+ while (!buffer_copy_done)
+ wl_display_roundtrip(display);
free(output);
}
- wl_display_roundtrip(display);
-
write_png(width, height, data);
return 0;