2 * Copyright © 2008 Kristian Høgsberg
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
30 #include "wayland-client.h"
31 #include "wayland-glib.h"
33 /* The screenshooter is a good example of a custom object exposed by
34 * the compositor and serves as a test bed for implementing client
35 * side marshalling outside libwayland.so */
37 static const char socket_name[] = "\0wayland";
39 struct screenshooter {
41 struct wl_display *display;
44 static struct screenshooter *
45 screenshooter_create(struct wl_display *display)
47 struct screenshooter *screenshooter;
50 id = wl_display_get_object_id(display, "screenshooter", 1);
52 fprintf(stderr, "server doesn't support screenshooter interface\n");
56 screenshooter = malloc(sizeof screenshooter);
57 if (screenshooter == NULL)
60 screenshooter->id = id;
61 screenshooter->display = display;
66 #define SCREENSHOOTER_SHOOT 0
69 screenshooter_shoot(struct screenshooter *screenshooter)
73 request[0] = screenshooter->id;
74 request[1] = SCREENSHOOTER_SHOOT | ((sizeof request) << 16);
76 wl_display_write(screenshooter->display,
77 request, sizeof request);
80 int main(int argc, char *argv[])
82 struct wl_display *display;
85 struct screenshooter *s;
87 display = wl_display_create(socket_name, sizeof socket_name);
88 if (display == NULL) {
89 fprintf(stderr, "failed to create display: %m\n");
93 loop = g_main_loop_new(NULL, FALSE);
94 source = wl_glib_source_new(display);
95 g_source_attach(source, NULL);
97 s = screenshooter_create(display);
101 screenshooter_shoot(s);
102 g_idle_add((GSourceFunc) g_main_loop_quit, loop);
103 g_main_loop_run(loop);