Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 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 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 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" |
Kristian Høgsberg | 3dd66d6 | 2010-09-14 16:23:24 -0400 | [diff] [blame] | 32 | #include "screenshooter-client-protocol.h" |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 33 | |
| 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øgsberg | 4fe1a3e | 2010-08-10 14:02:48 -0400 | [diff] [blame] | 38 | static void |
| 39 | handle_global(struct wl_display *display, uint32_t id, |
| 40 | const char *interface, uint32_t version, void *data) |
| 41 | { |
Kristian Høgsberg | 3dd66d6 | 2010-09-14 16:23:24 -0400 | [diff] [blame] | 42 | struct wl_screenshooter **screenshooter = data; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 43 | |
Kristian Høgsberg | 4fe1a3e | 2010-08-10 14:02:48 -0400 | [diff] [blame] | 44 | if (strcmp(interface, "screenshooter") == 0) |
Kristian Høgsberg | 3dd66d6 | 2010-09-14 16:23:24 -0400 | [diff] [blame] | 45 | *screenshooter = wl_screenshooter_create(display, id); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | int main(int argc, char *argv[]) |
| 49 | { |
| 50 | struct wl_display *display; |
| 51 | GMainLoop *loop; |
| 52 | GSource *source; |
Kristian Høgsberg | 3dd66d6 | 2010-09-14 16:23:24 -0400 | [diff] [blame] | 53 | struct wl_screenshooter *screenshooter; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 54 | |
Kristian Høgsberg | 2bb3ebe | 2010-12-01 15:36:20 -0500 | [diff] [blame^] | 55 | display = wl_display_connect(NULL); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 56 | if (display == NULL) { |
| 57 | fprintf(stderr, "failed to create display: %m\n"); |
| 58 | return -1; |
| 59 | } |
| 60 | |
Kristian Høgsberg | 4fe1a3e | 2010-08-10 14:02:48 -0400 | [diff] [blame] | 61 | screenshooter = NULL; |
| 62 | wl_display_add_global_listener(display, handle_global, &screenshooter); |
Kristian Høgsberg | 03fd86b | 2009-02-10 14:15:44 -0500 | [diff] [blame] | 63 | wl_display_iterate(display, WL_DISPLAY_READABLE); |
Kristian Høgsberg | 4fe1a3e | 2010-08-10 14:02:48 -0400 | [diff] [blame] | 64 | if (screenshooter == NULL) { |
| 65 | fprintf(stderr, "display doesn't support screenshooter\n"); |
| 66 | return -1; |
| 67 | } |
| 68 | |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 69 | loop = g_main_loop_new(NULL, FALSE); |
Kristian Høgsberg | e2ce43a | 2008-12-02 18:28:23 -0500 | [diff] [blame] | 70 | source = wl_glib_source_new(display); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 71 | g_source_attach(source, NULL); |
| 72 | |
Kristian Høgsberg | 3dd66d6 | 2010-09-14 16:23:24 -0400 | [diff] [blame] | 73 | wl_screenshooter_shoot(screenshooter); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 74 | |
Kristian Høgsberg | f53f4bb | 2008-11-24 11:32:43 -0500 | [diff] [blame] | 75 | g_idle_add((GSourceFunc) g_main_loop_quit, loop); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 76 | g_main_loop_run(loop); |
| 77 | |
| 78 | return 0; |
| 79 | } |