blob: 8f4446095b3de370f7183ed366bd89a2c1042d80 [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -05001/*
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
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050023#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"
Kristian Høgsberg3dd66d62010-09-14 16:23:24 -040032#include "screenshooter-client-protocol.h"
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050033
34/* The screenshooter is a good example of a custom object exposed by
35 * the compositor and serves as a test bed for implementing client
36 * side marshalling outside libwayland.so */
37
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -040038static void
39handle_global(struct wl_display *display, uint32_t id,
40 const char *interface, uint32_t version, void *data)
41{
Kristian Høgsberg3dd66d62010-09-14 16:23:24 -040042 struct wl_screenshooter **screenshooter = data;
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050043
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -040044 if (strcmp(interface, "screenshooter") == 0)
Kristian Høgsberg3dd66d62010-09-14 16:23:24 -040045 *screenshooter = wl_screenshooter_create(display, id);
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050046}
47
48int main(int argc, char *argv[])
49{
50 struct wl_display *display;
51 GMainLoop *loop;
52 GSource *source;
Kristian Høgsberg3dd66d62010-09-14 16:23:24 -040053 struct wl_screenshooter *screenshooter;
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050054
Kristian Høgsberg2bb3ebe2010-12-01 15:36:20 -050055 display = wl_display_connect(NULL);
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050056 if (display == NULL) {
57 fprintf(stderr, "failed to create display: %m\n");
58 return -1;
59 }
60
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -040061 screenshooter = NULL;
62 wl_display_add_global_listener(display, handle_global, &screenshooter);
Kristian Høgsberg03fd86b2009-02-10 14:15:44 -050063 wl_display_iterate(display, WL_DISPLAY_READABLE);
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -040064 if (screenshooter == NULL) {
65 fprintf(stderr, "display doesn't support screenshooter\n");
66 return -1;
67 }
68
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050069 loop = g_main_loop_new(NULL, FALSE);
Kristian Høgsberge2ce43a2008-12-02 18:28:23 -050070 source = wl_glib_source_new(display);
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050071 g_source_attach(source, NULL);
72
Kristian Høgsberg3dd66d62010-09-14 16:23:24 -040073 wl_screenshooter_shoot(screenshooter);
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050074
Kristian Høgsbergf53f4bb2008-11-24 11:32:43 -050075 g_idle_add((GSourceFunc) g_main_loop_quit, loop);
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050076 g_main_loop_run(loop);
77
78 return 0;
79}