[RFC PATCH weston 1/2] clients: screenshot: Add support to output multiple files

Tomohiro Komagata tomohiro.komagata.aj at gmail.com
Mon Jun 26 16:06:17 UTC 2017


Signed-off-by: Tomohiro Komagata <tomohiro.komagata.aj at gmail.com>
---
  clients/screenshot.c | 14 ++++++++++++--
  shared/file-util.c   |  2 +-
  shared/file-util.h   |  3 +++
  3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/clients/screenshot.c b/clients/screenshot.c
index 6e43d5c..2979b12 100644
--- a/clients/screenshot.c
+++ b/clients/screenshot.c
@@ -39,6 +39,7 @@
  #include "weston-screenshooter-client-protocol.h"
  #include "shared/os-compatibility.h"
  #include "shared/xalloc.h"
+#include "file-util.h"

  /* The screenshooter is a good example of a custom object exposed by
   * the compositor and serves as a test bed for implementing client
@@ -184,10 +185,11 @@ create_shm_buffer(int width, int height, void **data_out)
  static void
  write_png(int width, int height)
  {
-	int output_stride, buffer_stride, i;
+	int output_stride, buffer_stride, i, ret;
  	cairo_surface_t *surface;
  	void *data, *d, *s;
  	struct screenshooter_output *output, *next;
+	char filename[256], timestr[128];

  	buffer_stride = width * 4;

@@ -210,10 +212,18 @@ write_png(int width, int height)
  		free(output);
  	}

+	if (current_time_str(timestr, sizeof(timestr), "%F_%H-%M-%S") < 0)
+		return;
+
+	ret = snprintf(filename, sizeof(filename),
+		       "wayland-screenshot-%s.png", timestr);
+	if (ret < 0 || (size_t)ret >= sizeof(filename))
+		return;
+
  	surface = cairo_image_surface_create_for_data(data,
  						      CAIRO_FORMAT_ARGB32,
  						      width, height, buffer_stride);
-	cairo_surface_write_to_png(surface, "wayland-screenshot.png");
+	cairo_surface_write_to_png(surface, filename);
  	cairo_surface_destroy(surface);
  	free(data);
  }
diff --git a/shared/file-util.c b/shared/file-util.c
index 979a381..f51e5d4 100644
--- a/shared/file-util.c
+++ b/shared/file-util.c
@@ -34,7 +34,7 @@

  #include "file-util.h"

-static int
+int
  current_time_str(char *str, size_t len, const char *fmt)
  {
  	time_t t;
diff --git a/shared/file-util.h b/shared/file-util.h
index f639c44..9c0c10e 100644
--- a/shared/file-util.h
+++ b/shared/file-util.h
@@ -32,6 +32,9 @@ extern "C" {

  #include <stdio.h>

+int
+current_time_str(char *str, size_t len, const char *fmt);
+
  FILE *
  file_create_dated(const char *path_prefix, const char *suffix,
  		  char *name_out, size_t name_len);
-- 
2.7.4



More information about the wayland-devel mailing list