Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Tim Wiederhake |
| 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 | /** |
| 24 | * \file eventdemo.c |
| 25 | * \brief Demonstrate the use of Wayland's toytoolkit. |
| 26 | * |
| 27 | * Heavily commented demo program that can report all events that are |
| 28 | * dispatched to the window. For other functionality, eg. opengl/egl, |
| 29 | * drag and drop, etc. have a look at the other demos. |
| 30 | * \author Tim Wiederhake |
| 31 | */ |
| 32 | |
Andrew Wedgbury | 9cd661e | 2014-04-07 12:40:35 +0100 | [diff] [blame^] | 33 | #include "config.h" |
| 34 | |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
| 37 | |
| 38 | #include <cairo.h> |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 39 | |
| 40 | #include "window.h" |
| 41 | |
| 42 | /** window title */ |
| 43 | static char *title = "EventDemo"; |
| 44 | |
| 45 | /** window width */ |
| 46 | static int width = 500; |
| 47 | |
| 48 | /** window height */ |
| 49 | static int height = 400; |
| 50 | |
| 51 | /** set if window has no borders */ |
| 52 | static int noborder = 0; |
| 53 | |
| 54 | /** if non-zero, maximum window width */ |
| 55 | static int width_max = 0; |
| 56 | |
| 57 | /** if non-zero, maximum window height */ |
| 58 | static int height_max = 0; |
| 59 | |
| 60 | /** set to log redrawing */ |
| 61 | static int log_redraw = 0; |
| 62 | |
| 63 | /** set to log resizing */ |
| 64 | static int log_resize = 0; |
| 65 | |
| 66 | /** set to log keyboard focus */ |
| 67 | static int log_focus = 0; |
| 68 | |
| 69 | /** set to log key events */ |
| 70 | static int log_key = 0; |
| 71 | |
| 72 | /** set to log button events */ |
| 73 | static int log_button = 0; |
| 74 | |
Philipp Brüschweiler | 70cc73b | 2012-08-14 11:02:42 +0200 | [diff] [blame] | 75 | /** set to log axis events */ |
| 76 | static int log_axis = 0; |
| 77 | |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 78 | /** set to log motion events */ |
| 79 | static int log_motion = 0; |
| 80 | |
| 81 | /** |
| 82 | * \struct eventdemo |
| 83 | * \brief Holds all data the program needs per window |
| 84 | * |
| 85 | * In this demo the struct holds the position of a |
| 86 | * red rectangle that is drawn in the window's area. |
| 87 | */ |
| 88 | struct eventdemo { |
| 89 | struct window *window; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 90 | struct widget *widget; |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 91 | struct display *display; |
| 92 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 93 | int x, y, w, h; |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | /** |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 97 | * \brief CALLBACK function, Wayland requests the window to redraw. |
Philipp Brüschweiler | 850f504 | 2012-08-14 11:02:39 +0200 | [diff] [blame] | 98 | * \param widget widget to be redrawn |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 99 | * \param data user data associated to the window |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 100 | * |
| 101 | * Draws a red rectangle as demonstration of per-window data. |
| 102 | */ |
| 103 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 104 | redraw_handler(struct widget *widget, void *data) |
| 105 | { |
| 106 | struct eventdemo *e = data; |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 107 | cairo_surface_t *surface; |
| 108 | cairo_t *cr; |
| 109 | struct rectangle rect; |
| 110 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 111 | if (log_redraw) |
| 112 | printf("redraw\n"); |
| 113 | |
Kristian Høgsberg | bb97700 | 2012-01-10 19:11:42 -0500 | [diff] [blame] | 114 | widget_get_allocation(e->widget, &rect); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 115 | surface = window_get_surface(e->window); |
| 116 | |
| 117 | cr = cairo_create(surface); |
| 118 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 119 | |
| 120 | cairo_rectangle(cr, rect.x, rect.y, rect.width, rect.height); |
| 121 | cairo_set_source_rgba(cr, 0, 0, 0, 0.8); |
| 122 | cairo_fill(cr); |
| 123 | |
| 124 | cairo_rectangle(cr, e->x, e->y, e->w, e->h); |
| 125 | cairo_set_source_rgba(cr, 1.0, 0, 0, 1); |
| 126 | cairo_fill(cr); |
| 127 | |
| 128 | cairo_destroy(cr); |
| 129 | cairo_surface_destroy(surface); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /** |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 133 | * \brief CALLBACK function, Wayland requests the window to resize. |
Philipp Brüschweiler | 850f504 | 2012-08-14 11:02:39 +0200 | [diff] [blame] | 134 | * \param widget widget to be resized |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 135 | * \param width desired width |
| 136 | * \param height desired height |
| 137 | * \param data user data associated to the window |
| 138 | */ |
| 139 | |
| 140 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 141 | resize_handler(struct widget *widget, |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 142 | int32_t width, int32_t height, void *data) |
| 143 | { |
| 144 | struct eventdemo *e = data; |
| 145 | if (log_resize) |
| 146 | printf("resize width: %d, height: %d\n", width, height); |
| 147 | |
| 148 | /* if a maximum width is set, constrain to it */ |
| 149 | if (width_max && width_max < width) |
| 150 | width = width_max; |
| 151 | |
| 152 | /* if a maximum height is set, constrain to it */ |
| 153 | if (height_max && height_max < height) |
| 154 | height = height_max; |
| 155 | |
| 156 | /* set the new window dimensions */ |
Kristian Høgsberg | bb97700 | 2012-01-10 19:11:42 -0500 | [diff] [blame] | 157 | widget_set_size(e->widget, width, height); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /** |
| 161 | * \brief CALLBACK function, Wayland informs about keyboard focus change |
| 162 | * \param window window |
| 163 | * \param device device that caused the focus change |
| 164 | * \param data user data associated to the window |
| 165 | */ |
| 166 | static void |
| 167 | keyboard_focus_handler(struct window *window, |
| 168 | struct input *device, void *data) |
| 169 | { |
| 170 | int32_t x, y; |
| 171 | struct eventdemo *e = data; |
| 172 | |
| 173 | if(log_focus) { |
| 174 | if(device) { |
| 175 | input_get_position(device, &x, &y); |
| 176 | printf("focus x: %d, y: %d\n", x, y); |
| 177 | } else { |
| 178 | printf("focus lost\n"); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | window_schedule_redraw(e->window); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * \brief CALLBACK function, Wayland informs about key event |
| 187 | * \param window window |
| 188 | * \param key keycode |
| 189 | * \param unicode associated character |
| 190 | * \param state pressed or released |
| 191 | * \param modifiers modifiers: ctrl, alt, meta etc. |
| 192 | * \param data user data associated to the window |
| 193 | */ |
| 194 | static void |
| 195 | key_handler(struct window *window, struct input *input, uint32_t time, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 196 | uint32_t key, uint32_t unicode, enum wl_keyboard_key_state state, |
| 197 | void *data) |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 198 | { |
| 199 | uint32_t modifiers = input_get_modifiers(input); |
| 200 | |
| 201 | if(!log_key) |
| 202 | return; |
| 203 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 204 | printf("key key: %d, unicode: %d, state: %s, modifiers: 0x%x\n", |
| 205 | key, unicode, |
| 206 | (state == WL_KEYBOARD_KEY_STATE_PRESSED) ? "pressed" : |
| 207 | "released", |
| 208 | modifiers); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /** |
| 212 | * \brief CALLBACK function, Wayland informs about button event |
Philipp Brüschweiler | 850f504 | 2012-08-14 11:02:39 +0200 | [diff] [blame] | 213 | * \param widget widget |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 214 | * \param input input device that caused the button event |
Martin Olsson | 3b132e3 | 2012-09-29 15:13:56 +0200 | [diff] [blame] | 215 | * \param time time the event happened |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 216 | * \param button button |
| 217 | * \param state pressed or released |
| 218 | * \param data user data associated to the window |
| 219 | */ |
| 220 | static void |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 221 | button_handler(struct widget *widget, struct input *input, uint32_t time, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 222 | uint32_t button, enum wl_pointer_button_state state, void *data) |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 223 | { |
| 224 | int32_t x, y; |
| 225 | |
| 226 | if (!log_button) |
| 227 | return; |
| 228 | |
| 229 | input_get_position(input, &x, &y); |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 230 | printf("button time: %d, button: %d, state: %s, x: %d, y: %d\n", |
| 231 | time, button, |
| 232 | (state == WL_POINTER_BUTTON_STATE_PRESSED) ? "pressed" : |
| 233 | "released", |
| 234 | x, y); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** |
Philipp Brüschweiler | 70cc73b | 2012-08-14 11:02:42 +0200 | [diff] [blame] | 238 | * \brief CALLBACK function, Wayland informs about axis event |
| 239 | * \param widget widget |
| 240 | * \param input input device that caused the axis event |
| 241 | * \param time time the event happened |
| 242 | * \param axis vertical or horizontal |
| 243 | * \param value amount of scrolling |
| 244 | * \param data user data associated to the widget |
| 245 | */ |
| 246 | static void |
| 247 | axis_handler(struct widget *widget, struct input *input, uint32_t time, |
| 248 | uint32_t axis, wl_fixed_t value, void *data) |
| 249 | { |
| 250 | if (!log_axis) |
| 251 | return; |
| 252 | |
| 253 | printf("axis time: %d, axis: %s, value: %f\n", |
| 254 | time, |
| 255 | axis == WL_POINTER_AXIS_VERTICAL_SCROLL ? "vertical" : |
| 256 | "horizontal", |
| 257 | wl_fixed_to_double(value)); |
| 258 | } |
| 259 | |
| 260 | /** |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 261 | * \brief CALLBACK function, Waylands informs about pointer motion |
Philipp Brüschweiler | 850f504 | 2012-08-14 11:02:39 +0200 | [diff] [blame] | 262 | * \param widget widget |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 263 | * \param input input device that caused the motion event |
Martin Olsson | 3b132e3 | 2012-09-29 15:13:56 +0200 | [diff] [blame] | 264 | * \param time time the event happened |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 265 | * \param x absolute x position |
| 266 | * \param y absolute y position |
| 267 | * \param sx x position relative to the window |
| 268 | * \param sy y position relative to the window |
| 269 | * \param data user data associated to the window |
| 270 | * |
| 271 | * Demonstrates the use of different cursors |
| 272 | */ |
| 273 | static int |
Kristian Høgsberg | 87a57bb | 2012-01-09 10:34:35 -0500 | [diff] [blame] | 274 | motion_handler(struct widget *widget, struct input *input, uint32_t time, |
Kristian Høgsberg | 80680c7 | 2012-05-10 12:21:37 -0400 | [diff] [blame] | 275 | float x, float y, void *data) |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 276 | { |
| 277 | struct eventdemo *e = data; |
| 278 | |
| 279 | if (log_motion) { |
Daniel Stone | b230a7e | 2012-05-08 17:17:54 +0100 | [diff] [blame] | 280 | printf("motion time: %d, x: %f, y: %f\n", time, x, y); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 281 | } |
| 282 | |
Kristian Høgsberg | 87a57bb | 2012-01-09 10:34:35 -0500 | [diff] [blame] | 283 | if (x > e->x && x < e->x + e->w) |
| 284 | if (y > e->y && y < e->y + e->h) |
Ander Conselvan de Oliveira | dc8c8fc | 2012-05-25 16:01:41 +0300 | [diff] [blame] | 285 | return CURSOR_HAND1; |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 286 | |
Ander Conselvan de Oliveira | dc8c8fc | 2012-05-25 16:01:41 +0300 | [diff] [blame] | 287 | return CURSOR_LEFT_PTR; |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /** |
| 291 | * \brief Create and initialise a new eventdemo window. |
Martin Olsson | c663b22 | 2012-07-08 11:11:18 +0200 | [diff] [blame] | 292 | * The returned eventdemo instance should be destroyed using \c eventdemo_destroy(). |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 293 | * \param d associated display |
| 294 | */ |
| 295 | static struct eventdemo * |
| 296 | eventdemo_create(struct display *d) |
| 297 | { |
| 298 | struct eventdemo *e; |
| 299 | |
| 300 | e = malloc(sizeof (struct eventdemo)); |
| 301 | if(e == NULL) |
| 302 | return NULL; |
| 303 | |
Kristian Høgsberg | 009ac0a | 2012-01-31 15:24:48 -0500 | [diff] [blame] | 304 | e->window = window_create(d); |
Philipp Brüschweiler | a306a26 | 2012-08-14 11:02:40 +0200 | [diff] [blame] | 305 | |
| 306 | if (noborder) { |
| 307 | /* Demonstrate how to create a borderless window. |
| 308 | * Move windows with META + left mouse button. |
| 309 | */ |
| 310 | e->widget = window_add_widget(e->window, e); |
| 311 | } else { |
Jason Ekstrand | ee7fefc | 2013-10-13 19:08:38 -0500 | [diff] [blame] | 312 | e->widget = window_frame_create(e->window, e); |
Philipp Brüschweiler | a306a26 | 2012-08-14 11:02:40 +0200 | [diff] [blame] | 313 | window_set_title(e->window, title); |
| 314 | } |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 315 | e->display = d; |
| 316 | |
| 317 | /* The eventdemo window draws a red rectangle as a demonstration |
| 318 | * of per-window data. The dimensions of that rectangle are set |
| 319 | * here. |
| 320 | */ |
| 321 | e->x = width * 1.0 / 4.0; |
| 322 | e->w = width * 2.0 / 4.0; |
| 323 | e->y = height * 1.0 / 4.0; |
| 324 | e->h = height * 2.0 / 4.0; |
| 325 | |
| 326 | /* Connect the user data to the window */ |
| 327 | window_set_user_data(e->window, e); |
| 328 | |
| 329 | /* Set the callback redraw handler for the window */ |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 330 | widget_set_redraw_handler(e->widget, redraw_handler); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 331 | |
| 332 | /* Set the callback resize handler for the window */ |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 333 | widget_set_resize_handler(e->widget, resize_handler); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 334 | |
| 335 | /* Set the callback focus handler for the window */ |
| 336 | window_set_keyboard_focus_handler(e->window, |
| 337 | keyboard_focus_handler); |
| 338 | |
| 339 | /* Set the callback key handler for the window */ |
| 340 | window_set_key_handler(e->window, key_handler); |
| 341 | |
| 342 | /* Set the callback button handler for the window */ |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 343 | widget_set_button_handler(e->widget, button_handler); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 344 | |
| 345 | /* Set the callback motion handler for the window */ |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 346 | widget_set_motion_handler(e->widget, motion_handler); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 347 | |
Philipp Brüschweiler | 70cc73b | 2012-08-14 11:02:42 +0200 | [diff] [blame] | 348 | /* Set the callback axis handler for the window */ |
| 349 | widget_set_axis_handler(e->widget, axis_handler); |
| 350 | |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 351 | /* Initial drawing of the window */ |
Kristian Høgsberg | 009ac0a | 2012-01-31 15:24:48 -0500 | [diff] [blame] | 352 | window_schedule_resize(e->window, width, height); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 353 | |
| 354 | return e; |
| 355 | } |
| 356 | /** |
Martin Olsson | c663b22 | 2012-07-08 11:11:18 +0200 | [diff] [blame] | 357 | * \brief Destroy eventdemo instance previously created by \c eventdemo_create(). |
| 358 | * \param eventdemo eventdemo instance to destroy |
| 359 | */ |
| 360 | static void eventdemo_destroy(struct eventdemo * eventdemo) |
| 361 | { |
| 362 | widget_destroy(eventdemo->widget); |
| 363 | window_destroy(eventdemo->window); |
| 364 | free(eventdemo); |
| 365 | } |
| 366 | /** |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 367 | * \brief command line options for eventdemo |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 368 | */ |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 369 | static const struct weston_option eventdemo_options[] = { |
| 370 | { WESTON_OPTION_STRING, "title", 0, &title }, |
| 371 | { WESTON_OPTION_INTEGER, "width", 'w', &width }, |
| 372 | { WESTON_OPTION_INTEGER, "height", 'h', &height }, |
| 373 | { WESTON_OPTION_INTEGER, "max-width", 0, &width_max }, |
| 374 | { WESTON_OPTION_INTEGER, "max-height", 0, &height_max }, |
| 375 | { WESTON_OPTION_BOOLEAN, "no-border", 'b', &noborder }, |
| 376 | { WESTON_OPTION_BOOLEAN, "log-redraw", '0', &log_redraw }, |
| 377 | { WESTON_OPTION_BOOLEAN, "log-resize", '0', &log_resize }, |
| 378 | { WESTON_OPTION_BOOLEAN, "log-focus", '0', &log_focus }, |
| 379 | { WESTON_OPTION_BOOLEAN, "log-key", '0', &log_key }, |
| 380 | { WESTON_OPTION_BOOLEAN, "log-button", '0', &log_button }, |
Philipp Brüschweiler | 70cc73b | 2012-08-14 11:02:42 +0200 | [diff] [blame] | 381 | { WESTON_OPTION_BOOLEAN, "log-axis", '0', &log_axis }, |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 382 | { WESTON_OPTION_BOOLEAN, "log-motion", '0', &log_motion }, |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | /** |
| 386 | * \brief Connects to the display, creates the window and hands over |
| 387 | * to the main loop. |
| 388 | */ |
| 389 | int |
| 390 | main(int argc, char *argv[]) |
| 391 | { |
| 392 | struct display *d; |
| 393 | struct eventdemo *e; |
| 394 | |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 395 | parse_options(eventdemo_options, |
| 396 | ARRAY_LENGTH(eventdemo_options), &argc, argv); |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 397 | |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 398 | /* Connect to the display and have the arguments parsed */ |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 399 | d = display_create(&argc, argv); |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 400 | if (d == NULL) { |
| 401 | fprintf(stderr, "failed to create display: %m\n"); |
| 402 | return -1; |
| 403 | } |
| 404 | |
| 405 | /* Create new eventdemo window */ |
| 406 | e = eventdemo_create(d); |
| 407 | if (e == NULL) { |
| 408 | fprintf(stderr, "failed to create eventdemo: %m\n"); |
| 409 | return -1; |
| 410 | } |
| 411 | |
| 412 | display_run(d); |
| 413 | |
Martin Olsson | c663b22 | 2012-07-08 11:11:18 +0200 | [diff] [blame] | 414 | /* Release resources */ |
| 415 | eventdemo_destroy(e); |
| 416 | display_destroy(d); |
| 417 | |
Tim Wiederhake | 503ccca | 2011-01-21 16:56:07 +0100 | [diff] [blame] | 418 | return 0; |
| 419 | } |