[PATCH 2/2] Add flip client

Casey Dahlin cdahlin at redhat.com
Fri Apr 29 00:04:55 PDT 2011


The flip client provides access to the move method of the output interface, and
lets you rotate, flip, and shift the screen view.
---
 clients/.gitignore  |    1 +
 clients/Makefile.am |    4 ++
 clients/flip.c      |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 109 insertions(+), 0 deletions(-)
 create mode 100644 clients/flip.c

diff --git a/clients/.gitignore b/clients/.gitignore
index fe7546d..419f05b 100644
--- a/clients/.gitignore
+++ b/clients/.gitignore
@@ -12,3 +12,4 @@ simple-client
 smoke
 terminal
 view
+flip
diff --git a/clients/Makefile.am b/clients/Makefile.am
index ca11be3..6dd5b5a 100644
--- a/clients/Makefile.am
+++ b/clients/Makefile.am
@@ -2,6 +2,7 @@ noinst_PROGRAMS =				\
 	gears					\
 	flower					\
 	screenshot				\
+	flip					\
 	terminal				\
 	image					\
 	$(poppler_programs)			\
@@ -39,6 +40,9 @@ flower_LDADD = $(toolkit_libs)
 screenshot_SOURCES = screenshot.c screenshooter-protocol.c
 screenshot_LDADD = $(toolkit_libs)
 
+flip_SOURCES = flip.c
+flip_LDADD = $(CLIENT_LIBS) -lrt -lm
+
 terminal_SOURCES = terminal.c
 terminal_LDADD = $(toolkit_libs) -lutil
 
diff --git a/clients/flip.c b/clients/flip.c
new file mode 100644
index 0000000..5903a81
--- /dev/null
+++ b/clients/flip.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2011 Casey Dahlin
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <glib.h>
+
+#include "wayland-client.h"
+
+static void
+handle_global(struct wl_display *display, uint32_t id,
+	      const char *interface, uint32_t version, void *data)
+{
+	struct wl_output **output = data;
+
+	if (strcmp(interface, "wl_output") == 0)
+		*output = wl_output_create(display, id, 1);
+}
+
+int main(int argc, char *argv[])
+{
+	struct wl_display *display;
+	struct wl_output *output;
+	int x = 0, y = 0, flags = 0, i;
+	int had_nums = 0;
+	char *end = "";
+
+	for (i = 1; i < argc; i++) {
+		if (! strcmp(argv[i], "--hflip")) {
+			flags |= WL_OUTPUT_HORIZFLIP;
+		} else if (! strcmp(argv[i], "--vflip")) {
+			flags |= WL_OUTPUT_VERTFLIP;
+		} else if (! strcmp(argv[i], "--rotatecw")) {
+			flags |= WL_OUTPUT_CWROTATE;
+		} else if (had_nums == 2) {
+			fprintf(stderr, "too many arguments\n");
+			goto usage;
+		} else if (had_nums++ == 1) {
+			y = strtoll(argv[i], &end, 0);
+		} else {
+			x = strtoll(argv[i], &end, 0);
+		}
+
+		if (*end) {
+			fprintf(stderr, "coordinates must be numeric\n");
+			goto usage;
+		}
+	}
+
+	if (had_nums == 1)
+		goto usage;
+
+	display = wl_display_connect(NULL);
+	if (display == NULL) {
+		fprintf(stderr, "failed to create display: %m\n");
+		return -1;
+	}
+
+	output = NULL;
+	wl_display_add_global_listener(display, handle_global, &output);
+	wl_display_iterate(display, WL_DISPLAY_READABLE);
+	if (output == NULL) {
+		fprintf(stderr, "output not found\n");
+		return -1;
+	}
+
+	wl_output_move(output, x, y, flags);
+	wl_display_iterate(display, WL_DISPLAY_WRITABLE);
+	wl_display_destroy(display);
+
+	return 0;
+usage:
+	fprintf(stderr,
+		"Usage: %s [--hflip] [--vflip] [--rotatecw] [<x> <y>]\n", argv[0]);
+	fprintf(stderr, "  --hflip     Flip output horizontally\n");
+	fprintf(stderr, "  --vflip     Flip output vertically\n");
+	fprintf(stderr, "  --rotatecw  Rotate output clockwise 90 degrees\n");
+	fprintf(stderr,
+		"  <x> <y>     Make output display (x, y) in "
+		"wayland coordinate space\n");
+	return -1;
+}
-- 
1.7.5



More information about the wayland-devel mailing list