Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Intel Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Daniel Stone | 8e7a8bd | 2013-08-15 01:10:24 +0100 | [diff] [blame] | 23 | #include "config.h" |
| 24 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | #include <stdint.h> |
| 27 | #include <string.h> |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 28 | #include <sys/mman.h> |
| 29 | #include <assert.h> |
| 30 | #include <unistd.h> |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 31 | #include <fcntl.h> |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 32 | #include <limits.h> |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 33 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 34 | #include "../shared/os-compatibility.h" |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 35 | #include "compositor.h" |
| 36 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 37 | static void |
| 38 | empty_region(pixman_region32_t *region) |
| 39 | { |
| 40 | pixman_region32_fini(region); |
| 41 | pixman_region32_init(region); |
| 42 | } |
| 43 | |
| 44 | static void unbind_resource(struct wl_resource *resource) |
| 45 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 46 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Jonas Ådahl | 3042ffe | 2013-10-17 23:04:08 +0200 | [diff] [blame] | 49 | WL_EXPORT void |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 50 | weston_seat_repick(struct weston_seat *seat) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 51 | { |
Kristian Høgsberg | da751b8 | 2013-07-04 00:58:07 -0400 | [diff] [blame] | 52 | const struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 53 | |
Kristian Høgsberg | da751b8 | 2013-07-04 00:58:07 -0400 | [diff] [blame] | 54 | if (pointer == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 55 | return; |
| 56 | |
Kristian Høgsberg | da751b8 | 2013-07-04 00:58:07 -0400 | [diff] [blame] | 57 | pointer->grab->interface->focus(seat->pointer->grab); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static void |
| 61 | weston_compositor_idle_inhibit(struct weston_compositor *compositor) |
| 62 | { |
| 63 | weston_compositor_wake(compositor); |
| 64 | compositor->idle_inhibit++; |
| 65 | } |
| 66 | |
| 67 | static void |
| 68 | weston_compositor_idle_release(struct weston_compositor *compositor) |
| 69 | { |
| 70 | compositor->idle_inhibit--; |
| 71 | weston_compositor_wake(compositor); |
| 72 | } |
| 73 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 74 | static void |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 75 | pointer_focus_view_destroyed(struct wl_listener *listener, void *data) |
| 76 | { |
| 77 | struct weston_pointer *pointer = |
| 78 | container_of(listener, struct weston_pointer, |
| 79 | focus_view_listener); |
| 80 | |
| 81 | weston_pointer_set_focus(pointer, NULL, 0, 0); |
| 82 | } |
| 83 | |
| 84 | static void |
| 85 | pointer_focus_resource_destroyed(struct wl_listener *listener, void *data) |
| 86 | { |
| 87 | struct weston_pointer *pointer = |
| 88 | container_of(listener, struct weston_pointer, |
| 89 | focus_resource_listener); |
| 90 | |
| 91 | weston_pointer_set_focus(pointer, NULL, 0, 0); |
| 92 | } |
| 93 | |
| 94 | static void |
| 95 | keyboard_focus_resource_destroyed(struct wl_listener *listener, void *data) |
| 96 | { |
| 97 | struct weston_keyboard *keyboard = |
| 98 | container_of(listener, struct weston_keyboard, |
| 99 | focus_resource_listener); |
| 100 | |
| 101 | weston_keyboard_set_focus(keyboard, NULL); |
| 102 | } |
| 103 | |
| 104 | static void |
| 105 | touch_focus_view_destroyed(struct wl_listener *listener, void *data) |
| 106 | { |
| 107 | struct weston_touch *touch = |
| 108 | container_of(listener, struct weston_touch, |
| 109 | focus_view_listener); |
| 110 | |
| 111 | weston_touch_set_focus(touch->seat, NULL); |
| 112 | } |
| 113 | |
| 114 | static void |
| 115 | touch_focus_resource_destroyed(struct wl_listener *listener, void *data) |
| 116 | { |
| 117 | struct weston_touch *touch = |
| 118 | container_of(listener, struct weston_touch, |
| 119 | focus_resource_listener); |
| 120 | |
| 121 | weston_touch_set_focus(touch->seat, NULL); |
| 122 | } |
| 123 | |
| 124 | static void |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 125 | move_resources(struct wl_list *destination, struct wl_list *source) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 126 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 127 | wl_list_insert_list(destination, source); |
| 128 | wl_list_init(source); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 132 | move_resources_for_client(struct wl_list *destination, |
| 133 | struct wl_list *source, |
| 134 | struct wl_client *client) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 135 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 136 | struct wl_resource *resource, *tmp; |
| 137 | wl_resource_for_each_safe(resource, tmp, source) { |
| 138 | if (wl_resource_get_client(resource) == client) { |
| 139 | wl_list_remove(wl_resource_get_link(resource)); |
| 140 | wl_list_insert(destination, |
| 141 | wl_resource_get_link(resource)); |
| 142 | } |
| 143 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static void |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 147 | default_grab_pointer_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 148 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 149 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 150 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 151 | wl_fixed_t sx, sy; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 152 | |
| 153 | if (pointer->button_count > 0) |
| 154 | return; |
| 155 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 156 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 157 | pointer->x, pointer->y, |
| 158 | &sx, &sy); |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 159 | |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 160 | if (pointer->focus != view || pointer->sx != sx || pointer->sy != sy) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 161 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 165 | default_grab_pointer_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 166 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 167 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 168 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 169 | struct wl_list *resource_list; |
| 170 | struct wl_resource *resource; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 171 | |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 172 | if (pointer->focus) |
| 173 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 174 | &pointer->sx, &pointer->sy); |
| 175 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 176 | weston_pointer_move(pointer, x, y); |
| 177 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 178 | resource_list = &pointer->focus_resource_list; |
| 179 | wl_resource_for_each(resource, resource_list) { |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 180 | wl_pointer_send_motion(resource, time, |
| 181 | pointer->sx, pointer->sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 182 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static void |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 186 | default_grab_pointer_button(struct weston_pointer_grab *grab, |
| 187 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 188 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 189 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 190 | struct weston_compositor *compositor = pointer->seat->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 191 | struct weston_view *view; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 192 | struct wl_resource *resource; |
| 193 | uint32_t serial; |
| 194 | enum wl_pointer_button_state state = state_w; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 195 | struct wl_display *display = compositor->wl_display; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 196 | wl_fixed_t sx, sy; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 197 | struct wl_list *resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 198 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 199 | resource_list = &pointer->focus_resource_list; |
| 200 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 201 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 202 | wl_resource_for_each(resource, resource_list) |
| 203 | wl_pointer_send_button(resource, |
| 204 | serial, |
| 205 | time, |
| 206 | button, |
| 207 | state_w); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | if (pointer->button_count == 0 && |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 211 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 212 | view = weston_compositor_pick_view(compositor, |
| 213 | pointer->x, pointer->y, |
| 214 | &sx, &sy); |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 215 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 216 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 217 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 220 | static void |
| 221 | default_grab_pointer_cancel(struct weston_pointer_grab *grab) |
| 222 | { |
| 223 | } |
| 224 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 225 | static const struct weston_pointer_grab_interface |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 226 | default_pointer_grab_interface = { |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 227 | default_grab_pointer_focus, |
| 228 | default_grab_pointer_motion, |
| 229 | default_grab_pointer_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 230 | default_grab_pointer_cancel, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 231 | }; |
| 232 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 233 | static void |
| 234 | default_grab_touch_down(struct weston_touch_grab *grab, uint32_t time, |
| 235 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 236 | { |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 237 | struct weston_touch *touch = grab->touch; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 238 | struct wl_display *display = touch->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 239 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 240 | struct wl_resource *resource; |
| 241 | struct wl_list *resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 242 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 243 | resource_list = &touch->focus_resource_list; |
| 244 | |
| 245 | if (!wl_list_empty(resource_list) && touch->focus) { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 246 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 247 | wl_resource_for_each(resource, resource_list) |
| 248 | wl_touch_send_down(resource, serial, time, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 249 | touch->focus->surface->resource, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 250 | touch_id, sx, sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 254 | static void |
| 255 | default_grab_touch_up(struct weston_touch_grab *grab, |
| 256 | uint32_t time, int touch_id) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 257 | { |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 258 | struct weston_touch *touch = grab->touch; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 259 | struct wl_display *display = touch->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 260 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 261 | struct wl_resource *resource; |
| 262 | struct wl_list *resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 263 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 264 | resource_list = &touch->focus_resource_list; |
| 265 | |
| 266 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 267 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 268 | wl_resource_for_each(resource, resource_list) |
| 269 | wl_touch_send_up(resource, serial, time, touch_id); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 273 | static void |
| 274 | default_grab_touch_motion(struct weston_touch_grab *grab, uint32_t time, |
| 275 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 276 | { |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 277 | struct weston_touch *touch = grab->touch; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 278 | struct wl_resource *resource; |
| 279 | struct wl_list *resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 280 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 281 | resource_list = &touch->focus_resource_list; |
| 282 | |
| 283 | wl_resource_for_each(resource, resource_list) { |
| 284 | wl_touch_send_motion(resource, time, |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 285 | touch_id, sx, sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 289 | static void |
| 290 | default_grab_touch_cancel(struct weston_touch_grab *grab) |
| 291 | { |
| 292 | } |
| 293 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 294 | static const struct weston_touch_grab_interface default_touch_grab_interface = { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 295 | default_grab_touch_down, |
| 296 | default_grab_touch_up, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 297 | default_grab_touch_motion, |
| 298 | default_grab_touch_cancel, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | static void |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 302 | default_grab_keyboard_key(struct weston_keyboard_grab *grab, |
| 303 | uint32_t time, uint32_t key, uint32_t state) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 304 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 305 | struct weston_keyboard *keyboard = grab->keyboard; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 306 | struct wl_resource *resource; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 307 | struct wl_display *display = keyboard->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 308 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 309 | struct wl_list *resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 310 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 311 | resource_list = &keyboard->focus_resource_list; |
| 312 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 313 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 314 | wl_resource_for_each(resource, resource_list) |
| 315 | wl_keyboard_send_key(resource, |
| 316 | serial, |
| 317 | time, |
| 318 | key, |
| 319 | state); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | static void |
| 324 | send_modifiers_to_resource(struct weston_keyboard *keyboard, |
| 325 | struct wl_resource *resource, |
| 326 | uint32_t serial) |
| 327 | { |
| 328 | wl_keyboard_send_modifiers(resource, |
| 329 | serial, |
| 330 | keyboard->modifiers.mods_depressed, |
| 331 | keyboard->modifiers.mods_latched, |
| 332 | keyboard->modifiers.mods_locked, |
| 333 | keyboard->modifiers.group); |
| 334 | } |
| 335 | |
| 336 | static void |
| 337 | send_modifiers_to_client_in_list(struct wl_client *client, |
| 338 | struct wl_list *list, |
| 339 | uint32_t serial, |
| 340 | struct weston_keyboard *keyboard) |
| 341 | { |
| 342 | struct wl_resource *resource; |
| 343 | |
| 344 | wl_resource_for_each(resource, list) { |
| 345 | if (wl_resource_get_client(resource) == client) |
| 346 | send_modifiers_to_resource(keyboard, |
| 347 | resource, |
| 348 | serial); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
| 352 | static struct wl_resource * |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 353 | find_resource_for_surface(struct wl_list *list, struct weston_surface *surface) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 354 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 355 | if (!surface) |
| 356 | return NULL; |
| 357 | |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 358 | if (!surface->resource) |
| 359 | return NULL; |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 360 | |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 361 | return wl_resource_find_for_client(list, wl_resource_get_client(surface->resource)); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 362 | } |
| 363 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 364 | static struct wl_resource * |
| 365 | find_resource_for_view(struct wl_list *list, struct weston_view *view) |
| 366 | { |
| 367 | if (!view) |
| 368 | return NULL; |
| 369 | |
| 370 | return find_resource_for_surface(list, view->surface); |
| 371 | } |
| 372 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 373 | static void |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 374 | default_grab_keyboard_modifiers(struct weston_keyboard_grab *grab, |
| 375 | uint32_t serial, uint32_t mods_depressed, |
| 376 | uint32_t mods_latched, |
| 377 | uint32_t mods_locked, uint32_t group) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 378 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 379 | struct weston_keyboard *keyboard = grab->keyboard; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 380 | struct weston_pointer *pointer = grab->keyboard->seat->pointer; |
| 381 | struct wl_resource *resource; |
| 382 | struct wl_list *resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 383 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 384 | resource_list = &keyboard->focus_resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 385 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 386 | wl_resource_for_each(resource, resource_list) { |
| 387 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 388 | mods_latched, mods_locked, group); |
| 389 | } |
Jason Ekstrand | 42133d4 | 2013-11-14 20:06:16 -0600 | [diff] [blame] | 390 | if (pointer && pointer->focus && pointer->focus->surface->resource && |
| 391 | pointer->focus->surface != keyboard->focus) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 392 | struct wl_client *pointer_client = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 393 | wl_resource_get_client(pointer->focus->surface->resource); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 394 | send_modifiers_to_client_in_list(pointer_client, |
| 395 | &keyboard->resource_list, |
| 396 | serial, |
| 397 | keyboard); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 401 | static void |
| 402 | default_grab_keyboard_cancel(struct weston_keyboard_grab *grab) |
| 403 | { |
| 404 | } |
| 405 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 406 | static const struct weston_keyboard_grab_interface |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 407 | default_keyboard_grab_interface = { |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 408 | default_grab_keyboard_key, |
| 409 | default_grab_keyboard_modifiers, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 410 | default_grab_keyboard_cancel, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 411 | }; |
| 412 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 413 | static void |
| 414 | pointer_unmap_sprite(struct weston_pointer *pointer) |
| 415 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 416 | if (weston_surface_is_mapped(pointer->sprite->surface)) |
| 417 | weston_surface_unmap(pointer->sprite->surface); |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 418 | |
| 419 | wl_list_remove(&pointer->sprite_destroy_listener.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 420 | pointer->sprite->surface->configure = NULL; |
| 421 | pointer->sprite->surface->configure_private = NULL; |
| 422 | weston_view_destroy(pointer->sprite); |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 423 | pointer->sprite = NULL; |
| 424 | } |
| 425 | |
| 426 | static void |
| 427 | pointer_handle_sprite_destroy(struct wl_listener *listener, void *data) |
| 428 | { |
| 429 | struct weston_pointer *pointer = |
| 430 | container_of(listener, struct weston_pointer, |
| 431 | sprite_destroy_listener); |
| 432 | |
| 433 | pointer->sprite = NULL; |
| 434 | } |
| 435 | |
Jonas Ådahl | 3e12e63 | 2013-12-02 22:05:05 +0100 | [diff] [blame] | 436 | static void |
| 437 | weston_pointer_reset_state(struct weston_pointer *pointer) |
| 438 | { |
| 439 | pointer->button_count = 0; |
| 440 | } |
| 441 | |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 442 | static void |
| 443 | weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data); |
| 444 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 445 | WL_EXPORT struct weston_pointer * |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 446 | weston_pointer_create(struct weston_seat *seat) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 447 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 448 | struct weston_pointer *pointer; |
| 449 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 450 | pointer = zalloc(sizeof *pointer); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 451 | if (pointer == NULL) |
| 452 | return NULL; |
| 453 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 454 | wl_list_init(&pointer->resource_list); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 455 | wl_list_init(&pointer->focus_resource_list); |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 456 | weston_pointer_set_default_grab(pointer, |
| 457 | seat->compositor->default_pointer_grab); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 458 | wl_list_init(&pointer->focus_resource_listener.link); |
| 459 | pointer->focus_resource_listener.notify = pointer_focus_resource_destroyed; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 460 | pointer->default_grab.pointer = pointer; |
| 461 | pointer->grab = &pointer->default_grab; |
Giulio Camuffo | 6fcb378 | 2013-11-14 23:42:50 +0100 | [diff] [blame] | 462 | wl_signal_init(&pointer->motion_signal); |
Emilio Pozuelo Monfort | aa7a476 | 2013-11-19 11:37:15 +0100 | [diff] [blame] | 463 | wl_signal_init(&pointer->focus_signal); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 464 | wl_list_init(&pointer->focus_view_listener.link); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 465 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 466 | pointer->sprite_destroy_listener.notify = pointer_handle_sprite_destroy; |
| 467 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 468 | /* FIXME: Pick better co-ords. */ |
| 469 | pointer->x = wl_fixed_from_int(100); |
| 470 | pointer->y = wl_fixed_from_int(100); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 471 | |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 472 | pointer->output_destroy_listener.notify = |
| 473 | weston_pointer_handle_output_destroy; |
| 474 | wl_signal_add(&seat->compositor->output_destroyed_signal, |
| 475 | &pointer->output_destroy_listener); |
| 476 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 477 | return pointer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | WL_EXPORT void |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 481 | weston_pointer_destroy(struct weston_pointer *pointer) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 482 | { |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 483 | if (pointer->sprite) |
| 484 | pointer_unmap_sprite(pointer); |
| 485 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 486 | /* XXX: What about pointer->resource_list? */ |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 487 | |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 488 | wl_list_remove(&pointer->focus_resource_listener.link); |
| 489 | wl_list_remove(&pointer->focus_view_listener.link); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 490 | wl_list_remove(&pointer->output_destroy_listener.link); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 491 | free(pointer); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 492 | } |
| 493 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 494 | void |
| 495 | weston_pointer_set_default_grab(struct weston_pointer *pointer, |
| 496 | const struct weston_pointer_grab_interface *interface) |
| 497 | { |
| 498 | if (interface) |
| 499 | pointer->default_grab.interface = interface; |
| 500 | else |
| 501 | pointer->default_grab.interface = |
| 502 | &default_pointer_grab_interface; |
| 503 | } |
| 504 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 505 | WL_EXPORT struct weston_keyboard * |
| 506 | weston_keyboard_create(void) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 507 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 508 | struct weston_keyboard *keyboard; |
| 509 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 510 | keyboard = zalloc(sizeof *keyboard); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 511 | if (keyboard == NULL) |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 512 | return NULL; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 513 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 514 | wl_list_init(&keyboard->resource_list); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 515 | wl_list_init(&keyboard->focus_resource_list); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 516 | wl_list_init(&keyboard->focus_resource_listener.link); |
| 517 | keyboard->focus_resource_listener.notify = keyboard_focus_resource_destroyed; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 518 | wl_array_init(&keyboard->keys); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 519 | keyboard->default_grab.interface = &default_keyboard_grab_interface; |
| 520 | keyboard->default_grab.keyboard = keyboard; |
| 521 | keyboard->grab = &keyboard->default_grab; |
| 522 | wl_signal_init(&keyboard->focus_signal); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 523 | |
| 524 | return keyboard; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 525 | } |
| 526 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 527 | static void |
| 528 | weston_xkb_info_destroy(struct weston_xkb_info *xkb_info); |
| 529 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 530 | WL_EXPORT void |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 531 | weston_keyboard_destroy(struct weston_keyboard *keyboard) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 532 | { |
| 533 | /* XXX: What about keyboard->resource_list? */ |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 534 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 535 | #ifdef ENABLE_XKBCOMMON |
| 536 | if (keyboard->seat->compositor->use_xkbcommon) { |
| 537 | if (keyboard->xkb_state.state != NULL) |
| 538 | xkb_state_unref(keyboard->xkb_state.state); |
| 539 | if (keyboard->xkb_info) |
| 540 | weston_xkb_info_destroy(keyboard->xkb_info); |
| 541 | if (keyboard->pending_keymap) |
| 542 | xkb_keymap_unref(keyboard->pending_keymap); |
| 543 | } |
| 544 | #endif |
| 545 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 546 | wl_array_release(&keyboard->keys); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 547 | wl_list_remove(&keyboard->focus_resource_listener.link); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 548 | free(keyboard); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 549 | } |
| 550 | |
Jonas Ådahl | cbfa7f7 | 2013-12-02 22:05:04 +0100 | [diff] [blame] | 551 | static void |
| 552 | weston_touch_reset_state(struct weston_touch *touch) |
| 553 | { |
| 554 | touch->num_tp = 0; |
| 555 | } |
| 556 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 557 | WL_EXPORT struct weston_touch * |
| 558 | weston_touch_create(void) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 559 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 560 | struct weston_touch *touch; |
| 561 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 562 | touch = zalloc(sizeof *touch); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 563 | if (touch == NULL) |
| 564 | return NULL; |
| 565 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 566 | wl_list_init(&touch->resource_list); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 567 | wl_list_init(&touch->focus_resource_list); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 568 | wl_list_init(&touch->focus_view_listener.link); |
| 569 | touch->focus_view_listener.notify = touch_focus_view_destroyed; |
| 570 | wl_list_init(&touch->focus_resource_listener.link); |
| 571 | touch->focus_resource_listener.notify = touch_focus_resource_destroyed; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 572 | touch->default_grab.interface = &default_touch_grab_interface; |
| 573 | touch->default_grab.touch = touch; |
| 574 | touch->grab = &touch->default_grab; |
| 575 | wl_signal_init(&touch->focus_signal); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 576 | |
| 577 | return touch; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | WL_EXPORT void |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 581 | weston_touch_destroy(struct weston_touch *touch) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 582 | { |
| 583 | /* XXX: What about touch->resource_list? */ |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 584 | |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 585 | wl_list_remove(&touch->focus_view_listener.link); |
| 586 | wl_list_remove(&touch->focus_resource_listener.link); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 587 | free(touch); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 590 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 591 | seat_send_updated_caps(struct weston_seat *seat) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 592 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 593 | enum wl_seat_capability caps = 0; |
Rob Bradford | 6e737f5 | 2013-09-06 17:48:19 +0100 | [diff] [blame] | 594 | struct wl_resource *resource; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 595 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 596 | if (seat->pointer_device_count > 0) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 597 | caps |= WL_SEAT_CAPABILITY_POINTER; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 598 | if (seat->keyboard_device_count > 0) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 599 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 600 | if (seat->touch_device_count > 0) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 601 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 602 | |
Rob Bradford | 6e737f5 | 2013-09-06 17:48:19 +0100 | [diff] [blame] | 603 | wl_resource_for_each(resource, &seat->base_resource_list) { |
| 604 | wl_seat_send_capabilities(resource, caps); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 605 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 609 | weston_pointer_set_focus(struct weston_pointer *pointer, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 610 | struct weston_view *view, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 611 | wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 612 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 613 | struct weston_keyboard *kbd = pointer->seat->keyboard; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 614 | struct wl_resource *resource; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 615 | struct wl_display *display = pointer->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 616 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 617 | struct wl_list *focus_resource_list; |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 618 | int refocus = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 619 | |
| 620 | if ((!pointer->focus && view) || |
| 621 | (pointer->focus && !view) || |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 622 | (pointer->focus && pointer->focus->surface != view->surface) || |
| 623 | pointer->sx != sx || pointer->sy != sy) |
| 624 | refocus = 1; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 625 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 626 | focus_resource_list = &pointer->focus_resource_list; |
| 627 | |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 628 | if (!wl_list_empty(focus_resource_list) && refocus) { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 629 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 630 | wl_resource_for_each(resource, focus_resource_list) { |
| 631 | wl_pointer_send_leave(resource, serial, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 632 | pointer->focus->surface->resource); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | move_resources(&pointer->resource_list, focus_resource_list); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 636 | } |
| 637 | |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 638 | if (find_resource_for_view(&pointer->resource_list, view) && refocus) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 639 | struct wl_client *surface_client = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 640 | wl_resource_get_client(view->surface->resource); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 641 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 642 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 643 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 644 | if (kbd && kbd->focus != view->surface) |
Kristian Høgsberg | cb406f1 | 2013-10-09 10:54:03 -0700 | [diff] [blame] | 645 | send_modifiers_to_client_in_list(surface_client, |
| 646 | &kbd->resource_list, |
| 647 | serial, |
| 648 | kbd); |
| 649 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 650 | move_resources_for_client(focus_resource_list, |
| 651 | &pointer->resource_list, |
| 652 | surface_client); |
| 653 | |
| 654 | wl_resource_for_each(resource, focus_resource_list) { |
| 655 | wl_pointer_send_enter(resource, |
| 656 | serial, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 657 | view->surface->resource, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 658 | sx, sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 659 | } |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 660 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 661 | pointer->focus_serial = serial; |
| 662 | } |
| 663 | |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 664 | wl_list_remove(&pointer->focus_view_listener.link); |
| 665 | wl_list_init(&pointer->focus_view_listener.link); |
| 666 | wl_list_remove(&pointer->focus_resource_listener.link); |
| 667 | wl_list_init(&pointer->focus_resource_listener.link); |
Emilio Pozuelo Monfort | aa7a476 | 2013-11-19 11:37:15 +0100 | [diff] [blame] | 668 | if (view) |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 669 | wl_signal_add(&view->destroy_signal, &pointer->focus_view_listener); |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 670 | if (view && view->surface->resource) |
| 671 | wl_resource_add_destroy_listener(view->surface->resource, |
| 672 | &pointer->focus_resource_listener); |
| 673 | |
| 674 | pointer->focus = view; |
| 675 | pointer->focus_view_listener.notify = pointer_focus_view_destroyed; |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 676 | pointer->sx = sx; |
| 677 | pointer->sy = sy; |
| 678 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 679 | wl_signal_emit(&pointer->focus_signal, pointer); |
| 680 | } |
| 681 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 682 | static void |
| 683 | send_enter_to_resource_list(struct wl_list *list, |
| 684 | struct weston_keyboard *keyboard, |
| 685 | struct weston_surface *surface, |
| 686 | uint32_t serial) |
| 687 | { |
| 688 | struct wl_resource *resource; |
| 689 | |
| 690 | wl_resource_for_each(resource, list) { |
| 691 | send_modifiers_to_resource(keyboard, resource, serial); |
| 692 | wl_keyboard_send_enter(resource, serial, |
| 693 | surface->resource, |
| 694 | &keyboard->keys); |
| 695 | } |
| 696 | } |
| 697 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 698 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 699 | weston_keyboard_set_focus(struct weston_keyboard *keyboard, |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 700 | struct weston_surface *surface) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 701 | { |
| 702 | struct wl_resource *resource; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 703 | struct wl_display *display = keyboard->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 704 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 705 | struct wl_list *focus_resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 706 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 707 | focus_resource_list = &keyboard->focus_resource_list; |
| 708 | |
| 709 | if (!wl_list_empty(focus_resource_list) && keyboard->focus != surface) { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 710 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 711 | wl_resource_for_each(resource, focus_resource_list) { |
| 712 | wl_keyboard_send_leave(resource, serial, |
| 713 | keyboard->focus->resource); |
| 714 | } |
| 715 | move_resources(&keyboard->resource_list, focus_resource_list); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 716 | } |
| 717 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 718 | if (find_resource_for_surface(&keyboard->resource_list, surface) && |
| 719 | keyboard->focus != surface) { |
| 720 | struct wl_client *surface_client = |
| 721 | wl_resource_get_client(surface->resource); |
| 722 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 723 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 724 | |
| 725 | move_resources_for_client(focus_resource_list, |
| 726 | &keyboard->resource_list, |
| 727 | surface_client); |
| 728 | send_enter_to_resource_list(focus_resource_list, |
| 729 | keyboard, |
| 730 | surface, |
| 731 | serial); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 732 | keyboard->focus_serial = serial; |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | wl_list_remove(&keyboard->focus_resource_listener.link); |
| 736 | wl_list_init(&keyboard->focus_resource_listener.link); |
| 737 | if (surface && surface->resource) |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 738 | wl_resource_add_destroy_listener(surface->resource, |
| 739 | &keyboard->focus_resource_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 740 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 741 | keyboard->focus = surface; |
| 742 | wl_signal_emit(&keyboard->focus_signal, keyboard); |
| 743 | } |
| 744 | |
| 745 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 746 | weston_keyboard_start_grab(struct weston_keyboard *keyboard, |
| 747 | struct weston_keyboard_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 748 | { |
| 749 | keyboard->grab = grab; |
| 750 | grab->keyboard = keyboard; |
| 751 | |
| 752 | /* XXX focus? */ |
| 753 | } |
| 754 | |
| 755 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 756 | weston_keyboard_end_grab(struct weston_keyboard *keyboard) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 757 | { |
| 758 | keyboard->grab = &keyboard->default_grab; |
| 759 | } |
| 760 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 761 | static void |
| 762 | weston_keyboard_cancel_grab(struct weston_keyboard *keyboard) |
| 763 | { |
| 764 | keyboard->grab->interface->cancel(keyboard->grab); |
| 765 | } |
| 766 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 767 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 768 | weston_pointer_start_grab(struct weston_pointer *pointer, |
| 769 | struct weston_pointer_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 770 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 771 | pointer->grab = grab; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 772 | grab->pointer = pointer; |
Kristian Høgsberg | da751b8 | 2013-07-04 00:58:07 -0400 | [diff] [blame] | 773 | pointer->grab->interface->focus(pointer->grab); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 777 | weston_pointer_end_grab(struct weston_pointer *pointer) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 778 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 779 | pointer->grab = &pointer->default_grab; |
Kristian Høgsberg | da751b8 | 2013-07-04 00:58:07 -0400 | [diff] [blame] | 780 | pointer->grab->interface->focus(pointer->grab); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 781 | } |
| 782 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 783 | static void |
| 784 | weston_pointer_cancel_grab(struct weston_pointer *pointer) |
| 785 | { |
| 786 | pointer->grab->interface->cancel(pointer->grab); |
| 787 | } |
| 788 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 789 | WL_EXPORT void |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 790 | weston_touch_start_grab(struct weston_touch *touch, struct weston_touch_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 791 | { |
| 792 | touch->grab = grab; |
| 793 | grab->touch = touch; |
| 794 | } |
| 795 | |
| 796 | WL_EXPORT void |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 797 | weston_touch_end_grab(struct weston_touch *touch) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 798 | { |
| 799 | touch->grab = &touch->default_grab; |
| 800 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 801 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 802 | static void |
| 803 | weston_touch_cancel_grab(struct weston_touch *touch) |
| 804 | { |
| 805 | touch->grab->interface->cancel(touch->grab); |
| 806 | } |
| 807 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 808 | static void |
| 809 | weston_pointer_clamp_for_output(struct weston_pointer *pointer, |
| 810 | struct weston_output *output, |
| 811 | wl_fixed_t *fx, wl_fixed_t *fy) |
| 812 | { |
| 813 | int x, y; |
| 814 | |
| 815 | x = wl_fixed_to_int(*fx); |
| 816 | y = wl_fixed_to_int(*fy); |
| 817 | |
| 818 | if (x < output->x) |
| 819 | *fx = wl_fixed_from_int(output->x); |
| 820 | else if (x >= output->x + output->width) |
| 821 | *fx = wl_fixed_from_int(output->x + |
| 822 | output->width - 1); |
| 823 | if (y < output->y) |
| 824 | *fy = wl_fixed_from_int(output->y); |
| 825 | else if (y >= output->y + output->height) |
| 826 | *fy = wl_fixed_from_int(output->y + |
| 827 | output->height - 1); |
| 828 | } |
| 829 | |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 830 | WL_EXPORT void |
| 831 | weston_pointer_clamp(struct weston_pointer *pointer, wl_fixed_t *fx, wl_fixed_t *fy) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 832 | { |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 833 | struct weston_compositor *ec = pointer->seat->compositor; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 834 | struct weston_output *output, *prev = NULL; |
| 835 | int x, y, old_x, old_y, valid = 0; |
| 836 | |
| 837 | x = wl_fixed_to_int(*fx); |
| 838 | y = wl_fixed_to_int(*fy); |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 839 | old_x = wl_fixed_to_int(pointer->x); |
| 840 | old_y = wl_fixed_to_int(pointer->y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 841 | |
| 842 | wl_list_for_each(output, &ec->output_list, link) { |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 843 | if (pointer->seat->output && pointer->seat->output != output) |
| 844 | continue; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 845 | if (pixman_region32_contains_point(&output->region, |
| 846 | x, y, NULL)) |
| 847 | valid = 1; |
| 848 | if (pixman_region32_contains_point(&output->region, |
| 849 | old_x, old_y, NULL)) |
| 850 | prev = output; |
| 851 | } |
| 852 | |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 853 | if (!prev) |
| 854 | prev = pointer->seat->output; |
| 855 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 856 | if (prev && !valid) |
| 857 | weston_pointer_clamp_for_output(pointer, prev, fx, fy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /* Takes absolute values */ |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 861 | WL_EXPORT void |
| 862 | weston_pointer_move(struct weston_pointer *pointer, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 863 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 864 | int32_t ix, iy; |
| 865 | |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 866 | weston_pointer_clamp (pointer, &x, &y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 867 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 868 | pointer->x = x; |
| 869 | pointer->y = y; |
| 870 | |
| 871 | ix = wl_fixed_to_int(x); |
| 872 | iy = wl_fixed_to_int(y); |
| 873 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 874 | if (pointer->sprite) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 875 | weston_view_set_position(pointer->sprite, |
| 876 | ix - pointer->hotspot_x, |
| 877 | iy - pointer->hotspot_y); |
| 878 | weston_view_schedule_repaint(pointer->sprite); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 879 | } |
Giulio Camuffo | 6fcb378 | 2013-11-14 23:42:50 +0100 | [diff] [blame] | 880 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 881 | pointer->grab->interface->focus(pointer->grab); |
Giulio Camuffo | 6fcb378 | 2013-11-14 23:42:50 +0100 | [diff] [blame] | 882 | wl_signal_emit(&pointer->motion_signal, pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 883 | } |
| 884 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 885 | /** Verify if the pointer is in a valid position and move it if it isn't. |
| 886 | */ |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 887 | static void |
| 888 | weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 889 | { |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 890 | struct weston_pointer *pointer; |
| 891 | struct weston_compositor *ec; |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 892 | struct weston_output *output, *closest = NULL; |
| 893 | int x, y, distance, min = INT_MAX; |
| 894 | wl_fixed_t fx, fy; |
| 895 | |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 896 | pointer = container_of(listener, struct weston_pointer, |
| 897 | output_destroy_listener); |
| 898 | ec = pointer->seat->compositor; |
| 899 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 900 | x = wl_fixed_to_int(pointer->x); |
| 901 | y = wl_fixed_to_int(pointer->y); |
| 902 | |
| 903 | wl_list_for_each(output, &ec->output_list, link) { |
| 904 | if (pixman_region32_contains_point(&output->region, |
| 905 | x, y, NULL)) |
| 906 | return; |
| 907 | |
| 908 | /* Aproximante the distance from the pointer to the center of |
| 909 | * the output. */ |
| 910 | distance = abs(output->x + output->width / 2 - x) + |
| 911 | abs(output->y + output->height / 2 - y); |
| 912 | if (distance < min) { |
| 913 | min = distance; |
| 914 | closest = output; |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | /* Nothing to do if there's no output left. */ |
| 919 | if (!closest) |
| 920 | return; |
| 921 | |
| 922 | fx = pointer->x; |
| 923 | fy = pointer->y; |
| 924 | |
| 925 | weston_pointer_clamp_for_output(pointer, closest, &fx, &fy); |
| 926 | weston_pointer_move(pointer, fx, fy); |
| 927 | } |
| 928 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 929 | WL_EXPORT void |
| 930 | notify_motion(struct weston_seat *seat, |
| 931 | uint32_t time, wl_fixed_t dx, wl_fixed_t dy) |
| 932 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 933 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 934 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 935 | |
| 936 | weston_compositor_wake(ec); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 937 | pointer->grab->interface->motion(pointer->grab, time, pointer->x + dx, pointer->y + dy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 938 | } |
| 939 | |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 940 | static void |
| 941 | run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new) |
| 942 | { |
| 943 | struct weston_compositor *compositor = seat->compositor; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 944 | struct weston_keyboard *keyboard = seat->keyboard; |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 945 | uint32_t diff; |
| 946 | unsigned int i; |
| 947 | struct { |
| 948 | uint32_t xkb; |
| 949 | enum weston_keyboard_modifier weston; |
| 950 | } mods[] = { |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 951 | { keyboard->xkb_info->ctrl_mod, MODIFIER_CTRL }, |
| 952 | { keyboard->xkb_info->alt_mod, MODIFIER_ALT }, |
| 953 | { keyboard->xkb_info->super_mod, MODIFIER_SUPER }, |
| 954 | { keyboard->xkb_info->shift_mod, MODIFIER_SHIFT }, |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 955 | }; |
| 956 | |
| 957 | diff = new & ~old; |
| 958 | for (i = 0; i < ARRAY_LENGTH(mods); i++) { |
| 959 | if (diff & (1 << mods[i].xkb)) |
| 960 | weston_compositor_run_modifier_binding(compositor, |
| 961 | seat, |
| 962 | mods[i].weston, |
| 963 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 964 | } |
| 965 | |
| 966 | diff = old & ~new; |
| 967 | for (i = 0; i < ARRAY_LENGTH(mods); i++) { |
| 968 | if (diff & (1 << mods[i].xkb)) |
| 969 | weston_compositor_run_modifier_binding(compositor, |
| 970 | seat, |
| 971 | mods[i].weston, |
| 972 | WL_KEYBOARD_KEY_STATE_RELEASED); |
| 973 | } |
| 974 | } |
| 975 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 976 | WL_EXPORT void |
| 977 | notify_motion_absolute(struct weston_seat *seat, |
| 978 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
| 979 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 980 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 981 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 982 | |
| 983 | weston_compositor_wake(ec); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 984 | pointer->grab->interface->motion(pointer->grab, time, x, y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | WL_EXPORT void |
| 988 | weston_surface_activate(struct weston_surface *surface, |
| 989 | struct weston_seat *seat) |
| 990 | { |
| 991 | struct weston_compositor *compositor = seat->compositor; |
| 992 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 993 | if (seat->keyboard) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 994 | weston_keyboard_set_focus(seat->keyboard, surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 995 | wl_data_device_set_keyboard_focus(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | wl_signal_emit(&compositor->activate_signal, surface); |
| 999 | } |
| 1000 | |
| 1001 | WL_EXPORT void |
| 1002 | notify_button(struct weston_seat *seat, uint32_t time, int32_t button, |
| 1003 | enum wl_pointer_button_state state) |
| 1004 | { |
| 1005 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1006 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1007 | |
| 1008 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1009 | weston_compositor_idle_inhibit(compositor); |
| 1010 | if (pointer->button_count == 0) { |
| 1011 | pointer->grab_button = button; |
| 1012 | pointer->grab_time = time; |
| 1013 | pointer->grab_x = pointer->x; |
| 1014 | pointer->grab_y = pointer->y; |
| 1015 | } |
| 1016 | pointer->button_count++; |
| 1017 | } else { |
| 1018 | weston_compositor_idle_release(compositor); |
| 1019 | pointer->button_count--; |
| 1020 | } |
| 1021 | |
| 1022 | weston_compositor_run_button_binding(compositor, seat, time, button, |
| 1023 | state); |
| 1024 | |
| 1025 | pointer->grab->interface->button(pointer->grab, time, button, state); |
| 1026 | |
| 1027 | if (pointer->button_count == 1) |
| 1028 | pointer->grab_serial = |
| 1029 | wl_display_get_serial(compositor->wl_display); |
| 1030 | } |
| 1031 | |
| 1032 | WL_EXPORT void |
| 1033 | notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis, |
| 1034 | wl_fixed_t value) |
| 1035 | { |
| 1036 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1037 | struct weston_pointer *pointer = seat->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1038 | struct wl_resource *resource; |
| 1039 | struct wl_list *resource_list; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1040 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1041 | weston_compositor_wake(compositor); |
| 1042 | |
| 1043 | if (!value) |
| 1044 | return; |
| 1045 | |
| 1046 | if (weston_compositor_run_axis_binding(compositor, seat, |
| 1047 | time, axis, value)) |
| 1048 | return; |
| 1049 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1050 | resource_list = &pointer->focus_resource_list; |
| 1051 | wl_resource_for_each(resource, resource_list) |
| 1052 | wl_pointer_send_axis(resource, time, axis, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1053 | value); |
| 1054 | } |
| 1055 | |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1056 | #ifdef ENABLE_XKBCOMMON |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1057 | WL_EXPORT void |
| 1058 | notify_modifiers(struct weston_seat *seat, uint32_t serial) |
| 1059 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1060 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1061 | struct weston_keyboard_grab *grab = keyboard->grab; |
| 1062 | uint32_t mods_depressed, mods_latched, mods_locked, group; |
| 1063 | uint32_t mods_lookup; |
| 1064 | enum weston_led leds = 0; |
| 1065 | int changed = 0; |
| 1066 | |
| 1067 | /* Serialize and update our internal state, checking to see if it's |
| 1068 | * different to the previous state. */ |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1069 | mods_depressed = xkb_state_serialize_mods(keyboard->xkb_state.state, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1070 | XKB_STATE_DEPRESSED); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1071 | mods_latched = xkb_state_serialize_mods(keyboard->xkb_state.state, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1072 | XKB_STATE_LATCHED); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1073 | mods_locked = xkb_state_serialize_mods(keyboard->xkb_state.state, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1074 | XKB_STATE_LOCKED); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1075 | group = xkb_state_serialize_group(keyboard->xkb_state.state, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1076 | XKB_STATE_EFFECTIVE); |
| 1077 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1078 | if (mods_depressed != seat->keyboard->modifiers.mods_depressed || |
| 1079 | mods_latched != seat->keyboard->modifiers.mods_latched || |
| 1080 | mods_locked != seat->keyboard->modifiers.mods_locked || |
| 1081 | group != seat->keyboard->modifiers.group) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1082 | changed = 1; |
| 1083 | |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 1084 | run_modifier_bindings(seat, seat->keyboard->modifiers.mods_depressed, |
| 1085 | mods_depressed); |
| 1086 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1087 | seat->keyboard->modifiers.mods_depressed = mods_depressed; |
| 1088 | seat->keyboard->modifiers.mods_latched = mods_latched; |
| 1089 | seat->keyboard->modifiers.mods_locked = mods_locked; |
| 1090 | seat->keyboard->modifiers.group = group; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1091 | |
| 1092 | /* And update the modifier_state for bindings. */ |
| 1093 | mods_lookup = mods_depressed | mods_latched; |
| 1094 | seat->modifier_state = 0; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1095 | if (mods_lookup & (1 << keyboard->xkb_info->ctrl_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1096 | seat->modifier_state |= MODIFIER_CTRL; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1097 | if (mods_lookup & (1 << keyboard->xkb_info->alt_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1098 | seat->modifier_state |= MODIFIER_ALT; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1099 | if (mods_lookup & (1 << keyboard->xkb_info->super_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1100 | seat->modifier_state |= MODIFIER_SUPER; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1101 | if (mods_lookup & (1 << keyboard->xkb_info->shift_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1102 | seat->modifier_state |= MODIFIER_SHIFT; |
| 1103 | |
| 1104 | /* Finally, notify the compositor that LEDs have changed. */ |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1105 | if (xkb_state_led_index_is_active(keyboard->xkb_state.state, |
| 1106 | keyboard->xkb_info->num_led)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1107 | leds |= LED_NUM_LOCK; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1108 | if (xkb_state_led_index_is_active(keyboard->xkb_state.state, |
| 1109 | keyboard->xkb_info->caps_led)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1110 | leds |= LED_CAPS_LOCK; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1111 | if (xkb_state_led_index_is_active(keyboard->xkb_state.state, |
| 1112 | keyboard->xkb_info->scroll_led)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1113 | leds |= LED_SCROLL_LOCK; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1114 | if (leds != keyboard->xkb_state.leds && seat->led_update) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1115 | seat->led_update(seat, leds); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1116 | keyboard->xkb_state.leds = leds; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1117 | |
| 1118 | if (changed) { |
| 1119 | grab->interface->modifiers(grab, |
| 1120 | serial, |
| 1121 | keyboard->modifiers.mods_depressed, |
| 1122 | keyboard->modifiers.mods_latched, |
| 1123 | keyboard->modifiers.mods_locked, |
| 1124 | keyboard->modifiers.group); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | static void |
| 1129 | update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key, |
| 1130 | enum wl_keyboard_key_state state) |
| 1131 | { |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1132 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1133 | enum xkb_key_direction direction; |
| 1134 | |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1135 | /* Keyboard modifiers don't exist in raw keyboard mode */ |
| 1136 | if (!seat->compositor->use_xkbcommon) |
| 1137 | return; |
| 1138 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1139 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 1140 | direction = XKB_KEY_DOWN; |
| 1141 | else |
| 1142 | direction = XKB_KEY_UP; |
| 1143 | |
| 1144 | /* Offset the keycode by 8, as the evdev XKB rules reflect X's |
| 1145 | * broken keycode system, which starts at 8. */ |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1146 | xkb_state_update_key(keyboard->xkb_state.state, key + 8, direction); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1147 | |
| 1148 | notify_modifiers(seat, serial); |
| 1149 | } |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1150 | |
| 1151 | static void |
| 1152 | send_keymap(struct wl_resource *resource, struct weston_xkb_info *xkb_info) |
| 1153 | { |
| 1154 | wl_keyboard_send_keymap(resource, |
| 1155 | WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 1156 | xkb_info->keymap_fd, |
| 1157 | xkb_info->keymap_size); |
| 1158 | } |
| 1159 | |
| 1160 | static void |
| 1161 | send_modifiers(struct wl_resource *resource, uint32_t serial, struct weston_keyboard *keyboard) |
| 1162 | { |
| 1163 | wl_keyboard_send_modifiers(resource, serial, |
| 1164 | keyboard->modifiers.mods_depressed, |
| 1165 | keyboard->modifiers.mods_latched, |
| 1166 | keyboard->modifiers.mods_locked, |
| 1167 | keyboard->modifiers.group); |
| 1168 | } |
| 1169 | |
| 1170 | static struct weston_xkb_info * |
| 1171 | weston_xkb_info_create(struct xkb_keymap *keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1172 | |
| 1173 | static void |
| 1174 | update_keymap(struct weston_seat *seat) |
| 1175 | { |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1176 | struct weston_keyboard *keyboard = seat->keyboard; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1177 | struct wl_resource *resource; |
| 1178 | struct weston_xkb_info *xkb_info; |
| 1179 | struct xkb_state *state; |
| 1180 | xkb_mod_mask_t latched_mods; |
| 1181 | xkb_mod_mask_t locked_mods; |
| 1182 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1183 | xkb_info = weston_xkb_info_create(keyboard->pending_keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1184 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1185 | xkb_keymap_unref(keyboard->pending_keymap); |
| 1186 | keyboard->pending_keymap = NULL; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1187 | |
| 1188 | if (!xkb_info) { |
| 1189 | weston_log("failed to create XKB info\n"); |
| 1190 | return; |
| 1191 | } |
| 1192 | |
| 1193 | state = xkb_state_new(xkb_info->keymap); |
| 1194 | if (!state) { |
| 1195 | weston_log("failed to initialise XKB state\n"); |
| 1196 | weston_xkb_info_destroy(xkb_info); |
| 1197 | return; |
| 1198 | } |
| 1199 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1200 | latched_mods = xkb_state_serialize_mods(keyboard->xkb_state.state, |
| 1201 | XKB_STATE_MODS_LATCHED); |
| 1202 | locked_mods = xkb_state_serialize_mods(keyboard->xkb_state.state, |
| 1203 | XKB_STATE_MODS_LOCKED); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1204 | xkb_state_update_mask(state, |
| 1205 | 0, /* depressed */ |
| 1206 | latched_mods, |
| 1207 | locked_mods, |
| 1208 | 0, 0, 0); |
| 1209 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1210 | weston_xkb_info_destroy(keyboard->xkb_info); |
| 1211 | keyboard->xkb_info = xkb_info; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1212 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1213 | xkb_state_unref(keyboard->xkb_state.state); |
| 1214 | keyboard->xkb_state.state = state; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1215 | |
| 1216 | wl_resource_for_each(resource, &seat->keyboard->resource_list) |
| 1217 | send_keymap(resource, xkb_info); |
| 1218 | wl_resource_for_each(resource, &seat->keyboard->focus_resource_list) |
| 1219 | send_keymap(resource, xkb_info); |
| 1220 | |
| 1221 | notify_modifiers(seat, wl_display_next_serial(seat->compositor->wl_display)); |
| 1222 | |
| 1223 | if (!latched_mods && !locked_mods) |
| 1224 | return; |
| 1225 | |
| 1226 | wl_resource_for_each(resource, &seat->keyboard->resource_list) |
| 1227 | send_modifiers(resource, wl_display_get_serial(seat->compositor->wl_display), seat->keyboard); |
| 1228 | wl_resource_for_each(resource, &seat->keyboard->focus_resource_list) |
| 1229 | send_modifiers(resource, wl_display_get_serial(seat->compositor->wl_display), seat->keyboard); |
| 1230 | } |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1231 | #else |
| 1232 | WL_EXPORT void |
| 1233 | notify_modifiers(struct weston_seat *seat, uint32_t serial) |
| 1234 | { |
| 1235 | } |
| 1236 | |
| 1237 | static void |
| 1238 | update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key, |
| 1239 | enum wl_keyboard_key_state state) |
| 1240 | { |
| 1241 | } |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1242 | |
| 1243 | static void |
| 1244 | update_keymap(struct weston_seat *seat) |
| 1245 | { |
| 1246 | } |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1247 | #endif |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1248 | |
| 1249 | WL_EXPORT void |
| 1250 | notify_key(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 1251 | enum wl_keyboard_key_state state, |
| 1252 | enum weston_key_state_update update_state) |
| 1253 | { |
| 1254 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1255 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1256 | struct weston_keyboard_grab *grab = keyboard->grab; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1257 | uint32_t *k, *end; |
| 1258 | |
| 1259 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1260 | weston_compositor_idle_inhibit(compositor); |
| 1261 | keyboard->grab_key = key; |
| 1262 | keyboard->grab_time = time; |
| 1263 | } else { |
| 1264 | weston_compositor_idle_release(compositor); |
| 1265 | } |
| 1266 | |
| 1267 | end = keyboard->keys.data + keyboard->keys.size; |
| 1268 | for (k = keyboard->keys.data; k < end; k++) { |
| 1269 | if (*k == key) { |
| 1270 | /* Ignore server-generated repeats. */ |
| 1271 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 1272 | return; |
| 1273 | *k = *--end; |
| 1274 | } |
| 1275 | } |
| 1276 | keyboard->keys.size = (void *) end - keyboard->keys.data; |
| 1277 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
| 1278 | k = wl_array_add(&keyboard->keys, sizeof *k); |
| 1279 | *k = key; |
| 1280 | } |
| 1281 | |
| 1282 | if (grab == &keyboard->default_grab || |
| 1283 | grab == &keyboard->input_method_grab) { |
| 1284 | weston_compositor_run_key_binding(compositor, seat, time, key, |
| 1285 | state); |
| 1286 | grab = keyboard->grab; |
| 1287 | } |
| 1288 | |
| 1289 | grab->interface->key(grab, time, key, state); |
| 1290 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1291 | if (keyboard->pending_keymap && |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1292 | keyboard->keys.size == 0) |
| 1293 | update_keymap(seat); |
| 1294 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1295 | if (update_state == STATE_UPDATE_AUTOMATIC) { |
| 1296 | update_modifier_state(seat, |
| 1297 | wl_display_get_serial(compositor->wl_display), |
| 1298 | key, |
| 1299 | state); |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | WL_EXPORT void |
| 1304 | notify_pointer_focus(struct weston_seat *seat, struct weston_output *output, |
| 1305 | wl_fixed_t x, wl_fixed_t y) |
| 1306 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1307 | if (output) { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1308 | weston_pointer_move(seat->pointer, x, y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1309 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1310 | /* FIXME: We should call weston_pointer_set_focus(seat, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1311 | * NULL) here, but somehow that breaks re-entry... */ |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | static void |
| 1316 | destroy_device_saved_kbd_focus(struct wl_listener *listener, void *data) |
| 1317 | { |
| 1318 | struct weston_seat *ws; |
| 1319 | |
| 1320 | ws = container_of(listener, struct weston_seat, |
| 1321 | saved_kbd_focus_listener); |
| 1322 | |
| 1323 | ws->saved_kbd_focus = NULL; |
| 1324 | } |
| 1325 | |
| 1326 | WL_EXPORT void |
| 1327 | notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys, |
| 1328 | enum weston_key_state_update update_state) |
| 1329 | { |
| 1330 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1331 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 1332 | struct weston_surface *surface; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1333 | uint32_t *k, serial; |
| 1334 | |
| 1335 | serial = wl_display_next_serial(compositor->wl_display); |
| 1336 | wl_array_copy(&keyboard->keys, keys); |
| 1337 | wl_array_for_each(k, &keyboard->keys) { |
| 1338 | weston_compositor_idle_inhibit(compositor); |
| 1339 | if (update_state == STATE_UPDATE_AUTOMATIC) |
| 1340 | update_modifier_state(seat, serial, *k, |
| 1341 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 1342 | } |
| 1343 | |
| 1344 | /* Run key bindings after we've updated the state. */ |
| 1345 | wl_array_for_each(k, &keyboard->keys) { |
| 1346 | weston_compositor_run_key_binding(compositor, seat, 0, *k, |
| 1347 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 1348 | } |
| 1349 | |
| 1350 | surface = seat->saved_kbd_focus; |
| 1351 | |
| 1352 | if (surface) { |
| 1353 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 1354 | weston_keyboard_set_focus(keyboard, surface); |
| 1355 | seat->saved_kbd_focus = NULL; |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | WL_EXPORT void |
| 1360 | notify_keyboard_focus_out(struct weston_seat *seat) |
| 1361 | { |
| 1362 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1363 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1364 | uint32_t *k, serial; |
| 1365 | |
| 1366 | serial = wl_display_next_serial(compositor->wl_display); |
| 1367 | wl_array_for_each(k, &keyboard->keys) { |
| 1368 | weston_compositor_idle_release(compositor); |
| 1369 | update_modifier_state(seat, serial, *k, |
| 1370 | WL_KEYBOARD_KEY_STATE_RELEASED); |
| 1371 | } |
| 1372 | |
| 1373 | seat->modifier_state = 0; |
| 1374 | |
| 1375 | if (keyboard->focus) { |
| 1376 | seat->saved_kbd_focus = keyboard->focus; |
| 1377 | seat->saved_kbd_focus_listener.notify = |
| 1378 | destroy_device_saved_kbd_focus; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1379 | wl_signal_add(&keyboard->focus->destroy_signal, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1380 | &seat->saved_kbd_focus_listener); |
| 1381 | } |
| 1382 | |
| 1383 | weston_keyboard_set_focus(keyboard, NULL); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1384 | weston_keyboard_cancel_grab(keyboard); |
Kristian Høgsberg | ebd5fd4 | 2013-11-22 21:12:19 -0800 | [diff] [blame] | 1385 | if (seat->pointer) |
| 1386 | weston_pointer_cancel_grab(seat->pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1387 | } |
| 1388 | |
Michael Fu | a2bb791 | 2013-07-23 15:51:06 +0800 | [diff] [blame] | 1389 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1390 | weston_touch_set_focus(struct weston_seat *seat, struct weston_view *view) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1391 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1392 | struct wl_list *focus_resource_list; |
| 1393 | |
| 1394 | focus_resource_list = &seat->touch->focus_resource_list; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1395 | |
Kristian Høgsberg | c3244d7 | 2013-10-24 14:21:53 -0700 | [diff] [blame] | 1396 | if (view && seat->touch->focus && |
| 1397 | seat->touch->focus->surface == view->surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1398 | seat->touch->focus = view; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1399 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1400 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1401 | |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1402 | wl_list_remove(&seat->touch->focus_resource_listener.link); |
| 1403 | wl_list_init(&seat->touch->focus_resource_listener.link); |
| 1404 | wl_list_remove(&seat->touch->focus_view_listener.link); |
| 1405 | wl_list_init(&seat->touch->focus_view_listener.link); |
| 1406 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1407 | if (!wl_list_empty(focus_resource_list)) { |
| 1408 | move_resources(&seat->touch->resource_list, |
| 1409 | focus_resource_list); |
| 1410 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1411 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1412 | if (view) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1413 | struct wl_client *surface_client = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1414 | wl_resource_get_client(view->surface->resource); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1415 | move_resources_for_client(focus_resource_list, |
| 1416 | &seat->touch->resource_list, |
| 1417 | surface_client); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1418 | wl_resource_add_destroy_listener(view->surface->resource, |
| 1419 | &seat->touch->focus_resource_listener); |
| 1420 | wl_signal_add(&view->destroy_signal, &seat->touch->focus_view_listener); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1421 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1422 | seat->touch->focus = view; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | /** |
| 1426 | * notify_touch - emulates button touches and notifies surfaces accordingly. |
| 1427 | * |
| 1428 | * It assumes always the correct cycle sequence until it gets here: touch_down |
| 1429 | * → touch_update → ... → touch_update → touch_end. The driver is responsible |
| 1430 | * for sending along such order. |
| 1431 | * |
| 1432 | */ |
| 1433 | WL_EXPORT void |
| 1434 | notify_touch(struct weston_seat *seat, uint32_t time, int touch_id, |
| 1435 | wl_fixed_t x, wl_fixed_t y, int touch_type) |
| 1436 | { |
| 1437 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1438 | struct weston_touch *touch = seat->touch; |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 1439 | struct weston_touch_grab *grab = touch->grab; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1440 | struct weston_view *ev; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1441 | wl_fixed_t sx, sy; |
| 1442 | |
| 1443 | /* Update grab's global coordinates. */ |
Neil Roberts | 306fe08 | 2013-10-03 16:43:06 +0100 | [diff] [blame] | 1444 | if (touch_id == touch->grab_touch_id && touch_type != WL_TOUCH_UP) { |
| 1445 | touch->grab_x = x; |
| 1446 | touch->grab_y = y; |
| 1447 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1448 | |
| 1449 | switch (touch_type) { |
| 1450 | case WL_TOUCH_DOWN: |
| 1451 | weston_compositor_idle_inhibit(ec); |
| 1452 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1453 | touch->num_tp++; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1454 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1455 | /* the first finger down picks the view, and all further go |
| 1456 | * to that view for the remainder of the touch session i.e. |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1457 | * until all touch points are up again. */ |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1458 | if (touch->num_tp == 1) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1459 | ev = weston_compositor_pick_view(ec, x, y, &sx, &sy); |
| 1460 | weston_touch_set_focus(seat, ev); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1461 | } else if (touch->focus) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1462 | ev = touch->focus; |
| 1463 | weston_view_from_global_fixed(ev, x, y, &sx, &sy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1464 | } else { |
| 1465 | /* Unexpected condition: We have non-initial touch but |
| 1466 | * there is no focused surface. |
| 1467 | */ |
| 1468 | weston_log("touch event received with %d points down" |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1469 | "but no surface focused\n", touch->num_tp); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1470 | return; |
| 1471 | } |
| 1472 | |
Kristian Høgsberg | c896401 | 2014-02-05 14:25:18 -0800 | [diff] [blame] | 1473 | weston_compositor_run_touch_binding(ec, seat, |
| 1474 | time, touch_type); |
| 1475 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1476 | grab->interface->down(grab, time, touch_id, sx, sy); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1477 | if (touch->num_tp == 1) { |
Rusty Lynch | f1407ff | 2013-08-08 21:13:57 -0700 | [diff] [blame] | 1478 | touch->grab_serial = |
| 1479 | wl_display_get_serial(ec->wl_display); |
Neil Roberts | 306fe08 | 2013-10-03 16:43:06 +0100 | [diff] [blame] | 1480 | touch->grab_touch_id = touch_id; |
Rusty Lynch | f1407ff | 2013-08-08 21:13:57 -0700 | [diff] [blame] | 1481 | touch->grab_time = time; |
| 1482 | touch->grab_x = x; |
| 1483 | touch->grab_y = y; |
| 1484 | } |
| 1485 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1486 | break; |
| 1487 | case WL_TOUCH_MOTION: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1488 | ev = touch->focus; |
| 1489 | if (!ev) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1490 | break; |
| 1491 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1492 | weston_view_from_global_fixed(ev, x, y, &sx, &sy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1493 | grab->interface->motion(grab, time, touch_id, sx, sy); |
| 1494 | break; |
| 1495 | case WL_TOUCH_UP: |
Kristian Høgsberg | a30e29a | 2014-01-08 22:29:20 -0800 | [diff] [blame] | 1496 | if (touch->num_tp == 0) { |
| 1497 | /* This can happen if we start out with one or |
| 1498 | * more fingers on the touch screen, in which |
| 1499 | * case we didn't get the corresponding down |
| 1500 | * event. */ |
| 1501 | weston_log("unmatched touch up event\n"); |
| 1502 | break; |
| 1503 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1504 | weston_compositor_idle_release(ec); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1505 | touch->num_tp--; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1506 | |
| 1507 | grab->interface->up(grab, time, touch_id); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1508 | if (touch->num_tp == 0) |
Michael Fu | a2bb791 | 2013-07-23 15:51:06 +0800 | [diff] [blame] | 1509 | weston_touch_set_focus(seat, NULL); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1510 | break; |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1515 | pointer_cursor_surface_configure(struct weston_surface *es, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1516 | int32_t dx, int32_t dy) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1517 | { |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1518 | struct weston_pointer *pointer = es->configure_private; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1519 | int x, y; |
| 1520 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1521 | if (es->width == 0) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1522 | return; |
| 1523 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1524 | assert(es == pointer->sprite->surface); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1525 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1526 | pointer->hotspot_x -= dx; |
| 1527 | pointer->hotspot_y -= dy; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1528 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1529 | x = wl_fixed_to_int(pointer->x) - pointer->hotspot_x; |
| 1530 | y = wl_fixed_to_int(pointer->y) - pointer->hotspot_y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1531 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1532 | weston_view_set_position(pointer->sprite, x, y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1533 | |
| 1534 | empty_region(&es->pending.input); |
Ander Conselvan de Oliveira | 23900f7 | 2014-01-31 16:07:51 +0200 | [diff] [blame] | 1535 | empty_region(&es->input); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1536 | |
| 1537 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1538 | wl_list_insert(&es->compositor->cursor_layer.view_list, |
| 1539 | &pointer->sprite->layer_link); |
| 1540 | weston_view_update_transform(pointer->sprite); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1545 | pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, |
| 1546 | uint32_t serial, struct wl_resource *surface_resource, |
| 1547 | int32_t x, int32_t y) |
| 1548 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1549 | struct weston_pointer *pointer = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1550 | struct weston_surface *surface = NULL; |
| 1551 | |
| 1552 | if (surface_resource) |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1553 | surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1554 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1555 | if (pointer->focus == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1556 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1557 | /* pointer->focus->surface->resource can be NULL. Surfaces like the |
Giulio Camuffo | 1fd4b01 | 2013-06-20 18:13:07 +0200 | [diff] [blame] | 1558 | black_surface used in shell.c for fullscreen don't have |
| 1559 | a resource, but can still have focus */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1560 | if (pointer->focus->surface->resource == NULL) |
Giulio Camuffo | 1fd4b01 | 2013-06-20 18:13:07 +0200 | [diff] [blame] | 1561 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1562 | if (wl_resource_get_client(pointer->focus->surface->resource) != client) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1563 | return; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1564 | if (pointer->focus_serial - serial > UINT32_MAX / 2) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1565 | return; |
| 1566 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1567 | if (surface && pointer->sprite && surface != pointer->sprite->surface) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1568 | if (surface->configure) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1569 | wl_resource_post_error(surface->resource, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1570 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1571 | "surface->configure already " |
| 1572 | "set"); |
| 1573 | return; |
| 1574 | } |
| 1575 | } |
| 1576 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1577 | if (pointer->sprite) |
| 1578 | pointer_unmap_sprite(pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1579 | |
| 1580 | if (!surface) |
| 1581 | return; |
| 1582 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1583 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1584 | &pointer->sprite_destroy_listener); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1585 | |
| 1586 | surface->configure = pointer_cursor_surface_configure; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1587 | surface->configure_private = pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1588 | pointer->sprite = weston_view_create(surface); |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1589 | pointer->hotspot_x = x; |
| 1590 | pointer->hotspot_y = y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1591 | |
| 1592 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1593 | pointer_cursor_surface_configure(surface, 0, 0); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1594 | } |
| 1595 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1596 | static void |
| 1597 | pointer_release(struct wl_client *client, struct wl_resource *resource) |
| 1598 | { |
| 1599 | wl_resource_destroy(resource); |
| 1600 | } |
| 1601 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1602 | static const struct wl_pointer_interface pointer_interface = { |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1603 | pointer_set_cursor, |
| 1604 | pointer_release |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1605 | }; |
| 1606 | |
| 1607 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1608 | seat_get_pointer(struct wl_client *client, struct wl_resource *resource, |
| 1609 | uint32_t id) |
| 1610 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1611 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1612 | struct wl_resource *cr; |
| 1613 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1614 | if (!seat->pointer) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1615 | return; |
| 1616 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1617 | cr = wl_resource_create(client, &wl_pointer_interface, |
| 1618 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 1619 | if (cr == NULL) { |
| 1620 | wl_client_post_no_memory(client); |
| 1621 | return; |
| 1622 | } |
| 1623 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1624 | /* May be moved to focused list later by either |
| 1625 | * weston_pointer_set_focus or directly if this client is already |
| 1626 | * focused */ |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1627 | wl_list_insert(&seat->pointer->resource_list, wl_resource_get_link(cr)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1628 | wl_resource_set_implementation(cr, &pointer_interface, seat->pointer, |
| 1629 | unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1630 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1631 | if (seat->pointer->focus && seat->pointer->focus->surface->resource && |
| 1632 | wl_resource_get_client(seat->pointer->focus->surface->resource) == client) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1633 | wl_fixed_t sx, sy; |
| 1634 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1635 | weston_view_from_global_fixed(seat->pointer->focus, |
| 1636 | seat->pointer->x, |
| 1637 | seat->pointer->y, |
| 1638 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1639 | |
| 1640 | wl_list_remove(wl_resource_get_link(cr)); |
| 1641 | wl_list_insert(&seat->pointer->focus_resource_list, |
| 1642 | wl_resource_get_link(cr)); |
| 1643 | wl_pointer_send_enter(cr, |
| 1644 | seat->pointer->focus_serial, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1645 | seat->pointer->focus->surface->resource, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1646 | sx, sy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1647 | } |
| 1648 | } |
| 1649 | |
| 1650 | static void |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1651 | keyboard_release(struct wl_client *client, struct wl_resource *resource) |
| 1652 | { |
| 1653 | wl_resource_destroy(resource); |
| 1654 | } |
| 1655 | |
| 1656 | static const struct wl_keyboard_interface keyboard_interface = { |
| 1657 | keyboard_release |
| 1658 | }; |
| 1659 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1660 | static int |
| 1661 | should_send_modifiers_to_client(struct weston_seat *seat, |
| 1662 | struct wl_client *client) |
| 1663 | { |
| 1664 | if (seat->keyboard && |
| 1665 | seat->keyboard->focus && |
Jason Ekstrand | 42133d4 | 2013-11-14 20:06:16 -0600 | [diff] [blame] | 1666 | seat->keyboard->focus->resource && |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1667 | wl_resource_get_client(seat->keyboard->focus->resource) == client) |
| 1668 | return 1; |
| 1669 | |
| 1670 | if (seat->pointer && |
| 1671 | seat->pointer->focus && |
Jason Ekstrand | 42133d4 | 2013-11-14 20:06:16 -0600 | [diff] [blame] | 1672 | seat->pointer->focus->surface->resource && |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1673 | wl_resource_get_client(seat->pointer->focus->surface->resource) == client) |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1674 | return 1; |
| 1675 | |
| 1676 | return 0; |
| 1677 | } |
| 1678 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1679 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1680 | seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, |
| 1681 | uint32_t id) |
| 1682 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1683 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1684 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1685 | struct wl_resource *cr; |
| 1686 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1687 | if (!seat->keyboard) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1688 | return; |
| 1689 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1690 | cr = wl_resource_create(client, &wl_keyboard_interface, |
| 1691 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 1692 | if (cr == NULL) { |
| 1693 | wl_client_post_no_memory(client); |
| 1694 | return; |
| 1695 | } |
| 1696 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1697 | /* May be moved to focused list later by either |
| 1698 | * weston_keyboard_set_focus or directly if this client is already |
| 1699 | * focused */ |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1700 | wl_list_insert(&seat->keyboard->resource_list, wl_resource_get_link(cr)); |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1701 | wl_resource_set_implementation(cr, &keyboard_interface, |
| 1702 | seat, unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1703 | |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1704 | if (seat->compositor->use_xkbcommon) { |
| 1705 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1706 | keyboard->xkb_info->keymap_fd, |
| 1707 | keyboard->xkb_info->keymap_size); |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1708 | } else { |
| 1709 | int null_fd = open("/dev/null", O_RDONLY); |
| 1710 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, |
| 1711 | null_fd, |
| 1712 | 0); |
| 1713 | close(null_fd); |
| 1714 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1715 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1716 | if (should_send_modifiers_to_client(seat, client)) { |
| 1717 | send_modifiers_to_resource(seat->keyboard, |
| 1718 | cr, |
| 1719 | seat->keyboard->focus_serial); |
| 1720 | } |
| 1721 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1722 | if (seat->keyboard->focus && |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1723 | wl_resource_get_client(seat->keyboard->focus->resource) == client) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1724 | struct weston_surface *surface = |
| 1725 | (struct weston_surface *) seat->keyboard->focus; |
| 1726 | |
| 1727 | wl_list_remove(wl_resource_get_link(cr)); |
| 1728 | wl_list_insert(&seat->keyboard->focus_resource_list, |
| 1729 | wl_resource_get_link(cr)); |
| 1730 | wl_keyboard_send_enter(cr, |
| 1731 | seat->keyboard->focus_serial, |
| 1732 | surface->resource, |
| 1733 | &seat->keyboard->keys); |
| 1734 | |
| 1735 | /* If this is the first keyboard resource for this |
| 1736 | * client... */ |
| 1737 | if (seat->keyboard->focus_resource_list.prev == |
| 1738 | wl_resource_get_link(cr)) |
| 1739 | wl_data_device_set_keyboard_focus(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | static void |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1744 | touch_release(struct wl_client *client, struct wl_resource *resource) |
| 1745 | { |
| 1746 | wl_resource_destroy(resource); |
| 1747 | } |
| 1748 | |
| 1749 | static const struct wl_touch_interface touch_interface = { |
| 1750 | touch_release |
| 1751 | }; |
| 1752 | |
| 1753 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1754 | seat_get_touch(struct wl_client *client, struct wl_resource *resource, |
| 1755 | uint32_t id) |
| 1756 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1757 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1758 | struct wl_resource *cr; |
| 1759 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1760 | if (!seat->touch) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1761 | return; |
| 1762 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1763 | cr = wl_resource_create(client, &wl_touch_interface, |
| 1764 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 1765 | if (cr == NULL) { |
| 1766 | wl_client_post_no_memory(client); |
| 1767 | return; |
| 1768 | } |
| 1769 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1770 | if (seat->touch->focus && |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1771 | wl_resource_get_client(seat->touch->focus->surface->resource) == client) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1772 | wl_list_insert(&seat->touch->resource_list, |
| 1773 | wl_resource_get_link(cr)); |
| 1774 | } else { |
| 1775 | wl_list_insert(&seat->touch->focus_resource_list, |
| 1776 | wl_resource_get_link(cr)); |
| 1777 | } |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1778 | wl_resource_set_implementation(cr, &touch_interface, |
| 1779 | seat, unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | static const struct wl_seat_interface seat_interface = { |
| 1783 | seat_get_pointer, |
| 1784 | seat_get_keyboard, |
| 1785 | seat_get_touch, |
| 1786 | }; |
| 1787 | |
| 1788 | static void |
| 1789 | bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 1790 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1791 | struct weston_seat *seat = data; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1792 | struct wl_resource *resource; |
| 1793 | enum wl_seat_capability caps = 0; |
| 1794 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1795 | resource = wl_resource_create(client, |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1796 | &wl_seat_interface, MIN(version, 3), id); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1797 | wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1798 | wl_resource_set_implementation(resource, &seat_interface, data, |
| 1799 | unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1800 | |
| 1801 | if (seat->pointer) |
| 1802 | caps |= WL_SEAT_CAPABILITY_POINTER; |
| 1803 | if (seat->keyboard) |
| 1804 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
| 1805 | if (seat->touch) |
| 1806 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 1807 | |
| 1808 | wl_seat_send_capabilities(resource, caps); |
Rob Bradford | e445ae6 | 2013-05-31 18:09:51 +0100 | [diff] [blame] | 1809 | if (version >= 2) |
| 1810 | wl_seat_send_name(resource, seat->seat_name); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1811 | } |
| 1812 | |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1813 | #ifdef ENABLE_XKBCOMMON |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1814 | int |
| 1815 | weston_compositor_xkb_init(struct weston_compositor *ec, |
| 1816 | struct xkb_rule_names *names) |
| 1817 | { |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1818 | ec->use_xkbcommon = 1; |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1819 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1820 | if (ec->xkb_context == NULL) { |
| 1821 | ec->xkb_context = xkb_context_new(0); |
| 1822 | if (ec->xkb_context == NULL) { |
| 1823 | weston_log("failed to create XKB context\n"); |
| 1824 | return -1; |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | if (names) |
| 1829 | ec->xkb_names = *names; |
| 1830 | if (!ec->xkb_names.rules) |
| 1831 | ec->xkb_names.rules = strdup("evdev"); |
| 1832 | if (!ec->xkb_names.model) |
| 1833 | ec->xkb_names.model = strdup("pc105"); |
| 1834 | if (!ec->xkb_names.layout) |
| 1835 | ec->xkb_names.layout = strdup("us"); |
| 1836 | |
| 1837 | return 0; |
| 1838 | } |
| 1839 | |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1840 | static void |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1841 | weston_xkb_info_destroy(struct weston_xkb_info *xkb_info) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1842 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1843 | if (--xkb_info->ref_count > 0) |
| 1844 | return; |
| 1845 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1846 | if (xkb_info->keymap) |
| 1847 | xkb_map_unref(xkb_info->keymap); |
| 1848 | |
| 1849 | if (xkb_info->keymap_area) |
| 1850 | munmap(xkb_info->keymap_area, xkb_info->keymap_size); |
| 1851 | if (xkb_info->keymap_fd >= 0) |
| 1852 | close(xkb_info->keymap_fd); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1853 | free(xkb_info); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | void |
| 1857 | weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 1858 | { |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1859 | /* |
| 1860 | * If we're operating in raw keyboard mode, we never initialized |
| 1861 | * libxkbcommon so there's no cleanup to do either. |
| 1862 | */ |
| 1863 | if (!ec->use_xkbcommon) |
| 1864 | return; |
| 1865 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1866 | free((char *) ec->xkb_names.rules); |
| 1867 | free((char *) ec->xkb_names.model); |
| 1868 | free((char *) ec->xkb_names.layout); |
| 1869 | free((char *) ec->xkb_names.variant); |
| 1870 | free((char *) ec->xkb_names.options); |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1871 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1872 | if (ec->xkb_info) |
| 1873 | weston_xkb_info_destroy(ec->xkb_info); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1874 | xkb_context_unref(ec->xkb_context); |
| 1875 | } |
| 1876 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1877 | static struct weston_xkb_info * |
| 1878 | weston_xkb_info_create(struct xkb_keymap *keymap) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1879 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1880 | struct weston_xkb_info *xkb_info = zalloc(sizeof *xkb_info); |
| 1881 | if (xkb_info == NULL) |
| 1882 | return NULL; |
| 1883 | |
| 1884 | xkb_info->keymap = xkb_map_ref(keymap); |
| 1885 | xkb_info->ref_count = 1; |
| 1886 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1887 | char *keymap_str; |
| 1888 | |
| 1889 | xkb_info->shift_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1890 | XKB_MOD_NAME_SHIFT); |
| 1891 | xkb_info->caps_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1892 | XKB_MOD_NAME_CAPS); |
| 1893 | xkb_info->ctrl_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1894 | XKB_MOD_NAME_CTRL); |
| 1895 | xkb_info->alt_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1896 | XKB_MOD_NAME_ALT); |
| 1897 | xkb_info->mod2_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod2"); |
| 1898 | xkb_info->mod3_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod3"); |
| 1899 | xkb_info->super_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1900 | XKB_MOD_NAME_LOGO); |
| 1901 | xkb_info->mod5_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod5"); |
| 1902 | |
| 1903 | xkb_info->num_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1904 | XKB_LED_NAME_NUM); |
| 1905 | xkb_info->caps_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1906 | XKB_LED_NAME_CAPS); |
| 1907 | xkb_info->scroll_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1908 | XKB_LED_NAME_SCROLL); |
| 1909 | |
| 1910 | keymap_str = xkb_map_get_as_string(xkb_info->keymap); |
| 1911 | if (keymap_str == NULL) { |
| 1912 | weston_log("failed to get string version of keymap\n"); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1913 | goto err_keymap; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1914 | } |
| 1915 | xkb_info->keymap_size = strlen(keymap_str) + 1; |
| 1916 | |
| 1917 | xkb_info->keymap_fd = os_create_anonymous_file(xkb_info->keymap_size); |
| 1918 | if (xkb_info->keymap_fd < 0) { |
| 1919 | weston_log("creating a keymap file for %lu bytes failed: %m\n", |
| 1920 | (unsigned long) xkb_info->keymap_size); |
| 1921 | goto err_keymap_str; |
| 1922 | } |
| 1923 | |
| 1924 | xkb_info->keymap_area = mmap(NULL, xkb_info->keymap_size, |
| 1925 | PROT_READ | PROT_WRITE, |
| 1926 | MAP_SHARED, xkb_info->keymap_fd, 0); |
| 1927 | if (xkb_info->keymap_area == MAP_FAILED) { |
| 1928 | weston_log("failed to mmap() %lu bytes\n", |
| 1929 | (unsigned long) xkb_info->keymap_size); |
| 1930 | goto err_dev_zero; |
| 1931 | } |
| 1932 | strcpy(xkb_info->keymap_area, keymap_str); |
| 1933 | free(keymap_str); |
| 1934 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1935 | return xkb_info; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1936 | |
| 1937 | err_dev_zero: |
| 1938 | close(xkb_info->keymap_fd); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1939 | err_keymap_str: |
| 1940 | free(keymap_str); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1941 | err_keymap: |
| 1942 | xkb_map_unref(xkb_info->keymap); |
| 1943 | free(xkb_info); |
| 1944 | return NULL; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | static int |
| 1948 | weston_compositor_build_global_keymap(struct weston_compositor *ec) |
| 1949 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1950 | struct xkb_keymap *keymap; |
| 1951 | |
| 1952 | if (ec->xkb_info != NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1953 | return 0; |
| 1954 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1955 | keymap = xkb_map_new_from_names(ec->xkb_context, |
| 1956 | &ec->xkb_names, |
| 1957 | 0); |
| 1958 | if (keymap == NULL) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1959 | weston_log("failed to compile global XKB keymap\n"); |
| 1960 | weston_log(" tried rules %s, model %s, layout %s, variant %s, " |
| 1961 | "options %s\n", |
| 1962 | ec->xkb_names.rules, ec->xkb_names.model, |
| 1963 | ec->xkb_names.layout, ec->xkb_names.variant, |
| 1964 | ec->xkb_names.options); |
| 1965 | return -1; |
| 1966 | } |
| 1967 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1968 | ec->xkb_info = weston_xkb_info_create(keymap); |
Rui Matos | 73d9395 | 2013-10-24 19:28:41 +0200 | [diff] [blame] | 1969 | xkb_keymap_unref(keymap); |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1970 | if (ec->xkb_info == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1971 | return -1; |
| 1972 | |
| 1973 | return 0; |
| 1974 | } |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1975 | #else |
| 1976 | int |
| 1977 | weston_compositor_xkb_init(struct weston_compositor *ec, |
| 1978 | struct xkb_rule_names *names) |
| 1979 | { |
| 1980 | return 0; |
| 1981 | } |
| 1982 | |
| 1983 | void |
| 1984 | weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 1985 | { |
| 1986 | } |
| 1987 | #endif |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1988 | |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1989 | WL_EXPORT void |
| 1990 | weston_seat_update_keymap(struct weston_seat *seat, struct xkb_keymap *keymap) |
| 1991 | { |
| 1992 | if (!seat->keyboard || !keymap) |
| 1993 | return; |
| 1994 | |
| 1995 | #ifdef ENABLE_XKBCOMMON |
| 1996 | if (!seat->compositor->use_xkbcommon) |
| 1997 | return; |
| 1998 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1999 | xkb_keymap_unref(seat->keyboard->pending_keymap); |
| 2000 | seat->keyboard->pending_keymap = xkb_keymap_ref(keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2001 | |
| 2002 | if (seat->keyboard->keys.size == 0) |
| 2003 | update_keymap(seat); |
| 2004 | #endif |
| 2005 | } |
| 2006 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2007 | WL_EXPORT int |
| 2008 | weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap) |
| 2009 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2010 | struct weston_keyboard *keyboard; |
| 2011 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2012 | if (seat->keyboard) { |
| 2013 | seat->keyboard_device_count += 1; |
| 2014 | if (seat->keyboard_device_count == 1) |
| 2015 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2016 | return 0; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2017 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2018 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2019 | keyboard = weston_keyboard_create(); |
| 2020 | if (keyboard == NULL) { |
| 2021 | weston_log("failed to allocate weston keyboard struct\n"); |
| 2022 | return -1; |
| 2023 | } |
| 2024 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2025 | #ifdef ENABLE_XKBCOMMON |
| 2026 | if (seat->compositor->use_xkbcommon) { |
| 2027 | if (keymap != NULL) { |
| 2028 | keyboard->xkb_info = weston_xkb_info_create(keymap); |
| 2029 | if (keyboard->xkb_info == NULL) |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2030 | goto err; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2031 | } else { |
| 2032 | if (weston_compositor_build_global_keymap(seat->compositor) < 0) |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2033 | goto err; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2034 | keyboard->xkb_info = seat->compositor->xkb_info; |
| 2035 | keyboard->xkb_info->ref_count++; |
| 2036 | } |
| 2037 | |
| 2038 | keyboard->xkb_state.state = xkb_state_new(keyboard->xkb_info->keymap); |
| 2039 | if (keyboard->xkb_state.state == NULL) { |
| 2040 | weston_log("failed to initialise XKB state\n"); |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2041 | goto err; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | keyboard->xkb_state.leds = 0; |
| 2045 | } |
| 2046 | #endif |
| 2047 | |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2048 | seat->keyboard = keyboard; |
| 2049 | seat->keyboard_device_count = 1; |
| 2050 | keyboard->seat = seat; |
| 2051 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2052 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2053 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2054 | return 0; |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2055 | |
| 2056 | err: |
| 2057 | if (keyboard->xkb_info) |
| 2058 | weston_xkb_info_destroy(keyboard->xkb_info); |
| 2059 | free(keyboard); |
| 2060 | |
| 2061 | return -1; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2062 | } |
| 2063 | |
Jonas Ådahl | 91fed54 | 2013-12-03 09:14:27 +0100 | [diff] [blame] | 2064 | static void |
| 2065 | weston_keyboard_reset_state(struct weston_keyboard *keyboard) |
| 2066 | { |
| 2067 | struct weston_seat *seat = keyboard->seat; |
| 2068 | struct xkb_state *state; |
| 2069 | |
| 2070 | #ifdef ENABLE_XKBCOMMON |
| 2071 | if (seat->compositor->use_xkbcommon) { |
| 2072 | state = xkb_state_new(keyboard->xkb_info->keymap); |
| 2073 | if (!state) { |
| 2074 | weston_log("failed to reset XKB state\n"); |
| 2075 | return; |
| 2076 | } |
| 2077 | xkb_state_unref(keyboard->xkb_state.state); |
| 2078 | keyboard->xkb_state.state = state; |
| 2079 | |
| 2080 | keyboard->xkb_state.leds = 0; |
| 2081 | } |
| 2082 | #endif |
| 2083 | |
| 2084 | seat->modifier_state = 0; |
| 2085 | } |
| 2086 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2087 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2088 | weston_seat_release_keyboard(struct weston_seat *seat) |
| 2089 | { |
| 2090 | seat->keyboard_device_count--; |
| 2091 | if (seat->keyboard_device_count == 0) { |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2092 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2093 | weston_keyboard_cancel_grab(seat->keyboard); |
Jonas Ådahl | 91fed54 | 2013-12-03 09:14:27 +0100 | [diff] [blame] | 2094 | weston_keyboard_reset_state(seat->keyboard); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2095 | seat_send_updated_caps(seat); |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | WL_EXPORT void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2100 | weston_seat_init_pointer(struct weston_seat *seat) |
| 2101 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2102 | struct weston_pointer *pointer; |
| 2103 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2104 | if (seat->pointer) { |
| 2105 | seat->pointer_device_count += 1; |
| 2106 | if (seat->pointer_device_count == 1) |
| 2107 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2108 | return; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2109 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2110 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 2111 | pointer = weston_pointer_create(seat); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2112 | if (pointer == NULL) |
| 2113 | return; |
| 2114 | |
| 2115 | seat->pointer = pointer; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2116 | seat->pointer_device_count = 1; |
| 2117 | pointer->seat = seat; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2118 | |
| 2119 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2123 | weston_seat_release_pointer(struct weston_seat *seat) |
| 2124 | { |
| 2125 | struct weston_pointer *pointer = seat->pointer; |
| 2126 | |
| 2127 | seat->pointer_device_count--; |
| 2128 | if (seat->pointer_device_count == 0) { |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2129 | weston_pointer_set_focus(pointer, NULL, |
| 2130 | wl_fixed_from_int(0), |
| 2131 | wl_fixed_from_int(0)); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2132 | weston_pointer_cancel_grab(pointer); |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2133 | |
Jonas Ådahl | a493274 | 2013-10-17 23:04:07 +0200 | [diff] [blame] | 2134 | if (pointer->sprite) |
| 2135 | pointer_unmap_sprite(pointer); |
| 2136 | |
Jonas Ådahl | 3e12e63 | 2013-12-02 22:05:05 +0100 | [diff] [blame] | 2137 | weston_pointer_reset_state(pointer); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2138 | seat_send_updated_caps(seat); |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | WL_EXPORT void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2143 | weston_seat_init_touch(struct weston_seat *seat) |
| 2144 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2145 | struct weston_touch *touch; |
| 2146 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2147 | if (seat->touch) { |
| 2148 | seat->touch_device_count += 1; |
| 2149 | if (seat->touch_device_count == 1) |
| 2150 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2151 | return; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2152 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2153 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2154 | touch = weston_touch_create(); |
| 2155 | if (touch == NULL) |
| 2156 | return; |
| 2157 | |
| 2158 | seat->touch = touch; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2159 | seat->touch_device_count = 1; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2160 | touch->seat = seat; |
| 2161 | |
| 2162 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2166 | weston_seat_release_touch(struct weston_seat *seat) |
| 2167 | { |
| 2168 | seat->touch_device_count--; |
| 2169 | if (seat->touch_device_count == 0) { |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2170 | weston_touch_set_focus(seat, NULL); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2171 | weston_touch_cancel_grab(seat->touch); |
Jonas Ådahl | cbfa7f7 | 2013-12-02 22:05:04 +0100 | [diff] [blame] | 2172 | weston_touch_reset_state(seat->touch); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2173 | seat_send_updated_caps(seat); |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | WL_EXPORT void |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 2178 | weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec, |
| 2179 | const char *seat_name) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2180 | { |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 2181 | memset(seat, 0, sizeof *seat); |
| 2182 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2183 | seat->selection_data_source = NULL; |
| 2184 | wl_list_init(&seat->base_resource_list); |
| 2185 | wl_signal_init(&seat->selection_signal); |
| 2186 | wl_list_init(&seat->drag_resource_list); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2187 | wl_signal_init(&seat->destroy_signal); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 2188 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 2189 | seat->global = wl_global_create(ec->wl_display, &wl_seat_interface, 3, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 2190 | seat, bind_seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2191 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2192 | seat->compositor = ec; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2193 | seat->modifier_state = 0; |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 2194 | seat->seat_name = strdup(seat_name); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2195 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2196 | wl_list_insert(ec->seat_list.prev, &seat->link); |
| 2197 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2198 | clipboard_create(seat); |
| 2199 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2200 | wl_signal_emit(&ec->seat_created_signal, seat); |
| 2201 | } |
| 2202 | |
| 2203 | WL_EXPORT void |
| 2204 | weston_seat_release(struct weston_seat *seat) |
| 2205 | { |
| 2206 | wl_list_remove(&seat->link); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2207 | |
Jonas Ådahl | 1afb238 | 2014-01-03 19:46:51 +0100 | [diff] [blame] | 2208 | if (seat->saved_kbd_focus) |
| 2209 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 2210 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2211 | if (seat->pointer) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2212 | weston_pointer_destroy(seat->pointer); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2213 | if (seat->keyboard) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2214 | weston_keyboard_destroy(seat->keyboard); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2215 | if (seat->touch) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2216 | weston_touch_destroy(seat->touch); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 2217 | |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 2218 | free (seat->seat_name); |
| 2219 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 2220 | wl_global_destroy(seat->global); |
Kristian Høgsberg | aaadc77 | 2013-07-08 16:20:31 -0400 | [diff] [blame] | 2221 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2222 | wl_signal_emit(&seat->destroy_signal, seat); |
| 2223 | } |