blob: d8eef5b532c8247fe6a220d688fa1a0d5d6b453c [file] [log] [blame]
Tim Wiederhake503ccca2011-01-21 16:56:07 +01001/*
2 * Copyright © 2011 Tim Wiederhake
3 *
Bryce Harrington1f6b0d12015-06-10 22:48:59 -07004 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
Tim Wiederhake503ccca2011-01-21 16:56:07 +010010 *
Bryce Harrington1f6b0d12015-06-10 22:48:59 -070011 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
Tim Wiederhake503ccca2011-01-21 16:56:07 +010022 */
23
24/**
25 * \file eventdemo.c
26 * \brief Demonstrate the use of Wayland's toytoolkit.
27 *
28 * Heavily commented demo program that can report all events that are
29 * dispatched to the window. For other functionality, eg. opengl/egl,
30 * drag and drop, etc. have a look at the other demos.
31 * \author Tim Wiederhake
32 */
33
Andrew Wedgbury9cd661e2014-04-07 12:40:35 +010034#include "config.h"
35
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030036#include <stdint.h>
Tim Wiederhake503ccca2011-01-21 16:56:07 +010037#include <stdio.h>
38#include <stdlib.h>
Pekka Paalanen43864992016-04-12 13:33:09 +030039#include <stdbool.h>
Tim Wiederhake503ccca2011-01-21 16:56:07 +010040
41#include <cairo.h>
Tim Wiederhake503ccca2011-01-21 16:56:07 +010042
Jon Cruz35b2eaa2015-06-15 15:37:08 -070043#include "shared/helpers.h"
Tim Wiederhake503ccca2011-01-21 16:56:07 +010044#include "window.h"
45
46/** window title */
47static char *title = "EventDemo";
48
49/** window width */
50static int width = 500;
51
52/** window height */
53static int height = 400;
54
55/** set if window has no borders */
56static int noborder = 0;
57
58/** if non-zero, maximum window width */
59static int width_max = 0;
60
61/** if non-zero, maximum window height */
62static int height_max = 0;
63
64/** set to log redrawing */
65static int log_redraw = 0;
66
67/** set to log resizing */
68static int log_resize = 0;
69
70/** set to log keyboard focus */
71static int log_focus = 0;
72
73/** set to log key events */
74static int log_key = 0;
75
76/** set to log button events */
77static int log_button = 0;
78
Philipp Brüschweiler70cc73b2012-08-14 11:02:42 +020079/** set to log axis events */
80static int log_axis = 0;
81
Tim Wiederhake503ccca2011-01-21 16:56:07 +010082/** set to log motion events */
83static int log_motion = 0;
84
85/**
86 * \struct eventdemo
87 * \brief Holds all data the program needs per window
88 *
89 * In this demo the struct holds the position of a
90 * red rectangle that is drawn in the window's area.
91 */
92struct eventdemo {
93 struct window *window;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -050094 struct widget *widget;
Tim Wiederhake503ccca2011-01-21 16:56:07 +010095 struct display *display;
96
Kristian Høgsberg875ab9e2012-03-30 11:52:39 -040097 int x, y, w, h;
Pekka Paalanen43864992016-04-12 13:33:09 +030098
99 bool print_pointer_frame;
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100100};
101
102/**
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500103 * \brief CALLBACK function, Wayland requests the window to redraw.
Philipp Brüschweiler850f5042012-08-14 11:02:39 +0200104 * \param widget widget to be redrawn
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500105 * \param data user data associated to the window
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100106 *
107 * Draws a red rectangle as demonstration of per-window data.
108 */
109static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500110redraw_handler(struct widget *widget, void *data)
111{
112 struct eventdemo *e = data;
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100113 cairo_surface_t *surface;
114 cairo_t *cr;
115 struct rectangle rect;
116
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500117 if (log_redraw)
118 printf("redraw\n");
119
Kristian Høgsbergbb977002012-01-10 19:11:42 -0500120 widget_get_allocation(e->widget, &rect);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100121 surface = window_get_surface(e->window);
122
123 cr = cairo_create(surface);
124 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
125
126 cairo_rectangle(cr, rect.x, rect.y, rect.width, rect.height);
127 cairo_set_source_rgba(cr, 0, 0, 0, 0.8);
128 cairo_fill(cr);
129
130 cairo_rectangle(cr, e->x, e->y, e->w, e->h);
131 cairo_set_source_rgba(cr, 1.0, 0, 0, 1);
132 cairo_fill(cr);
133
134 cairo_destroy(cr);
135 cairo_surface_destroy(surface);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100136}
137
138/**
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100139 * \brief CALLBACK function, Wayland requests the window to resize.
Philipp Brüschweiler850f5042012-08-14 11:02:39 +0200140 * \param widget widget to be resized
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100141 * \param width desired width
142 * \param height desired height
143 * \param data user data associated to the window
144 */
145
146static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500147resize_handler(struct widget *widget,
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100148 int32_t width, int32_t height, void *data)
149{
150 struct eventdemo *e = data;
151 if (log_resize)
152 printf("resize width: %d, height: %d\n", width, height);
153
154 /* if a maximum width is set, constrain to it */
155 if (width_max && width_max < width)
156 width = width_max;
157
158 /* if a maximum height is set, constrain to it */
159 if (height_max && height_max < height)
160 height = height_max;
161
162 /* set the new window dimensions */
Kristian Høgsbergbb977002012-01-10 19:11:42 -0500163 widget_set_size(e->widget, width, height);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100164}
165
166/**
167 * \brief CALLBACK function, Wayland informs about keyboard focus change
168 * \param window window
169 * \param device device that caused the focus change
170 * \param data user data associated to the window
171 */
172static void
173keyboard_focus_handler(struct window *window,
174 struct input *device, void *data)
175{
176 int32_t x, y;
177 struct eventdemo *e = data;
178
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300179 if (log_focus) {
180 if (device) {
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100181 input_get_position(device, &x, &y);
182 printf("focus x: %d, y: %d\n", x, y);
183 } else {
184 printf("focus lost\n");
185 }
186 }
187
188 window_schedule_redraw(e->window);
189}
190
191/**
192 * \brief CALLBACK function, Wayland informs about key event
193 * \param window window
194 * \param key keycode
195 * \param unicode associated character
196 * \param state pressed or released
197 * \param modifiers modifiers: ctrl, alt, meta etc.
198 * \param data user data associated to the window
199 */
200static void
201key_handler(struct window *window, struct input *input, uint32_t time,
Daniel Stonec9785ea2012-05-30 16:31:52 +0100202 uint32_t key, uint32_t unicode, enum wl_keyboard_key_state state,
203 void *data)
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100204{
205 uint32_t modifiers = input_get_modifiers(input);
206
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300207 if (!log_key)
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100208 return;
209
Pekka Paalanen901ac322016-05-13 14:07:20 +0300210 printf("key key: %u, unicode: %u, state: %s, modifiers: 0x%x\n",
Daniel Stonec9785ea2012-05-30 16:31:52 +0100211 key, unicode,
212 (state == WL_KEYBOARD_KEY_STATE_PRESSED) ? "pressed" :
213 "released",
214 modifiers);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100215}
216
217/**
218 * \brief CALLBACK function, Wayland informs about button event
Philipp Brüschweiler850f5042012-08-14 11:02:39 +0200219 * \param widget widget
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100220 * \param input input device that caused the button event
Martin Olsson3b132e32012-09-29 15:13:56 +0200221 * \param time time the event happened
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100222 * \param button button
223 * \param state pressed or released
224 * \param data user data associated to the window
225 */
226static void
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500227button_handler(struct widget *widget, struct input *input, uint32_t time,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100228 uint32_t button, enum wl_pointer_button_state state, void *data)
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100229{
Pekka Paalanen43864992016-04-12 13:33:09 +0300230 struct eventdemo *e = data;
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100231 int32_t x, y;
232
233 if (!log_button)
234 return;
235
Pekka Paalanen43864992016-04-12 13:33:09 +0300236 e->print_pointer_frame = true;
237
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100238 input_get_position(input, &x, &y);
Pekka Paalanen901ac322016-05-13 14:07:20 +0300239 printf("button time: %u, button: %u, state: %s, x: %d, y: %d\n",
Daniel Stone4dbadb12012-05-30 16:31:51 +0100240 time, button,
241 (state == WL_POINTER_BUTTON_STATE_PRESSED) ? "pressed" :
242 "released",
243 x, y);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100244}
245
246/**
Philipp Brüschweiler70cc73b2012-08-14 11:02:42 +0200247 * \brief CALLBACK function, Wayland informs about axis event
248 * \param widget widget
249 * \param input input device that caused the axis event
250 * \param time time the event happened
251 * \param axis vertical or horizontal
252 * \param value amount of scrolling
253 * \param data user data associated to the widget
254 */
255static void
256axis_handler(struct widget *widget, struct input *input, uint32_t time,
257 uint32_t axis, wl_fixed_t value, void *data)
258{
Pekka Paalanen43864992016-04-12 13:33:09 +0300259 struct eventdemo *e = data;
260
Philipp Brüschweiler70cc73b2012-08-14 11:02:42 +0200261 if (!log_axis)
262 return;
263
Pekka Paalanen43864992016-04-12 13:33:09 +0300264 e->print_pointer_frame = true;
265
Pekka Paalanen901ac322016-05-13 14:07:20 +0300266 printf("axis time: %u, axis: %s, value: %f\n",
Philipp Brüschweiler70cc73b2012-08-14 11:02:42 +0200267 time,
268 axis == WL_POINTER_AXIS_VERTICAL_SCROLL ? "vertical" :
269 "horizontal",
270 wl_fixed_to_double(value));
271}
272
Peter Hutterer87743e92016-01-18 16:38:22 +1000273static void
274pointer_frame_handler(struct widget *widget, struct input *input, void *data)
275{
Pekka Paalanen43864992016-04-12 13:33:09 +0300276 struct eventdemo *e = data;
277
278 if (!e->print_pointer_frame)
279 return;
280
Peter Hutterer87743e92016-01-18 16:38:22 +1000281 printf("pointer frame\n");
Pekka Paalanen43864992016-04-12 13:33:09 +0300282 e->print_pointer_frame = false;
Peter Hutterer87743e92016-01-18 16:38:22 +1000283}
284
285static void
286axis_source_handler(struct widget *widget, struct input *input,
287 uint32_t source, void *data)
288{
289 const char *axis_source;
Pekka Paalanen43864992016-04-12 13:33:09 +0300290 struct eventdemo *e = data;
291
Pekka Paalanen0baffb02016-04-12 13:53:55 +0300292 if (!log_axis)
293 return;
294
Pekka Paalanen43864992016-04-12 13:33:09 +0300295 e->print_pointer_frame = true;
Peter Hutterer87743e92016-01-18 16:38:22 +1000296
297 switch (source) {
298 case WL_POINTER_AXIS_SOURCE_WHEEL:
299 axis_source = "wheel";
300 break;
301 case WL_POINTER_AXIS_SOURCE_FINGER:
302 axis_source = "finger";
303 break;
304 case WL_POINTER_AXIS_SOURCE_CONTINUOUS:
305 axis_source = "continuous";
306 break;
307 default:
308 axis_source = "<invalid source value>";
309 break;
310 }
311
312 printf("axis source: %s\n", axis_source);
313}
314
315static void
316axis_stop_handler(struct widget *widget, struct input *input,
317 uint32_t time, uint32_t axis,
318 void *data)
319{
Pekka Paalanen43864992016-04-12 13:33:09 +0300320 struct eventdemo *e = data;
321
Pekka Paalanen0baffb02016-04-12 13:53:55 +0300322 if (!log_axis)
323 return;
324
Pekka Paalanen43864992016-04-12 13:33:09 +0300325 e->print_pointer_frame = true;
Pekka Paalanen901ac322016-05-13 14:07:20 +0300326 printf("axis stop time: %u, axis: %s\n",
Peter Hutterer87743e92016-01-18 16:38:22 +1000327 time,
328 axis == WL_POINTER_AXIS_VERTICAL_SCROLL ? "vertical" :
329 "horizontal");
330}
331
332static void
333axis_discrete_handler(struct widget *widget, struct input *input,
334 uint32_t axis, int32_t discrete, void *data)
335{
Pekka Paalanen43864992016-04-12 13:33:09 +0300336 struct eventdemo *e = data;
337
Pekka Paalanen0baffb02016-04-12 13:53:55 +0300338 if (!log_axis)
339 return;
340
Pekka Paalanen43864992016-04-12 13:33:09 +0300341 e->print_pointer_frame = true;
Pekka Paalanen901ac322016-05-13 14:07:20 +0300342 printf("axis discrete axis: %u value: %d\n", axis, discrete);
Peter Hutterer87743e92016-01-18 16:38:22 +1000343}
344
Philipp Brüschweiler70cc73b2012-08-14 11:02:42 +0200345/**
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100346 * \brief CALLBACK function, Waylands informs about pointer motion
Philipp Brüschweiler850f5042012-08-14 11:02:39 +0200347 * \param widget widget
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100348 * \param input input device that caused the motion event
Martin Olsson3b132e32012-09-29 15:13:56 +0200349 * \param time time the event happened
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100350 * \param x absolute x position
351 * \param y absolute y position
352 * \param sx x position relative to the window
353 * \param sy y position relative to the window
354 * \param data user data associated to the window
355 *
356 * Demonstrates the use of different cursors
357 */
358static int
Kristian Høgsberg87a57bb2012-01-09 10:34:35 -0500359motion_handler(struct widget *widget, struct input *input, uint32_t time,
Kristian Høgsberg80680c72012-05-10 12:21:37 -0400360 float x, float y, void *data)
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100361{
362 struct eventdemo *e = data;
363
364 if (log_motion) {
Pekka Paalanen901ac322016-05-13 14:07:20 +0300365 printf("motion time: %u, x: %f, y: %f\n", time, x, y);
Pekka Paalanen43864992016-04-12 13:33:09 +0300366 e->print_pointer_frame = true;
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100367 }
368
Kristian Høgsberg87a57bb2012-01-09 10:34:35 -0500369 if (x > e->x && x < e->x + e->w)
370 if (y > e->y && y < e->y + e->h)
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300371 return CURSOR_HAND1;
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100372
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300373 return CURSOR_LEFT_PTR;
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100374}
375
376/**
377 * \brief Create and initialise a new eventdemo window.
Martin Olssonc663b222012-07-08 11:11:18 +0200378 * The returned eventdemo instance should be destroyed using \c eventdemo_destroy().
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100379 * \param d associated display
380 */
381static struct eventdemo *
382eventdemo_create(struct display *d)
383{
384 struct eventdemo *e;
385
Pekka Paalanen10e92db2016-04-12 13:49:53 +0300386 e = zalloc(sizeof (struct eventdemo));
Dawid Gajownik74a635b2015-08-06 17:12:19 -0300387 if (e == NULL)
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100388 return NULL;
389
Kristian Høgsberg009ac0a2012-01-31 15:24:48 -0500390 e->window = window_create(d);
Philipp Brüschweilera306a262012-08-14 11:02:40 +0200391
392 if (noborder) {
393 /* Demonstrate how to create a borderless window.
394 * Move windows with META + left mouse button.
395 */
396 e->widget = window_add_widget(e->window, e);
397 } else {
Jason Ekstrandee7fefc2013-10-13 19:08:38 -0500398 e->widget = window_frame_create(e->window, e);
Philipp Brüschweilera306a262012-08-14 11:02:40 +0200399 window_set_title(e->window, title);
400 }
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100401 e->display = d;
402
403 /* The eventdemo window draws a red rectangle as a demonstration
404 * of per-window data. The dimensions of that rectangle are set
405 * here.
406 */
407 e->x = width * 1.0 / 4.0;
408 e->w = width * 2.0 / 4.0;
409 e->y = height * 1.0 / 4.0;
410 e->h = height * 2.0 / 4.0;
411
412 /* Connect the user data to the window */
413 window_set_user_data(e->window, e);
414
415 /* Set the callback redraw handler for the window */
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500416 widget_set_redraw_handler(e->widget, redraw_handler);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100417
418 /* Set the callback resize handler for the window */
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500419 widget_set_resize_handler(e->widget, resize_handler);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100420
421 /* Set the callback focus handler for the window */
422 window_set_keyboard_focus_handler(e->window,
423 keyboard_focus_handler);
424
425 /* Set the callback key handler for the window */
426 window_set_key_handler(e->window, key_handler);
427
428 /* Set the callback button handler for the window */
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500429 widget_set_button_handler(e->widget, button_handler);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100430
431 /* Set the callback motion handler for the window */
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500432 widget_set_motion_handler(e->widget, motion_handler);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100433
Peter Hutterer87743e92016-01-18 16:38:22 +1000434 /* Set the callback pointer frame handler for the window */
435 widget_set_pointer_frame_handler(e->widget, pointer_frame_handler);
436
Philipp Brüschweiler70cc73b2012-08-14 11:02:42 +0200437 /* Set the callback axis handler for the window */
Peter Hutterer87743e92016-01-18 16:38:22 +1000438 widget_set_axis_handlers(e->widget,
439 axis_handler,
440 axis_source_handler,
441 axis_stop_handler,
442 axis_discrete_handler);
Philipp Brüschweiler70cc73b2012-08-14 11:02:42 +0200443
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100444 /* Initial drawing of the window */
Kristian Høgsberg009ac0a2012-01-31 15:24:48 -0500445 window_schedule_resize(e->window, width, height);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100446
447 return e;
448}
449/**
Martin Olssonc663b222012-07-08 11:11:18 +0200450 * \brief Destroy eventdemo instance previously created by \c eventdemo_create().
451 * \param eventdemo eventdemo instance to destroy
452 */
453static void eventdemo_destroy(struct eventdemo * eventdemo)
454{
455 widget_destroy(eventdemo->widget);
456 window_destroy(eventdemo->window);
457 free(eventdemo);
458}
459/**
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100460 * \brief command line options for eventdemo
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100461 */
Kristian Høgsbergbcacef12012-03-11 21:05:57 -0400462static const struct weston_option eventdemo_options[] = {
463 { WESTON_OPTION_STRING, "title", 0, &title },
464 { WESTON_OPTION_INTEGER, "width", 'w', &width },
465 { WESTON_OPTION_INTEGER, "height", 'h', &height },
466 { WESTON_OPTION_INTEGER, "max-width", 0, &width_max },
467 { WESTON_OPTION_INTEGER, "max-height", 0, &height_max },
468 { WESTON_OPTION_BOOLEAN, "no-border", 'b', &noborder },
Bill Spitzak4fb84912014-08-08 12:59:51 -0700469 { WESTON_OPTION_BOOLEAN, "log-redraw", 0, &log_redraw },
470 { WESTON_OPTION_BOOLEAN, "log-resize", 0, &log_resize },
471 { WESTON_OPTION_BOOLEAN, "log-focus", 0, &log_focus },
472 { WESTON_OPTION_BOOLEAN, "log-key", 0, &log_key },
473 { WESTON_OPTION_BOOLEAN, "log-button", 0, &log_button },
474 { WESTON_OPTION_BOOLEAN, "log-axis", 0, &log_axis },
475 { WESTON_OPTION_BOOLEAN, "log-motion", 0, &log_motion },
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100476};
477
478/**
479 * \brief Connects to the display, creates the window and hands over
480 * to the main loop.
481 */
482int
483main(int argc, char *argv[])
484{
485 struct display *d;
486 struct eventdemo *e;
487
Bill Spitzak4fb84912014-08-08 12:59:51 -0700488 if (parse_options(eventdemo_options,
489 ARRAY_LENGTH(eventdemo_options), &argc, argv) > 1) {
490 unsigned k;
491 printf("Usage: %s [OPTIONS]\n\n", argv[0]);
492 for (k = 0; k < ARRAY_LENGTH(eventdemo_options); k++) {
493 const struct weston_option* p = &eventdemo_options[k];
494 if (p->name) {
495 printf(" --%s", p->name);
496 if (p->type != WESTON_OPTION_BOOLEAN)
497 printf("=VALUE");
498 putchar('\n');
499 }
500 if (p->short_name) {
501 printf(" -%c", p->short_name);
502 if (p->type != WESTON_OPTION_BOOLEAN)
503 printf("VALUE");
504 putchar('\n');
505 }
506 }
507 return 1;
508 }
509
510 if (!log_redraw && !log_resize && !log_focus && !log_key &&
511 !log_button && !log_axis && !log_motion)
512 log_redraw = log_resize = log_focus = log_key =
513 log_button = log_axis = log_motion = 1;
Kristian Høgsbergbcacef12012-03-11 21:05:57 -0400514
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100515 /* Connect to the display and have the arguments parsed */
Kristian Høgsberg4172f662013-02-20 15:27:49 -0500516 d = display_create(&argc, argv);
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100517 if (d == NULL) {
518 fprintf(stderr, "failed to create display: %m\n");
519 return -1;
520 }
521
522 /* Create new eventdemo window */
523 e = eventdemo_create(d);
524 if (e == NULL) {
525 fprintf(stderr, "failed to create eventdemo: %m\n");
526 return -1;
527 }
528
529 display_run(d);
530
Martin Olssonc663b222012-07-08 11:11:18 +0200531 /* Release resources */
532 eventdemo_destroy(e);
533 display_destroy(d);
534
Tim Wiederhake503ccca2011-01-21 16:56:07 +0100535 return 0;
536}