2011-01-21 18:56:07 +03:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 Tim Wiederhake
|
|
|
|
*
|
2015-06-11 08:48:59 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2011-01-21 18:56:07 +03:00
|
|
|
*
|
2015-06-11 08:48:59 +03:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2011-01-21 18:56:07 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file eventdemo.c
|
|
|
|
* \brief Demonstrate the use of Wayland's toytoolkit.
|
|
|
|
*
|
|
|
|
* Heavily commented demo program that can report all events that are
|
|
|
|
* dispatched to the window. For other functionality, eg. opengl/egl,
|
|
|
|
* drag and drop, etc. have a look at the other demos.
|
|
|
|
* \author Tim Wiederhake
|
|
|
|
*/
|
|
|
|
|
2014-04-07 15:40:35 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2011-01-21 18:56:07 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-04-12 13:33:09 +03:00
|
|
|
#include <stdbool.h>
|
2019-04-27 00:57:31 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
#include <cairo.h>
|
|
|
|
|
2015-06-16 01:37:08 +03:00
|
|
|
#include "shared/helpers.h"
|
2011-01-21 18:56:07 +03:00
|
|
|
#include "window.h"
|
|
|
|
|
|
|
|
/** window title */
|
|
|
|
static char *title = "EventDemo";
|
clients/window: Add functions to set/retrieve app_id
Adds appid for all clients using the toolkit, flower, fullscreen, image,
resizor, scaler, smoke, stacking, subsurfaces, terminal,
touch-calibrator, transformed, etc.
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-09-09 13:52:18 +03:00
|
|
|
static char *appid = "org.freedesktop.weston.eventdemo";
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/** window width */
|
|
|
|
static int width = 500;
|
|
|
|
|
|
|
|
/** window height */
|
|
|
|
static int height = 400;
|
|
|
|
|
|
|
|
/** set if window has no borders */
|
2019-11-26 03:32:22 +03:00
|
|
|
static bool noborder = false;
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/** if non-zero, maximum window width */
|
|
|
|
static int width_max = 0;
|
|
|
|
|
|
|
|
/** if non-zero, maximum window height */
|
|
|
|
static int height_max = 0;
|
|
|
|
|
|
|
|
/** set to log redrawing */
|
2019-11-26 03:32:22 +03:00
|
|
|
static bool log_redraw = false;
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/** set to log resizing */
|
2019-11-26 03:32:22 +03:00
|
|
|
static bool log_resize = false;
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/** set to log keyboard focus */
|
2019-11-26 03:32:22 +03:00
|
|
|
static bool log_focus = false;
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/** set to log key events */
|
2019-11-26 03:32:22 +03:00
|
|
|
static bool log_key = false;
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/** set to log button events */
|
2019-11-26 03:32:22 +03:00
|
|
|
static bool log_button = false;
|
2011-01-21 18:56:07 +03:00
|
|
|
|
2012-08-14 13:02:42 +04:00
|
|
|
/** set to log axis events */
|
2019-11-26 03:32:22 +03:00
|
|
|
static bool log_axis = false;
|
2012-08-14 13:02:42 +04:00
|
|
|
|
2011-01-21 18:56:07 +03:00
|
|
|
/** set to log motion events */
|
2019-11-26 03:32:22 +03:00
|
|
|
static bool log_motion = false;
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \struct eventdemo
|
|
|
|
* \brief Holds all data the program needs per window
|
|
|
|
*
|
|
|
|
* In this demo the struct holds the position of a
|
|
|
|
* red rectangle that is drawn in the window's area.
|
|
|
|
*/
|
|
|
|
struct eventdemo {
|
|
|
|
struct window *window;
|
2012-01-10 18:43:58 +04:00
|
|
|
struct widget *widget;
|
2011-01-21 18:56:07 +03:00
|
|
|
struct display *display;
|
|
|
|
|
2012-03-30 19:52:39 +04:00
|
|
|
int x, y, w, h;
|
2016-04-12 13:33:09 +03:00
|
|
|
|
|
|
|
bool print_pointer_frame;
|
2011-01-21 18:56:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-01-10 21:23:19 +04:00
|
|
|
* \brief CALLBACK function, Wayland requests the window to redraw.
|
2012-08-14 13:02:39 +04:00
|
|
|
* \param widget widget to be redrawn
|
2012-01-10 21:23:19 +04:00
|
|
|
* \param data user data associated to the window
|
2011-01-21 18:56:07 +03:00
|
|
|
*
|
|
|
|
* Draws a red rectangle as demonstration of per-window data.
|
|
|
|
*/
|
|
|
|
static void
|
2012-01-10 21:23:19 +04:00
|
|
|
redraw_handler(struct widget *widget, void *data)
|
|
|
|
{
|
|
|
|
struct eventdemo *e = data;
|
2011-01-21 18:56:07 +03:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
struct rectangle rect;
|
|
|
|
|
2012-01-10 21:23:19 +04:00
|
|
|
if (log_redraw)
|
|
|
|
printf("redraw\n");
|
|
|
|
|
2012-01-11 04:11:42 +04:00
|
|
|
widget_get_allocation(e->widget, &rect);
|
2011-01-21 18:56:07 +03:00
|
|
|
surface = window_get_surface(e->window);
|
|
|
|
|
|
|
|
cr = cairo_create(surface);
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
|
|
|
|
cairo_rectangle(cr, rect.x, rect.y, rect.width, rect.height);
|
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 0.8);
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
|
|
|
cairo_rectangle(cr, e->x, e->y, e->w, e->h);
|
|
|
|
cairo_set_source_rgba(cr, 1.0, 0, 0, 1);
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
cairo_surface_destroy(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief CALLBACK function, Wayland requests the window to resize.
|
2012-08-14 13:02:39 +04:00
|
|
|
* \param widget widget to be resized
|
2011-01-21 18:56:07 +03:00
|
|
|
* \param width desired width
|
|
|
|
* \param height desired height
|
|
|
|
* \param data user data associated to the window
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2012-01-10 21:23:19 +04:00
|
|
|
resize_handler(struct widget *widget,
|
2011-01-21 18:56:07 +03:00
|
|
|
int32_t width, int32_t height, void *data)
|
|
|
|
{
|
|
|
|
struct eventdemo *e = data;
|
|
|
|
if (log_resize)
|
|
|
|
printf("resize width: %d, height: %d\n", width, height);
|
|
|
|
|
|
|
|
/* if a maximum width is set, constrain to it */
|
|
|
|
if (width_max && width_max < width)
|
|
|
|
width = width_max;
|
|
|
|
|
|
|
|
/* if a maximum height is set, constrain to it */
|
|
|
|
if (height_max && height_max < height)
|
|
|
|
height = height_max;
|
|
|
|
|
|
|
|
/* set the new window dimensions */
|
2012-01-11 04:11:42 +04:00
|
|
|
widget_set_size(e->widget, width, height);
|
2011-01-21 18:56:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief CALLBACK function, Wayland informs about keyboard focus change
|
|
|
|
* \param window window
|
|
|
|
* \param device device that caused the focus change
|
|
|
|
* \param data user data associated to the window
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
keyboard_focus_handler(struct window *window,
|
|
|
|
struct input *device, void *data)
|
|
|
|
{
|
|
|
|
int32_t x, y;
|
|
|
|
struct eventdemo *e = data;
|
|
|
|
|
2015-08-06 23:12:19 +03:00
|
|
|
if (log_focus) {
|
|
|
|
if (device) {
|
2011-01-21 18:56:07 +03:00
|
|
|
input_get_position(device, &x, &y);
|
|
|
|
printf("focus x: %d, y: %d\n", x, y);
|
|
|
|
} else {
|
|
|
|
printf("focus lost\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window_schedule_redraw(e->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief CALLBACK function, Wayland informs about key event
|
|
|
|
* \param window window
|
2019-06-14 13:04:52 +03:00
|
|
|
* \param input input
|
|
|
|
* \param time time
|
2011-01-21 18:56:07 +03:00
|
|
|
* \param key keycode
|
|
|
|
* \param unicode associated character
|
|
|
|
* \param state pressed or released
|
|
|
|
* \param data user data associated to the window
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
key_handler(struct window *window, struct input *input, uint32_t time,
|
2012-05-30 19:31:52 +04:00
|
|
|
uint32_t key, uint32_t unicode, enum wl_keyboard_key_state state,
|
|
|
|
void *data)
|
2011-01-21 18:56:07 +03:00
|
|
|
{
|
|
|
|
uint32_t modifiers = input_get_modifiers(input);
|
|
|
|
|
2015-08-06 23:12:19 +03:00
|
|
|
if (!log_key)
|
2011-01-21 18:56:07 +03:00
|
|
|
return;
|
|
|
|
|
2016-05-13 14:07:20 +03:00
|
|
|
printf("key key: %u, unicode: %u, state: %s, modifiers: 0x%x\n",
|
2012-05-30 19:31:52 +04:00
|
|
|
key, unicode,
|
|
|
|
(state == WL_KEYBOARD_KEY_STATE_PRESSED) ? "pressed" :
|
|
|
|
"released",
|
|
|
|
modifiers);
|
2011-01-21 18:56:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief CALLBACK function, Wayland informs about button event
|
2012-08-14 13:02:39 +04:00
|
|
|
* \param widget widget
|
2011-01-21 18:56:07 +03:00
|
|
|
* \param input input device that caused the button event
|
2012-09-29 17:13:56 +04:00
|
|
|
* \param time time the event happened
|
2011-01-21 18:56:07 +03:00
|
|
|
* \param button button
|
|
|
|
* \param state pressed or released
|
|
|
|
* \param data user data associated to the window
|
|
|
|
*/
|
|
|
|
static void
|
2012-01-09 20:12:05 +04:00
|
|
|
button_handler(struct widget *widget, struct input *input, uint32_t time,
|
2012-05-30 19:31:51 +04:00
|
|
|
uint32_t button, enum wl_pointer_button_state state, void *data)
|
2011-01-21 18:56:07 +03:00
|
|
|
{
|
2016-04-12 13:33:09 +03:00
|
|
|
struct eventdemo *e = data;
|
2011-01-21 18:56:07 +03:00
|
|
|
int32_t x, y;
|
|
|
|
|
|
|
|
if (!log_button)
|
|
|
|
return;
|
|
|
|
|
2016-04-12 13:33:09 +03:00
|
|
|
e->print_pointer_frame = true;
|
|
|
|
|
2011-01-21 18:56:07 +03:00
|
|
|
input_get_position(input, &x, &y);
|
2016-05-13 14:07:20 +03:00
|
|
|
printf("button time: %u, button: %u, state: %s, x: %d, y: %d\n",
|
2012-05-30 19:31:51 +04:00
|
|
|
time, button,
|
|
|
|
(state == WL_POINTER_BUTTON_STATE_PRESSED) ? "pressed" :
|
|
|
|
"released",
|
|
|
|
x, y);
|
2011-01-21 18:56:07 +03:00
|
|
|
}
|
|
|
|
|
2012-08-14 13:02:42 +04:00
|
|
|
/**
|
|
|
|
* \brief CALLBACK function, Wayland informs about axis event
|
|
|
|
* \param widget widget
|
|
|
|
* \param input input device that caused the axis event
|
|
|
|
* \param time time the event happened
|
|
|
|
* \param axis vertical or horizontal
|
|
|
|
* \param value amount of scrolling
|
|
|
|
* \param data user data associated to the widget
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
axis_handler(struct widget *widget, struct input *input, uint32_t time,
|
|
|
|
uint32_t axis, wl_fixed_t value, void *data)
|
|
|
|
{
|
2016-04-12 13:33:09 +03:00
|
|
|
struct eventdemo *e = data;
|
|
|
|
|
2012-08-14 13:02:42 +04:00
|
|
|
if (!log_axis)
|
|
|
|
return;
|
|
|
|
|
2016-04-12 13:33:09 +03:00
|
|
|
e->print_pointer_frame = true;
|
|
|
|
|
2016-05-13 14:07:20 +03:00
|
|
|
printf("axis time: %u, axis: %s, value: %f\n",
|
2012-08-14 13:02:42 +04:00
|
|
|
time,
|
|
|
|
axis == WL_POINTER_AXIS_VERTICAL_SCROLL ? "vertical" :
|
|
|
|
"horizontal",
|
|
|
|
wl_fixed_to_double(value));
|
|
|
|
}
|
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
static void
|
|
|
|
pointer_frame_handler(struct widget *widget, struct input *input, void *data)
|
|
|
|
{
|
2016-04-12 13:33:09 +03:00
|
|
|
struct eventdemo *e = data;
|
|
|
|
|
|
|
|
if (!e->print_pointer_frame)
|
|
|
|
return;
|
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
printf("pointer frame\n");
|
2016-04-12 13:33:09 +03:00
|
|
|
e->print_pointer_frame = false;
|
2016-01-18 09:38:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
axis_source_handler(struct widget *widget, struct input *input,
|
|
|
|
uint32_t source, void *data)
|
|
|
|
{
|
|
|
|
const char *axis_source;
|
2016-04-12 13:33:09 +03:00
|
|
|
struct eventdemo *e = data;
|
|
|
|
|
2016-04-12 13:53:55 +03:00
|
|
|
if (!log_axis)
|
|
|
|
return;
|
|
|
|
|
2016-04-12 13:33:09 +03:00
|
|
|
e->print_pointer_frame = true;
|
2016-01-18 09:38:22 +03:00
|
|
|
|
|
|
|
switch (source) {
|
|
|
|
case WL_POINTER_AXIS_SOURCE_WHEEL:
|
|
|
|
axis_source = "wheel";
|
|
|
|
break;
|
|
|
|
case WL_POINTER_AXIS_SOURCE_FINGER:
|
|
|
|
axis_source = "finger";
|
|
|
|
break;
|
|
|
|
case WL_POINTER_AXIS_SOURCE_CONTINUOUS:
|
|
|
|
axis_source = "continuous";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
axis_source = "<invalid source value>";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("axis source: %s\n", axis_source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
axis_stop_handler(struct widget *widget, struct input *input,
|
|
|
|
uint32_t time, uint32_t axis,
|
|
|
|
void *data)
|
|
|
|
{
|
2016-04-12 13:33:09 +03:00
|
|
|
struct eventdemo *e = data;
|
|
|
|
|
2016-04-12 13:53:55 +03:00
|
|
|
if (!log_axis)
|
|
|
|
return;
|
|
|
|
|
2016-04-12 13:33:09 +03:00
|
|
|
e->print_pointer_frame = true;
|
2016-05-13 14:07:20 +03:00
|
|
|
printf("axis stop time: %u, axis: %s\n",
|
2016-01-18 09:38:22 +03:00
|
|
|
time,
|
|
|
|
axis == WL_POINTER_AXIS_VERTICAL_SCROLL ? "vertical" :
|
|
|
|
"horizontal");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
axis_discrete_handler(struct widget *widget, struct input *input,
|
|
|
|
uint32_t axis, int32_t discrete, void *data)
|
|
|
|
{
|
2016-04-12 13:33:09 +03:00
|
|
|
struct eventdemo *e = data;
|
|
|
|
|
2016-04-12 13:53:55 +03:00
|
|
|
if (!log_axis)
|
|
|
|
return;
|
|
|
|
|
2016-04-12 13:33:09 +03:00
|
|
|
e->print_pointer_frame = true;
|
2016-05-13 14:07:20 +03:00
|
|
|
printf("axis discrete axis: %u value: %d\n", axis, discrete);
|
2016-01-18 09:38:22 +03:00
|
|
|
}
|
|
|
|
|
2011-01-21 18:56:07 +03:00
|
|
|
/**
|
|
|
|
* \brief CALLBACK function, Waylands informs about pointer motion
|
2012-08-14 13:02:39 +04:00
|
|
|
* \param widget widget
|
2011-01-21 18:56:07 +03:00
|
|
|
* \param input input device that caused the motion event
|
2012-09-29 17:13:56 +04:00
|
|
|
* \param time time the event happened
|
2011-01-21 18:56:07 +03:00
|
|
|
* \param x absolute x position
|
|
|
|
* \param y absolute y position
|
2019-06-14 13:04:52 +03:00
|
|
|
* \param x x position relative to the window
|
|
|
|
* \param y y position relative to the window
|
2011-01-21 18:56:07 +03:00
|
|
|
* \param data user data associated to the window
|
|
|
|
*
|
|
|
|
* Demonstrates the use of different cursors
|
|
|
|
*/
|
|
|
|
static int
|
2012-01-09 19:34:35 +04:00
|
|
|
motion_handler(struct widget *widget, struct input *input, uint32_t time,
|
2012-05-10 20:21:37 +04:00
|
|
|
float x, float y, void *data)
|
2011-01-21 18:56:07 +03:00
|
|
|
{
|
|
|
|
struct eventdemo *e = data;
|
|
|
|
|
|
|
|
if (log_motion) {
|
2016-05-13 14:07:20 +03:00
|
|
|
printf("motion time: %u, x: %f, y: %f\n", time, x, y);
|
2016-04-12 13:33:09 +03:00
|
|
|
e->print_pointer_frame = true;
|
2011-01-21 18:56:07 +03:00
|
|
|
}
|
|
|
|
|
2012-01-09 19:34:35 +04:00
|
|
|
if (x > e->x && x < e->x + e->w)
|
|
|
|
if (y > e->y && y < e->y + e->h)
|
2012-05-25 17:01:41 +04:00
|
|
|
return CURSOR_HAND1;
|
2011-01-21 18:56:07 +03:00
|
|
|
|
2012-05-25 17:01:41 +04:00
|
|
|
return CURSOR_LEFT_PTR;
|
2011-01-21 18:56:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Create and initialise a new eventdemo window.
|
2012-07-08 13:11:18 +04:00
|
|
|
* The returned eventdemo instance should be destroyed using \c eventdemo_destroy().
|
2011-01-21 18:56:07 +03:00
|
|
|
* \param d associated display
|
|
|
|
*/
|
|
|
|
static struct eventdemo *
|
|
|
|
eventdemo_create(struct display *d)
|
|
|
|
{
|
|
|
|
struct eventdemo *e;
|
|
|
|
|
2016-04-12 13:49:53 +03:00
|
|
|
e = zalloc(sizeof (struct eventdemo));
|
2015-08-06 23:12:19 +03:00
|
|
|
if (e == NULL)
|
2011-01-21 18:56:07 +03:00
|
|
|
return NULL;
|
|
|
|
|
2012-02-01 00:24:48 +04:00
|
|
|
e->window = window_create(d);
|
2012-08-14 13:02:40 +04:00
|
|
|
|
|
|
|
if (noborder) {
|
|
|
|
/* Demonstrate how to create a borderless window.
|
|
|
|
* Move windows with META + left mouse button.
|
|
|
|
*/
|
|
|
|
e->widget = window_add_widget(e->window, e);
|
|
|
|
} else {
|
2013-10-14 04:08:38 +04:00
|
|
|
e->widget = window_frame_create(e->window, e);
|
2012-08-14 13:02:40 +04:00
|
|
|
window_set_title(e->window, title);
|
clients/window: Add functions to set/retrieve app_id
Adds appid for all clients using the toolkit, flower, fullscreen, image,
resizor, scaler, smoke, stacking, subsurfaces, terminal,
touch-calibrator, transformed, etc.
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-09-09 13:52:18 +03:00
|
|
|
window_set_appid(e->window, appid);
|
2012-08-14 13:02:40 +04:00
|
|
|
}
|
2011-01-21 18:56:07 +03:00
|
|
|
e->display = d;
|
|
|
|
|
|
|
|
/* The eventdemo window draws a red rectangle as a demonstration
|
|
|
|
* of per-window data. The dimensions of that rectangle are set
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
e->x = width * 1.0 / 4.0;
|
|
|
|
e->w = width * 2.0 / 4.0;
|
|
|
|
e->y = height * 1.0 / 4.0;
|
|
|
|
e->h = height * 2.0 / 4.0;
|
|
|
|
|
|
|
|
/* Connect the user data to the window */
|
|
|
|
window_set_user_data(e->window, e);
|
|
|
|
|
|
|
|
/* Set the callback redraw handler for the window */
|
2012-01-10 21:23:19 +04:00
|
|
|
widget_set_redraw_handler(e->widget, redraw_handler);
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/* Set the callback resize handler for the window */
|
2012-01-10 21:23:19 +04:00
|
|
|
widget_set_resize_handler(e->widget, resize_handler);
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/* Set the callback focus handler for the window */
|
|
|
|
window_set_keyboard_focus_handler(e->window,
|
|
|
|
keyboard_focus_handler);
|
|
|
|
|
|
|
|
/* Set the callback key handler for the window */
|
|
|
|
window_set_key_handler(e->window, key_handler);
|
|
|
|
|
|
|
|
/* Set the callback button handler for the window */
|
2012-01-10 18:43:58 +04:00
|
|
|
widget_set_button_handler(e->widget, button_handler);
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
/* Set the callback motion handler for the window */
|
2012-01-10 18:43:58 +04:00
|
|
|
widget_set_motion_handler(e->widget, motion_handler);
|
2011-01-21 18:56:07 +03:00
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
/* Set the callback pointer frame handler for the window */
|
|
|
|
widget_set_pointer_frame_handler(e->widget, pointer_frame_handler);
|
|
|
|
|
2012-08-14 13:02:42 +04:00
|
|
|
/* Set the callback axis handler for the window */
|
2016-01-18 09:38:22 +03:00
|
|
|
widget_set_axis_handlers(e->widget,
|
|
|
|
axis_handler,
|
|
|
|
axis_source_handler,
|
|
|
|
axis_stop_handler,
|
|
|
|
axis_discrete_handler);
|
2012-08-14 13:02:42 +04:00
|
|
|
|
2011-01-21 18:56:07 +03:00
|
|
|
/* Initial drawing of the window */
|
2012-02-01 00:24:48 +04:00
|
|
|
window_schedule_resize(e->window, width, height);
|
2011-01-21 18:56:07 +03:00
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
2012-07-08 13:11:18 +04:00
|
|
|
/**
|
|
|
|
* \brief Destroy eventdemo instance previously created by \c eventdemo_create().
|
|
|
|
* \param eventdemo eventdemo instance to destroy
|
|
|
|
*/
|
|
|
|
static void eventdemo_destroy(struct eventdemo * eventdemo)
|
|
|
|
{
|
|
|
|
widget_destroy(eventdemo->widget);
|
|
|
|
window_destroy(eventdemo->window);
|
|
|
|
free(eventdemo);
|
|
|
|
}
|
2011-01-21 18:56:07 +03:00
|
|
|
/**
|
|
|
|
* \brief command line options for eventdemo
|
|
|
|
*/
|
2012-03-12 05:05:57 +04:00
|
|
|
static const struct weston_option eventdemo_options[] = {
|
|
|
|
{ WESTON_OPTION_STRING, "title", 0, &title },
|
|
|
|
{ WESTON_OPTION_INTEGER, "width", 'w', &width },
|
|
|
|
{ WESTON_OPTION_INTEGER, "height", 'h', &height },
|
|
|
|
{ WESTON_OPTION_INTEGER, "max-width", 0, &width_max },
|
|
|
|
{ WESTON_OPTION_INTEGER, "max-height", 0, &height_max },
|
|
|
|
{ WESTON_OPTION_BOOLEAN, "no-border", 'b', &noborder },
|
2014-08-08 23:59:51 +04:00
|
|
|
{ WESTON_OPTION_BOOLEAN, "log-redraw", 0, &log_redraw },
|
|
|
|
{ WESTON_OPTION_BOOLEAN, "log-resize", 0, &log_resize },
|
|
|
|
{ WESTON_OPTION_BOOLEAN, "log-focus", 0, &log_focus },
|
|
|
|
{ WESTON_OPTION_BOOLEAN, "log-key", 0, &log_key },
|
|
|
|
{ WESTON_OPTION_BOOLEAN, "log-button", 0, &log_button },
|
|
|
|
{ WESTON_OPTION_BOOLEAN, "log-axis", 0, &log_axis },
|
|
|
|
{ WESTON_OPTION_BOOLEAN, "log-motion", 0, &log_motion },
|
2011-01-21 18:56:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Connects to the display, creates the window and hands over
|
|
|
|
* to the main loop.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct display *d;
|
|
|
|
struct eventdemo *e;
|
|
|
|
|
2014-08-08 23:59:51 +04:00
|
|
|
if (parse_options(eventdemo_options,
|
|
|
|
ARRAY_LENGTH(eventdemo_options), &argc, argv) > 1) {
|
|
|
|
unsigned k;
|
|
|
|
printf("Usage: %s [OPTIONS]\n\n", argv[0]);
|
|
|
|
for (k = 0; k < ARRAY_LENGTH(eventdemo_options); k++) {
|
|
|
|
const struct weston_option* p = &eventdemo_options[k];
|
|
|
|
if (p->name) {
|
|
|
|
printf(" --%s", p->name);
|
|
|
|
if (p->type != WESTON_OPTION_BOOLEAN)
|
|
|
|
printf("=VALUE");
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (p->short_name) {
|
|
|
|
printf(" -%c", p->short_name);
|
|
|
|
if (p->type != WESTON_OPTION_BOOLEAN)
|
|
|
|
printf("VALUE");
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!log_redraw && !log_resize && !log_focus && !log_key &&
|
|
|
|
!log_button && !log_axis && !log_motion)
|
|
|
|
log_redraw = log_resize = log_focus = log_key =
|
2019-11-26 03:32:22 +03:00
|
|
|
log_button = log_axis = log_motion = true;
|
2012-03-12 05:05:57 +04:00
|
|
|
|
2011-01-21 18:56:07 +03:00
|
|
|
/* Connect to the display and have the arguments parsed */
|
2013-02-21 00:27:49 +04:00
|
|
|
d = display_create(&argc, argv);
|
2011-01-21 18:56:07 +03:00
|
|
|
if (d == NULL) {
|
2019-04-27 00:57:31 +03:00
|
|
|
fprintf(stderr, "failed to create display: %s\n",
|
|
|
|
strerror(errno));
|
2011-01-21 18:56:07 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create new eventdemo window */
|
|
|
|
e = eventdemo_create(d);
|
|
|
|
if (e == NULL) {
|
2019-04-27 00:57:31 +03:00
|
|
|
fprintf(stderr, "failed to create eventdemo: %s\n",
|
|
|
|
strerror(errno));
|
2011-01-21 18:56:07 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
display_run(d);
|
|
|
|
|
2012-07-08 13:11:18 +04:00
|
|
|
/* Release resources */
|
|
|
|
eventdemo_destroy(e);
|
|
|
|
display_destroy(d);
|
|
|
|
|
2011-01-21 18:56:07 +03:00
|
|
|
return 0;
|
|
|
|
}
|