Drop libdrm CFLAGS where no longer necessary.
[profile/ivi/wayland.git] / screenshot.c
1 /*
2  * Copyright © 2008 Kristian Høgsberg
3  *
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.
13  *
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
20  * OF THIS SOFTWARE.
21  */
22
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <fcntl.h>
28 #include <glib.h>
29
30 #include "wayland-client.h"
31 #include "wayland-glib.h"
32
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 */
36
37 static const char socket_name[] = "\0wayland";
38
39 struct screenshooter {
40         uint32_t id;
41         struct wl_display *display;
42 };
43
44 static struct screenshooter *
45 screenshooter_create(struct wl_display *display)
46 {
47         struct screenshooter *screenshooter;
48         uint32_t id;
49
50         id = wl_display_get_object_id(display, "screenshooter", 1);
51         if (id == 0) {
52                 fprintf(stderr, "server doesn't support screenshooter interface\n");
53                 return NULL;
54         }
55
56         screenshooter = malloc(sizeof screenshooter);
57         if (screenshooter == NULL)
58                 return NULL;
59
60         screenshooter->id = id;
61         screenshooter->display = display;
62
63         return screenshooter;
64 }
65
66 #define SCREENSHOOTER_SHOOT 0
67
68 static void
69 screenshooter_shoot(struct screenshooter *screenshooter)
70 {
71         uint32_t request[2];
72
73         request[0] = screenshooter->id;
74         request[1] = SCREENSHOOTER_SHOOT | ((sizeof request) << 16);
75
76         wl_display_write(screenshooter->display,
77                          request, sizeof request);
78 }
79
80 int main(int argc, char *argv[])
81 {
82         struct wl_display *display;
83         GMainLoop *loop;
84         GSource *source;
85         struct screenshooter *s;
86
87         display = wl_display_create(socket_name, sizeof socket_name);
88         if (display == NULL) {
89                 fprintf(stderr, "failed to create display: %m\n");
90                 return -1;
91         }
92
93         loop = g_main_loop_new(NULL, FALSE);
94         source = wl_glib_source_new(display);
95         g_source_attach(source, NULL);
96
97         s = screenshooter_create(display);
98         if (s == NULL)
99                 exit(-1);
100
101         screenshooter_shoot(s);
102         g_idle_add((GSourceFunc) g_main_loop_quit, loop);
103         g_main_loop_run(loop);
104
105         return 0;
106 }