1/* swc: libswc/pointer.h
2 *
3 * Copyright (c) 2013, 2014 Michael Forney
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the 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 THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24#ifndef SWC_POINTER_H
25#define SWC_POINTER_H
26
27#include "input.h"
28#include "view.h"
29
30#include <pixman.h>
31#include <wayland-server.h>
32
33struct button {
34 struct press press;
35 struct pointer_handler *handler;
36};
37
38struct pointer_handler {
39 bool (*motion)(struct pointer_handler *handler, uint32_t time, wl_fixed_t x,
40 wl_fixed_t y);
41 bool (*button)(struct pointer_handler *handler, uint32_t time,
42 struct button *button, uint32_t state);
43 bool (*axis)(struct pointer_handler *handler, uint32_t time,
44 enum wl_pointer_axis axis, enum wl_pointer_axis_source source,
45 wl_fixed_t value, int value120);
46 void (*frame)(struct pointer_handler *handler);
47
48 int pending;
49 struct wl_list link;
50};
51
52struct pointer {
53 struct input_focus focus;
54 struct input_focus_handler focus_handler;
55
56 struct {
57 struct view view;
58 struct surface *surface;
59 struct wl_listener destroy_listener;
60 struct wld_buffer *buffer;
61
62 /* Used for cursors set with pointer_set_cursor */
63 struct wld_buffer *internal_buffer;
64
65 struct {
66 int32_t x, y;
67 } hotspot;
68 } cursor;
69
70 struct wl_array buttons;
71 struct wl_list handlers;
72 struct pointer_handler client_handler;
73 enum wl_pointer_axis_source client_axis_source;
74
75 wl_fixed_t x, y;
76 pixman_region32_t region;
77};
78
79bool
80pointer_initialize(struct pointer *pointer);
81void
82pointer_finalize(struct pointer *pointer);
83void
84pointer_set_focus(struct pointer *pointer, struct compositor_view *view);
85void
86pointer_set_region(struct pointer *pointer, pixman_region32_t *region);
87void
88pointer_set_cursor(struct pointer *pointer, uint32_t id);
89
90struct button *
91pointer_get_button(struct pointer *pointer, uint32_t serial);
92
93struct wl_resource *
94pointer_bind(struct pointer *pointer, struct wl_client *client,
95 uint32_t version, uint32_t id);
96void
97pointer_handle_button(struct pointer *pointer, uint32_t time, uint32_t button,
98 uint32_t state);
99void
100pointer_handle_axis(struct pointer *pointer, uint32_t time,
101 enum wl_pointer_axis axis,
102 enum wl_pointer_axis_source source, wl_fixed_t value,
103 int value120);
104void
105pointer_handle_relative_motion(struct pointer *pointer, uint32_t time,
106 wl_fixed_t dx, wl_fixed_t dy);
107void
108pointer_handle_absolute_motion(struct pointer *pointer, uint32_t time,
109 wl_fixed_t x, wl_fixed_t y);
110void
111pointer_handle_frame(struct pointer *pointer);
112
113#endif