Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Benjamin Franzke |
| 3 | * Copyright © 2011 Intel Corporation |
| 4 | * |
Bryce Harrington | 1f6b0d1 | 2015-06-10 22:48:59 -0700 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 11 | * |
Bryce Harrington | 1f6b0d1 | 2015-06-10 22:48:59 -0700 | [diff] [blame] | 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 23 | */ |
| 24 | |
Bryce Harrington | b4dae9b | 2016-06-15 18:13:07 -0700 | [diff] [blame] | 25 | #include "config.h" |
Kristian Høgsberg | c7d2c4c | 2013-08-26 14:43:17 -0700 | [diff] [blame] | 26 | |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 27 | #include <stdint.h> |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
| 31 | #include <stdbool.h> |
| 32 | #include <assert.h> |
| 33 | #include <unistd.h> |
| 34 | #include <sys/mman.h> |
| 35 | |
| 36 | #include <wayland-client.h> |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 37 | #include "shared/helpers.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 38 | #include "shared/os-compatibility.h" |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 39 | |
Ander Conselvan de Oliveira | c3f03f5 | 2014-05-07 11:57:27 +0300 | [diff] [blame] | 40 | struct seat { |
| 41 | struct touch *touch; |
| 42 | struct wl_seat *seat; |
| 43 | struct wl_touch *wl_touch; |
| 44 | }; |
| 45 | |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 46 | struct touch { |
| 47 | struct wl_display *display; |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 48 | struct wl_registry *registry; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 49 | struct wl_compositor *compositor; |
| 50 | struct wl_shell *shell; |
| 51 | struct wl_shm *shm; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 52 | struct wl_pointer *pointer; |
| 53 | struct wl_keyboard *keyboard; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 54 | struct wl_surface *surface; |
| 55 | struct wl_shell_surface *shell_surface; |
| 56 | struct wl_buffer *buffer; |
| 57 | int has_argb; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 58 | int width, height; |
| 59 | void *data; |
| 60 | }; |
| 61 | |
| 62 | static void |
| 63 | create_shm_buffer(struct touch *touch) |
| 64 | { |
Kristian Høgsberg | 1662628 | 2012-04-03 11:21:27 -0400 | [diff] [blame] | 65 | struct wl_shm_pool *pool; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 66 | int fd, size, stride; |
| 67 | |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 68 | stride = touch->width * 4; |
| 69 | size = stride * touch->height; |
Pekka Paalanen | 1da1b8f | 2012-06-06 16:59:43 +0300 | [diff] [blame] | 70 | |
| 71 | fd = os_create_anonymous_file(size); |
| 72 | if (fd < 0) { |
| 73 | fprintf(stderr, "creating a buffer file for %d B failed: %m\n", |
| 74 | size); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 75 | exit(1); |
| 76 | } |
| 77 | |
| 78 | touch->data = |
| 79 | mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 80 | if (touch->data == MAP_FAILED) { |
| 81 | fprintf(stderr, "mmap failed: %m\n"); |
| 82 | close(fd); |
| 83 | exit(1); |
| 84 | } |
| 85 | |
Kristian Høgsberg | 1662628 | 2012-04-03 11:21:27 -0400 | [diff] [blame] | 86 | pool = wl_shm_create_pool(touch->shm, fd, size); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 87 | touch->buffer = |
Kristian Høgsberg | 1662628 | 2012-04-03 11:21:27 -0400 | [diff] [blame] | 88 | wl_shm_pool_create_buffer(pool, 0, |
| 89 | touch->width, touch->height, stride, |
| 90 | WL_SHM_FORMAT_ARGB8888); |
| 91 | wl_shm_pool_destroy(pool); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 92 | |
| 93 | close(fd); |
| 94 | } |
| 95 | |
| 96 | static void |
| 97 | shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) |
| 98 | { |
| 99 | struct touch *touch = data; |
| 100 | |
Kristian Høgsberg | 8e81df4 | 2012-01-11 14:24:46 -0500 | [diff] [blame] | 101 | if (format == WL_SHM_FORMAT_ARGB8888) |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 102 | touch->has_argb = 1; |
| 103 | } |
| 104 | |
Stefan Schmidt | 85c40f2 | 2013-08-05 13:50:50 +0100 | [diff] [blame] | 105 | struct wl_shm_listener shm_listener = { |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 106 | shm_format |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | static void |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 111 | touch_paint(struct touch *touch, int32_t x, int32_t y, int32_t id) |
| 112 | { |
| 113 | uint32_t *p, c; |
| 114 | static const uint32_t colors[] = { |
| 115 | 0xffff0000, |
| 116 | 0xffffff00, |
| 117 | 0xff0000ff, |
| 118 | 0xffff00ff, |
Pekka Paalanen | 55b7cb2 | 2012-07-31 13:21:11 +0300 | [diff] [blame] | 119 | 0xff00ff00, |
| 120 | 0xff00ffff, |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 121 | }; |
| 122 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 123 | if (id < (int32_t) ARRAY_LENGTH(colors)) |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 124 | c = colors[id]; |
| 125 | else |
| 126 | c = 0xffffffff; |
| 127 | |
Pekka Paalanen | 0768419 | 2012-07-31 13:21:12 +0300 | [diff] [blame] | 128 | if (x < 2 || x >= touch->width - 2 || |
| 129 | y < 2 || y >= touch->height - 2) |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 130 | return; |
| 131 | |
Pekka Paalanen | 55b7cb2 | 2012-07-31 13:21:11 +0300 | [diff] [blame] | 132 | p = (uint32_t *) touch->data + (x - 2) + (y - 2) * touch->width; |
| 133 | p[2] = c; |
| 134 | p += touch->width; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 135 | p[1] = c; |
Pekka Paalanen | 55b7cb2 | 2012-07-31 13:21:11 +0300 | [diff] [blame] | 136 | p[2] = c; |
| 137 | p[3] = c; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 138 | p += touch->width; |
| 139 | p[0] = c; |
| 140 | p[1] = c; |
| 141 | p[2] = c; |
Pekka Paalanen | 55b7cb2 | 2012-07-31 13:21:11 +0300 | [diff] [blame] | 142 | p[3] = c; |
| 143 | p[4] = c; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 144 | p += touch->width; |
| 145 | p[1] = c; |
Pekka Paalanen | 55b7cb2 | 2012-07-31 13:21:11 +0300 | [diff] [blame] | 146 | p[2] = c; |
| 147 | p[3] = c; |
| 148 | p += touch->width; |
| 149 | p[2] = c; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 150 | |
Kristian Høgsberg | 5addaa1 | 2013-07-22 14:32:41 -0700 | [diff] [blame] | 151 | wl_surface_attach(touch->surface, touch->buffer, 0, 0); |
Pekka Paalanen | 76fc57e | 2012-07-31 13:21:13 +0300 | [diff] [blame] | 152 | wl_surface_damage(touch->surface, x - 2, y - 2, 5, 5); |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 153 | /* todo: We could queue up more damage before committing, if there |
| 154 | * are more input events to handle. |
| 155 | */ |
| 156 | wl_surface_commit(touch->surface); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 160 | touch_handle_down(void *data, struct wl_touch *wl_touch, |
| 161 | uint32_t serial, uint32_t time, struct wl_surface *surface, |
| 162 | int32_t id, wl_fixed_t x_w, wl_fixed_t y_w) |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 163 | { |
| 164 | struct touch *touch = data; |
Kristian Høgsberg | 80680c7 | 2012-05-10 12:21:37 -0400 | [diff] [blame] | 165 | float x = wl_fixed_to_double(x_w); |
| 166 | float y = wl_fixed_to_double(y_w); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 167 | |
| 168 | touch_paint(touch, x, y, id); |
| 169 | } |
| 170 | |
| 171 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 172 | touch_handle_up(void *data, struct wl_touch *wl_touch, |
| 173 | uint32_t serial, uint32_t time, int32_t id) |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 174 | { |
| 175 | } |
| 176 | |
| 177 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 178 | touch_handle_motion(void *data, struct wl_touch *wl_touch, |
| 179 | uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w) |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 180 | { |
| 181 | struct touch *touch = data; |
Kristian Høgsberg | 80680c7 | 2012-05-10 12:21:37 -0400 | [diff] [blame] | 182 | float x = wl_fixed_to_double(x_w); |
| 183 | float y = wl_fixed_to_double(y_w); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 184 | |
| 185 | touch_paint(touch, x, y, id); |
| 186 | } |
| 187 | |
| 188 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 189 | touch_handle_frame(void *data, struct wl_touch *wl_touch) |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 190 | { |
| 191 | } |
| 192 | |
| 193 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 194 | touch_handle_cancel(void *data, struct wl_touch *wl_touch) |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 195 | { |
| 196 | } |
| 197 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 198 | static const struct wl_touch_listener touch_listener = { |
| 199 | touch_handle_down, |
| 200 | touch_handle_up, |
| 201 | touch_handle_motion, |
| 202 | touch_handle_frame, |
| 203 | touch_handle_cancel, |
| 204 | }; |
| 205 | |
| 206 | static void |
Ander Conselvan de Oliveira | c3f03f5 | 2014-05-07 11:57:27 +0300 | [diff] [blame] | 207 | seat_handle_capabilities(void *data, struct wl_seat *wl_seat, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 208 | enum wl_seat_capability caps) |
| 209 | { |
Ander Conselvan de Oliveira | c3f03f5 | 2014-05-07 11:57:27 +0300 | [diff] [blame] | 210 | struct seat *seat = data; |
| 211 | struct touch *touch = seat->touch; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 212 | |
Ander Conselvan de Oliveira | c3f03f5 | 2014-05-07 11:57:27 +0300 | [diff] [blame] | 213 | if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !seat->wl_touch) { |
| 214 | seat->wl_touch = wl_seat_get_touch(wl_seat); |
| 215 | wl_touch_set_user_data(seat->wl_touch, touch); |
| 216 | wl_touch_add_listener(seat->wl_touch, &touch_listener, touch); |
| 217 | } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && seat->wl_touch) { |
| 218 | wl_touch_destroy(seat->wl_touch); |
| 219 | seat->wl_touch = NULL; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | static const struct wl_seat_listener seat_listener = { |
| 224 | seat_handle_capabilities, |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | static void |
Ander Conselvan de Oliveira | c3f03f5 | 2014-05-07 11:57:27 +0300 | [diff] [blame] | 228 | add_seat(struct touch *touch, uint32_t name, uint32_t version) |
| 229 | { |
| 230 | struct seat *seat; |
| 231 | |
| 232 | seat = malloc(sizeof *seat); |
| 233 | assert(seat); |
| 234 | |
| 235 | seat->touch = touch; |
| 236 | seat->wl_touch = NULL; |
| 237 | seat->seat = wl_registry_bind(touch->registry, name, |
| 238 | &wl_seat_interface, 1); |
| 239 | wl_seat_add_listener(seat->seat, &seat_listener, seat); |
| 240 | } |
| 241 | |
| 242 | static void |
Pekka Paalanen | 7e94a98 | 2012-07-31 13:21:10 +0300 | [diff] [blame] | 243 | handle_ping(void *data, struct wl_shell_surface *shell_surface, |
| 244 | uint32_t serial) |
| 245 | { |
| 246 | wl_shell_surface_pong(shell_surface, serial); |
| 247 | } |
| 248 | |
| 249 | static void |
| 250 | handle_configure(void *data, struct wl_shell_surface *shell_surface, |
| 251 | uint32_t edges, int32_t width, int32_t height) |
| 252 | { |
| 253 | } |
| 254 | |
| 255 | static void |
| 256 | handle_popup_done(void *data, struct wl_shell_surface *shell_surface) |
| 257 | { |
| 258 | } |
| 259 | |
| 260 | static const struct wl_shell_surface_listener shell_surface_listener = { |
| 261 | handle_ping, |
| 262 | handle_configure, |
| 263 | handle_popup_done |
| 264 | }; |
| 265 | |
| 266 | static void |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 267 | handle_global(void *data, struct wl_registry *registry, |
| 268 | uint32_t name, const char *interface, uint32_t version) |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 269 | { |
| 270 | struct touch *touch = data; |
| 271 | |
| 272 | if (strcmp(interface, "wl_compositor") == 0) { |
| 273 | touch->compositor = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 274 | wl_registry_bind(registry, name, |
| 275 | &wl_compositor_interface, 1); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 276 | } else if (strcmp(interface, "wl_shell") == 0) { |
| 277 | touch->shell = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 278 | wl_registry_bind(registry, name, |
| 279 | &wl_shell_interface, 1); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 280 | } else if (strcmp(interface, "wl_shm") == 0) { |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 281 | touch->shm = wl_registry_bind(registry, name, |
| 282 | &wl_shm_interface, 1); |
Stefan Schmidt | 85c40f2 | 2013-08-05 13:50:50 +0100 | [diff] [blame] | 283 | wl_shm_add_listener(touch->shm, &shm_listener, touch); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 284 | } else if (strcmp(interface, "wl_seat") == 0) { |
Ander Conselvan de Oliveira | c3f03f5 | 2014-05-07 11:57:27 +0300 | [diff] [blame] | 285 | add_seat(touch, name, version); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
Pekka Paalanen | 0eab05d | 2013-01-22 14:53:55 +0200 | [diff] [blame] | 289 | static void |
| 290 | handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) |
| 291 | { |
| 292 | } |
| 293 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 294 | static const struct wl_registry_listener registry_listener = { |
Pekka Paalanen | 0eab05d | 2013-01-22 14:53:55 +0200 | [diff] [blame] | 295 | handle_global, |
| 296 | handle_global_remove |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 297 | }; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 298 | |
| 299 | static struct touch * |
| 300 | touch_create(int width, int height) |
| 301 | { |
| 302 | struct touch *touch; |
| 303 | |
| 304 | touch = malloc(sizeof *touch); |
Kristian Høgsberg | c85a917 | 2013-08-15 11:40:30 -0700 | [diff] [blame] | 305 | if (touch == NULL) { |
| 306 | fprintf(stderr, "out of memory\n"); |
| 307 | exit(1); |
| 308 | } |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 309 | touch->display = wl_display_connect(NULL); |
| 310 | assert(touch->display); |
| 311 | |
| 312 | touch->has_argb = 0; |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 313 | touch->registry = wl_display_get_registry(touch->display); |
| 314 | wl_registry_add_listener(touch->registry, ®istry_listener, touch); |
| 315 | wl_display_dispatch(touch->display); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 316 | wl_display_roundtrip(touch->display); |
| 317 | |
| 318 | if (!touch->has_argb) { |
| 319 | fprintf(stderr, "WL_SHM_FORMAT_ARGB32 not available\n"); |
| 320 | exit(1); |
| 321 | } |
| 322 | |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 323 | touch->width = width; |
| 324 | touch->height = height; |
| 325 | touch->surface = wl_compositor_create_surface(touch->compositor); |
| 326 | touch->shell_surface = wl_shell_get_shell_surface(touch->shell, |
| 327 | touch->surface); |
| 328 | create_shm_buffer(touch); |
| 329 | |
Pekka Paalanen | 7e94a98 | 2012-07-31 13:21:10 +0300 | [diff] [blame] | 330 | if (touch->shell_surface) { |
| 331 | wl_shell_surface_add_listener(touch->shell_surface, |
| 332 | &shell_surface_listener, touch); |
| 333 | wl_shell_surface_set_toplevel(touch->shell_surface); |
| 334 | } |
| 335 | |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 336 | wl_surface_set_user_data(touch->surface, touch); |
Scott Moreau | 01a9f1b | 2012-10-07 08:56:30 -0600 | [diff] [blame] | 337 | wl_shell_surface_set_title(touch->shell_surface, "simple-touch"); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 338 | |
| 339 | memset(touch->data, 64, width * height * 4); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 340 | wl_surface_attach(touch->surface, touch->buffer, 0, 0); |
| 341 | wl_surface_damage(touch->surface, 0, 0, width, height); |
Pekka Paalanen | c9e00c0 | 2012-10-10 12:49:24 +0300 | [diff] [blame] | 342 | wl_surface_commit(touch->surface); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 343 | |
| 344 | return touch; |
| 345 | } |
| 346 | |
| 347 | int |
| 348 | main(int argc, char **argv) |
| 349 | { |
| 350 | struct touch *touch; |
Kristian Høgsberg | a17f7a1 | 2012-10-16 13:16:10 -0400 | [diff] [blame] | 351 | int ret = 0; |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 352 | |
| 353 | touch = touch_create(600, 500); |
| 354 | |
Kristian Høgsberg | a17f7a1 | 2012-10-16 13:16:10 -0400 | [diff] [blame] | 355 | while (ret != -1) |
| 356 | ret = wl_display_dispatch(touch->display); |
Kristian Høgsberg | 558949b | 2011-12-21 22:54:49 -0500 | [diff] [blame] | 357 | |
| 358 | return 0; |
| 359 | } |