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 | } |
Jason Ekstrand | a4ab542 | 2014-04-02 19:53:45 -0500 | [diff] [blame^] | 606 | wl_signal_emit(&seat->updated_caps_signal, seat); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 610 | weston_pointer_set_focus(struct weston_pointer *pointer, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 611 | struct weston_view *view, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 612 | wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 613 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 614 | struct weston_keyboard *kbd = pointer->seat->keyboard; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 615 | struct wl_resource *resource; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 616 | struct wl_display *display = pointer->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 617 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 618 | struct wl_list *focus_resource_list; |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 619 | int refocus = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 620 | |
| 621 | if ((!pointer->focus && view) || |
| 622 | (pointer->focus && !view) || |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 623 | (pointer->focus && pointer->focus->surface != view->surface) || |
| 624 | pointer->sx != sx || pointer->sy != sy) |
| 625 | refocus = 1; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 626 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 627 | focus_resource_list = &pointer->focus_resource_list; |
| 628 | |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 629 | if (!wl_list_empty(focus_resource_list) && refocus) { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 630 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 631 | wl_resource_for_each(resource, focus_resource_list) { |
| 632 | wl_pointer_send_leave(resource, serial, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 633 | pointer->focus->surface->resource); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | move_resources(&pointer->resource_list, focus_resource_list); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 637 | } |
| 638 | |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 639 | if (find_resource_for_view(&pointer->resource_list, view) && refocus) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 640 | struct wl_client *surface_client = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 641 | wl_resource_get_client(view->surface->resource); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 642 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 643 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 644 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 645 | if (kbd && kbd->focus != view->surface) |
Kristian Høgsberg | cb406f1 | 2013-10-09 10:54:03 -0700 | [diff] [blame] | 646 | send_modifiers_to_client_in_list(surface_client, |
| 647 | &kbd->resource_list, |
| 648 | serial, |
| 649 | kbd); |
| 650 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 651 | move_resources_for_client(focus_resource_list, |
| 652 | &pointer->resource_list, |
| 653 | surface_client); |
| 654 | |
| 655 | wl_resource_for_each(resource, focus_resource_list) { |
| 656 | wl_pointer_send_enter(resource, |
| 657 | serial, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 658 | view->surface->resource, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 659 | sx, sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 660 | } |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 661 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 662 | pointer->focus_serial = serial; |
| 663 | } |
| 664 | |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 665 | wl_list_remove(&pointer->focus_view_listener.link); |
| 666 | wl_list_init(&pointer->focus_view_listener.link); |
| 667 | wl_list_remove(&pointer->focus_resource_listener.link); |
| 668 | wl_list_init(&pointer->focus_resource_listener.link); |
Emilio Pozuelo Monfort | aa7a476 | 2013-11-19 11:37:15 +0100 | [diff] [blame] | 669 | if (view) |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 670 | wl_signal_add(&view->destroy_signal, &pointer->focus_view_listener); |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 671 | if (view && view->surface->resource) |
| 672 | wl_resource_add_destroy_listener(view->surface->resource, |
| 673 | &pointer->focus_resource_listener); |
| 674 | |
| 675 | pointer->focus = view; |
| 676 | pointer->focus_view_listener.notify = pointer_focus_view_destroyed; |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 677 | pointer->sx = sx; |
| 678 | pointer->sy = sy; |
| 679 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 680 | wl_signal_emit(&pointer->focus_signal, pointer); |
| 681 | } |
| 682 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 683 | static void |
| 684 | send_enter_to_resource_list(struct wl_list *list, |
| 685 | struct weston_keyboard *keyboard, |
| 686 | struct weston_surface *surface, |
| 687 | uint32_t serial) |
| 688 | { |
| 689 | struct wl_resource *resource; |
| 690 | |
| 691 | wl_resource_for_each(resource, list) { |
| 692 | send_modifiers_to_resource(keyboard, resource, serial); |
| 693 | wl_keyboard_send_enter(resource, serial, |
| 694 | surface->resource, |
| 695 | &keyboard->keys); |
| 696 | } |
| 697 | } |
| 698 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 699 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 700 | weston_keyboard_set_focus(struct weston_keyboard *keyboard, |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 701 | struct weston_surface *surface) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 702 | { |
| 703 | struct wl_resource *resource; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 704 | struct wl_display *display = keyboard->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 705 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 706 | struct wl_list *focus_resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 707 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 708 | focus_resource_list = &keyboard->focus_resource_list; |
| 709 | |
| 710 | if (!wl_list_empty(focus_resource_list) && keyboard->focus != surface) { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 711 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 712 | wl_resource_for_each(resource, focus_resource_list) { |
| 713 | wl_keyboard_send_leave(resource, serial, |
| 714 | keyboard->focus->resource); |
| 715 | } |
| 716 | move_resources(&keyboard->resource_list, focus_resource_list); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 717 | } |
| 718 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 719 | if (find_resource_for_surface(&keyboard->resource_list, surface) && |
| 720 | keyboard->focus != surface) { |
| 721 | struct wl_client *surface_client = |
| 722 | wl_resource_get_client(surface->resource); |
| 723 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 724 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 725 | |
| 726 | move_resources_for_client(focus_resource_list, |
| 727 | &keyboard->resource_list, |
| 728 | surface_client); |
| 729 | send_enter_to_resource_list(focus_resource_list, |
| 730 | keyboard, |
| 731 | surface, |
| 732 | serial); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 733 | keyboard->focus_serial = serial; |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | wl_list_remove(&keyboard->focus_resource_listener.link); |
| 737 | wl_list_init(&keyboard->focus_resource_listener.link); |
| 738 | if (surface && surface->resource) |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 739 | wl_resource_add_destroy_listener(surface->resource, |
| 740 | &keyboard->focus_resource_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 741 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 742 | keyboard->focus = surface; |
| 743 | wl_signal_emit(&keyboard->focus_signal, keyboard); |
| 744 | } |
| 745 | |
| 746 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 747 | weston_keyboard_start_grab(struct weston_keyboard *keyboard, |
| 748 | struct weston_keyboard_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 749 | { |
| 750 | keyboard->grab = grab; |
| 751 | grab->keyboard = keyboard; |
| 752 | |
| 753 | /* XXX focus? */ |
| 754 | } |
| 755 | |
| 756 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 757 | weston_keyboard_end_grab(struct weston_keyboard *keyboard) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 758 | { |
| 759 | keyboard->grab = &keyboard->default_grab; |
| 760 | } |
| 761 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 762 | static void |
| 763 | weston_keyboard_cancel_grab(struct weston_keyboard *keyboard) |
| 764 | { |
| 765 | keyboard->grab->interface->cancel(keyboard->grab); |
| 766 | } |
| 767 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 768 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 769 | weston_pointer_start_grab(struct weston_pointer *pointer, |
| 770 | struct weston_pointer_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 771 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 772 | pointer->grab = grab; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 773 | grab->pointer = pointer; |
Kristian Høgsberg | da751b8 | 2013-07-04 00:58:07 -0400 | [diff] [blame] | 774 | pointer->grab->interface->focus(pointer->grab); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 778 | weston_pointer_end_grab(struct weston_pointer *pointer) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 779 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 780 | pointer->grab = &pointer->default_grab; |
Kristian Høgsberg | da751b8 | 2013-07-04 00:58:07 -0400 | [diff] [blame] | 781 | pointer->grab->interface->focus(pointer->grab); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 782 | } |
| 783 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 784 | static void |
| 785 | weston_pointer_cancel_grab(struct weston_pointer *pointer) |
| 786 | { |
| 787 | pointer->grab->interface->cancel(pointer->grab); |
| 788 | } |
| 789 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 790 | WL_EXPORT void |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 791 | 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] | 792 | { |
| 793 | touch->grab = grab; |
| 794 | grab->touch = touch; |
| 795 | } |
| 796 | |
| 797 | WL_EXPORT void |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 798 | weston_touch_end_grab(struct weston_touch *touch) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 799 | { |
| 800 | touch->grab = &touch->default_grab; |
| 801 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 802 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 803 | static void |
| 804 | weston_touch_cancel_grab(struct weston_touch *touch) |
| 805 | { |
| 806 | touch->grab->interface->cancel(touch->grab); |
| 807 | } |
| 808 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 809 | static void |
| 810 | weston_pointer_clamp_for_output(struct weston_pointer *pointer, |
| 811 | struct weston_output *output, |
| 812 | wl_fixed_t *fx, wl_fixed_t *fy) |
| 813 | { |
| 814 | int x, y; |
| 815 | |
| 816 | x = wl_fixed_to_int(*fx); |
| 817 | y = wl_fixed_to_int(*fy); |
| 818 | |
| 819 | if (x < output->x) |
| 820 | *fx = wl_fixed_from_int(output->x); |
| 821 | else if (x >= output->x + output->width) |
| 822 | *fx = wl_fixed_from_int(output->x + |
| 823 | output->width - 1); |
| 824 | if (y < output->y) |
| 825 | *fy = wl_fixed_from_int(output->y); |
| 826 | else if (y >= output->y + output->height) |
| 827 | *fy = wl_fixed_from_int(output->y + |
| 828 | output->height - 1); |
| 829 | } |
| 830 | |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 831 | WL_EXPORT void |
| 832 | 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] | 833 | { |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 834 | struct weston_compositor *ec = pointer->seat->compositor; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 835 | struct weston_output *output, *prev = NULL; |
| 836 | int x, y, old_x, old_y, valid = 0; |
| 837 | |
| 838 | x = wl_fixed_to_int(*fx); |
| 839 | y = wl_fixed_to_int(*fy); |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 840 | old_x = wl_fixed_to_int(pointer->x); |
| 841 | old_y = wl_fixed_to_int(pointer->y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 842 | |
| 843 | wl_list_for_each(output, &ec->output_list, link) { |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 844 | if (pointer->seat->output && pointer->seat->output != output) |
| 845 | continue; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 846 | if (pixman_region32_contains_point(&output->region, |
| 847 | x, y, NULL)) |
| 848 | valid = 1; |
| 849 | if (pixman_region32_contains_point(&output->region, |
| 850 | old_x, old_y, NULL)) |
| 851 | prev = output; |
| 852 | } |
| 853 | |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 854 | if (!prev) |
| 855 | prev = pointer->seat->output; |
| 856 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 857 | if (prev && !valid) |
| 858 | weston_pointer_clamp_for_output(pointer, prev, fx, fy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | /* Takes absolute values */ |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 862 | WL_EXPORT void |
| 863 | 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] | 864 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 865 | int32_t ix, iy; |
| 866 | |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 867 | weston_pointer_clamp (pointer, &x, &y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 868 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 869 | pointer->x = x; |
| 870 | pointer->y = y; |
| 871 | |
| 872 | ix = wl_fixed_to_int(x); |
| 873 | iy = wl_fixed_to_int(y); |
| 874 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 875 | if (pointer->sprite) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 876 | weston_view_set_position(pointer->sprite, |
| 877 | ix - pointer->hotspot_x, |
| 878 | iy - pointer->hotspot_y); |
| 879 | weston_view_schedule_repaint(pointer->sprite); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 880 | } |
Giulio Camuffo | 6fcb378 | 2013-11-14 23:42:50 +0100 | [diff] [blame] | 881 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 882 | pointer->grab->interface->focus(pointer->grab); |
Giulio Camuffo | 6fcb378 | 2013-11-14 23:42:50 +0100 | [diff] [blame] | 883 | wl_signal_emit(&pointer->motion_signal, pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 884 | } |
| 885 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 886 | /** Verify if the pointer is in a valid position and move it if it isn't. |
| 887 | */ |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 888 | static void |
| 889 | 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] | 890 | { |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 891 | struct weston_pointer *pointer; |
| 892 | struct weston_compositor *ec; |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 893 | struct weston_output *output, *closest = NULL; |
| 894 | int x, y, distance, min = INT_MAX; |
| 895 | wl_fixed_t fx, fy; |
| 896 | |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 897 | pointer = container_of(listener, struct weston_pointer, |
| 898 | output_destroy_listener); |
| 899 | ec = pointer->seat->compositor; |
| 900 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 901 | x = wl_fixed_to_int(pointer->x); |
| 902 | y = wl_fixed_to_int(pointer->y); |
| 903 | |
| 904 | wl_list_for_each(output, &ec->output_list, link) { |
| 905 | if (pixman_region32_contains_point(&output->region, |
| 906 | x, y, NULL)) |
| 907 | return; |
| 908 | |
| 909 | /* Aproximante the distance from the pointer to the center of |
| 910 | * the output. */ |
| 911 | distance = abs(output->x + output->width / 2 - x) + |
| 912 | abs(output->y + output->height / 2 - y); |
| 913 | if (distance < min) { |
| 914 | min = distance; |
| 915 | closest = output; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | /* Nothing to do if there's no output left. */ |
| 920 | if (!closest) |
| 921 | return; |
| 922 | |
| 923 | fx = pointer->x; |
| 924 | fy = pointer->y; |
| 925 | |
| 926 | weston_pointer_clamp_for_output(pointer, closest, &fx, &fy); |
| 927 | weston_pointer_move(pointer, fx, fy); |
| 928 | } |
| 929 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 930 | WL_EXPORT void |
| 931 | notify_motion(struct weston_seat *seat, |
| 932 | uint32_t time, wl_fixed_t dx, wl_fixed_t dy) |
| 933 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 934 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 935 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 936 | |
| 937 | weston_compositor_wake(ec); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 938 | 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] | 939 | } |
| 940 | |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 941 | static void |
| 942 | run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new) |
| 943 | { |
| 944 | struct weston_compositor *compositor = seat->compositor; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 945 | struct weston_keyboard *keyboard = seat->keyboard; |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 946 | uint32_t diff; |
| 947 | unsigned int i; |
| 948 | struct { |
| 949 | uint32_t xkb; |
| 950 | enum weston_keyboard_modifier weston; |
| 951 | } mods[] = { |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 952 | { keyboard->xkb_info->ctrl_mod, MODIFIER_CTRL }, |
| 953 | { keyboard->xkb_info->alt_mod, MODIFIER_ALT }, |
| 954 | { keyboard->xkb_info->super_mod, MODIFIER_SUPER }, |
| 955 | { keyboard->xkb_info->shift_mod, MODIFIER_SHIFT }, |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 956 | }; |
| 957 | |
| 958 | diff = new & ~old; |
| 959 | for (i = 0; i < ARRAY_LENGTH(mods); i++) { |
| 960 | if (diff & (1 << mods[i].xkb)) |
| 961 | weston_compositor_run_modifier_binding(compositor, |
| 962 | seat, |
| 963 | mods[i].weston, |
| 964 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 965 | } |
| 966 | |
| 967 | diff = old & ~new; |
| 968 | for (i = 0; i < ARRAY_LENGTH(mods); i++) { |
| 969 | if (diff & (1 << mods[i].xkb)) |
| 970 | weston_compositor_run_modifier_binding(compositor, |
| 971 | seat, |
| 972 | mods[i].weston, |
| 973 | WL_KEYBOARD_KEY_STATE_RELEASED); |
| 974 | } |
| 975 | } |
| 976 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 977 | WL_EXPORT void |
| 978 | notify_motion_absolute(struct weston_seat *seat, |
| 979 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
| 980 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 981 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 982 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 983 | |
| 984 | weston_compositor_wake(ec); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 985 | pointer->grab->interface->motion(pointer->grab, time, x, y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | WL_EXPORT void |
| 989 | weston_surface_activate(struct weston_surface *surface, |
| 990 | struct weston_seat *seat) |
| 991 | { |
| 992 | struct weston_compositor *compositor = seat->compositor; |
| 993 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 994 | if (seat->keyboard) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 995 | weston_keyboard_set_focus(seat->keyboard, surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 996 | wl_data_device_set_keyboard_focus(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | wl_signal_emit(&compositor->activate_signal, surface); |
| 1000 | } |
| 1001 | |
| 1002 | WL_EXPORT void |
| 1003 | notify_button(struct weston_seat *seat, uint32_t time, int32_t button, |
| 1004 | enum wl_pointer_button_state state) |
| 1005 | { |
| 1006 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1007 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1008 | |
| 1009 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1010 | weston_compositor_idle_inhibit(compositor); |
| 1011 | if (pointer->button_count == 0) { |
| 1012 | pointer->grab_button = button; |
| 1013 | pointer->grab_time = time; |
| 1014 | pointer->grab_x = pointer->x; |
| 1015 | pointer->grab_y = pointer->y; |
| 1016 | } |
| 1017 | pointer->button_count++; |
| 1018 | } else { |
| 1019 | weston_compositor_idle_release(compositor); |
| 1020 | pointer->button_count--; |
| 1021 | } |
| 1022 | |
| 1023 | weston_compositor_run_button_binding(compositor, seat, time, button, |
| 1024 | state); |
| 1025 | |
| 1026 | pointer->grab->interface->button(pointer->grab, time, button, state); |
| 1027 | |
| 1028 | if (pointer->button_count == 1) |
| 1029 | pointer->grab_serial = |
| 1030 | wl_display_get_serial(compositor->wl_display); |
| 1031 | } |
| 1032 | |
| 1033 | WL_EXPORT void |
| 1034 | notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis, |
| 1035 | wl_fixed_t value) |
| 1036 | { |
| 1037 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1038 | struct weston_pointer *pointer = seat->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1039 | struct wl_resource *resource; |
| 1040 | struct wl_list *resource_list; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1041 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1042 | weston_compositor_wake(compositor); |
| 1043 | |
| 1044 | if (!value) |
| 1045 | return; |
| 1046 | |
| 1047 | if (weston_compositor_run_axis_binding(compositor, seat, |
| 1048 | time, axis, value)) |
| 1049 | return; |
| 1050 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1051 | resource_list = &pointer->focus_resource_list; |
| 1052 | wl_resource_for_each(resource, resource_list) |
| 1053 | wl_pointer_send_axis(resource, time, axis, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1054 | value); |
| 1055 | } |
| 1056 | |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1057 | #ifdef ENABLE_XKBCOMMON |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1058 | WL_EXPORT void |
| 1059 | notify_modifiers(struct weston_seat *seat, uint32_t serial) |
| 1060 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1061 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1062 | struct weston_keyboard_grab *grab = keyboard->grab; |
| 1063 | uint32_t mods_depressed, mods_latched, mods_locked, group; |
| 1064 | uint32_t mods_lookup; |
| 1065 | enum weston_led leds = 0; |
| 1066 | int changed = 0; |
| 1067 | |
| 1068 | /* Serialize and update our internal state, checking to see if it's |
| 1069 | * different to the previous state. */ |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1070 | mods_depressed = xkb_state_serialize_mods(keyboard->xkb_state.state, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1071 | XKB_STATE_DEPRESSED); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1072 | mods_latched = xkb_state_serialize_mods(keyboard->xkb_state.state, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1073 | XKB_STATE_LATCHED); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1074 | mods_locked = xkb_state_serialize_mods(keyboard->xkb_state.state, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1075 | XKB_STATE_LOCKED); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1076 | group = xkb_state_serialize_group(keyboard->xkb_state.state, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1077 | XKB_STATE_EFFECTIVE); |
| 1078 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1079 | if (mods_depressed != seat->keyboard->modifiers.mods_depressed || |
| 1080 | mods_latched != seat->keyboard->modifiers.mods_latched || |
| 1081 | mods_locked != seat->keyboard->modifiers.mods_locked || |
| 1082 | group != seat->keyboard->modifiers.group) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1083 | changed = 1; |
| 1084 | |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 1085 | run_modifier_bindings(seat, seat->keyboard->modifiers.mods_depressed, |
| 1086 | mods_depressed); |
| 1087 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1088 | seat->keyboard->modifiers.mods_depressed = mods_depressed; |
| 1089 | seat->keyboard->modifiers.mods_latched = mods_latched; |
| 1090 | seat->keyboard->modifiers.mods_locked = mods_locked; |
| 1091 | seat->keyboard->modifiers.group = group; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1092 | |
| 1093 | /* And update the modifier_state for bindings. */ |
| 1094 | mods_lookup = mods_depressed | mods_latched; |
| 1095 | seat->modifier_state = 0; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1096 | if (mods_lookup & (1 << keyboard->xkb_info->ctrl_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1097 | seat->modifier_state |= MODIFIER_CTRL; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1098 | if (mods_lookup & (1 << keyboard->xkb_info->alt_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1099 | seat->modifier_state |= MODIFIER_ALT; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1100 | if (mods_lookup & (1 << keyboard->xkb_info->super_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1101 | seat->modifier_state |= MODIFIER_SUPER; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1102 | if (mods_lookup & (1 << keyboard->xkb_info->shift_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1103 | seat->modifier_state |= MODIFIER_SHIFT; |
| 1104 | |
| 1105 | /* Finally, notify the compositor that LEDs have changed. */ |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1106 | if (xkb_state_led_index_is_active(keyboard->xkb_state.state, |
| 1107 | keyboard->xkb_info->num_led)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1108 | leds |= LED_NUM_LOCK; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1109 | if (xkb_state_led_index_is_active(keyboard->xkb_state.state, |
| 1110 | keyboard->xkb_info->caps_led)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1111 | leds |= LED_CAPS_LOCK; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1112 | if (xkb_state_led_index_is_active(keyboard->xkb_state.state, |
| 1113 | keyboard->xkb_info->scroll_led)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1114 | leds |= LED_SCROLL_LOCK; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1115 | if (leds != keyboard->xkb_state.leds && seat->led_update) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1116 | seat->led_update(seat, leds); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1117 | keyboard->xkb_state.leds = leds; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1118 | |
| 1119 | if (changed) { |
| 1120 | grab->interface->modifiers(grab, |
| 1121 | serial, |
| 1122 | keyboard->modifiers.mods_depressed, |
| 1123 | keyboard->modifiers.mods_latched, |
| 1124 | keyboard->modifiers.mods_locked, |
| 1125 | keyboard->modifiers.group); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | static void |
| 1130 | update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key, |
| 1131 | enum wl_keyboard_key_state state) |
| 1132 | { |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1133 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1134 | enum xkb_key_direction direction; |
| 1135 | |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1136 | /* Keyboard modifiers don't exist in raw keyboard mode */ |
| 1137 | if (!seat->compositor->use_xkbcommon) |
| 1138 | return; |
| 1139 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1140 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 1141 | direction = XKB_KEY_DOWN; |
| 1142 | else |
| 1143 | direction = XKB_KEY_UP; |
| 1144 | |
| 1145 | /* Offset the keycode by 8, as the evdev XKB rules reflect X's |
| 1146 | * broken keycode system, which starts at 8. */ |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1147 | xkb_state_update_key(keyboard->xkb_state.state, key + 8, direction); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1148 | |
| 1149 | notify_modifiers(seat, serial); |
| 1150 | } |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1151 | |
| 1152 | static void |
| 1153 | send_keymap(struct wl_resource *resource, struct weston_xkb_info *xkb_info) |
| 1154 | { |
| 1155 | wl_keyboard_send_keymap(resource, |
| 1156 | WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 1157 | xkb_info->keymap_fd, |
| 1158 | xkb_info->keymap_size); |
| 1159 | } |
| 1160 | |
| 1161 | static void |
| 1162 | send_modifiers(struct wl_resource *resource, uint32_t serial, struct weston_keyboard *keyboard) |
| 1163 | { |
| 1164 | wl_keyboard_send_modifiers(resource, serial, |
| 1165 | keyboard->modifiers.mods_depressed, |
| 1166 | keyboard->modifiers.mods_latched, |
| 1167 | keyboard->modifiers.mods_locked, |
| 1168 | keyboard->modifiers.group); |
| 1169 | } |
| 1170 | |
| 1171 | static struct weston_xkb_info * |
| 1172 | weston_xkb_info_create(struct xkb_keymap *keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1173 | |
| 1174 | static void |
| 1175 | update_keymap(struct weston_seat *seat) |
| 1176 | { |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1177 | struct weston_keyboard *keyboard = seat->keyboard; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1178 | struct wl_resource *resource; |
| 1179 | struct weston_xkb_info *xkb_info; |
| 1180 | struct xkb_state *state; |
| 1181 | xkb_mod_mask_t latched_mods; |
| 1182 | xkb_mod_mask_t locked_mods; |
| 1183 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1184 | xkb_info = weston_xkb_info_create(keyboard->pending_keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1185 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1186 | xkb_keymap_unref(keyboard->pending_keymap); |
| 1187 | keyboard->pending_keymap = NULL; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1188 | |
| 1189 | if (!xkb_info) { |
| 1190 | weston_log("failed to create XKB info\n"); |
| 1191 | return; |
| 1192 | } |
| 1193 | |
| 1194 | state = xkb_state_new(xkb_info->keymap); |
| 1195 | if (!state) { |
| 1196 | weston_log("failed to initialise XKB state\n"); |
| 1197 | weston_xkb_info_destroy(xkb_info); |
| 1198 | return; |
| 1199 | } |
| 1200 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1201 | latched_mods = xkb_state_serialize_mods(keyboard->xkb_state.state, |
| 1202 | XKB_STATE_MODS_LATCHED); |
| 1203 | locked_mods = xkb_state_serialize_mods(keyboard->xkb_state.state, |
| 1204 | XKB_STATE_MODS_LOCKED); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1205 | xkb_state_update_mask(state, |
| 1206 | 0, /* depressed */ |
| 1207 | latched_mods, |
| 1208 | locked_mods, |
| 1209 | 0, 0, 0); |
| 1210 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1211 | weston_xkb_info_destroy(keyboard->xkb_info); |
| 1212 | keyboard->xkb_info = xkb_info; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1213 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1214 | xkb_state_unref(keyboard->xkb_state.state); |
| 1215 | keyboard->xkb_state.state = state; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1216 | |
| 1217 | wl_resource_for_each(resource, &seat->keyboard->resource_list) |
| 1218 | send_keymap(resource, xkb_info); |
| 1219 | wl_resource_for_each(resource, &seat->keyboard->focus_resource_list) |
| 1220 | send_keymap(resource, xkb_info); |
| 1221 | |
| 1222 | notify_modifiers(seat, wl_display_next_serial(seat->compositor->wl_display)); |
| 1223 | |
| 1224 | if (!latched_mods && !locked_mods) |
| 1225 | return; |
| 1226 | |
| 1227 | wl_resource_for_each(resource, &seat->keyboard->resource_list) |
| 1228 | send_modifiers(resource, wl_display_get_serial(seat->compositor->wl_display), seat->keyboard); |
| 1229 | wl_resource_for_each(resource, &seat->keyboard->focus_resource_list) |
| 1230 | send_modifiers(resource, wl_display_get_serial(seat->compositor->wl_display), seat->keyboard); |
| 1231 | } |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1232 | #else |
| 1233 | WL_EXPORT void |
| 1234 | notify_modifiers(struct weston_seat *seat, uint32_t serial) |
| 1235 | { |
| 1236 | } |
| 1237 | |
| 1238 | static void |
| 1239 | update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key, |
| 1240 | enum wl_keyboard_key_state state) |
| 1241 | { |
| 1242 | } |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1243 | |
| 1244 | static void |
| 1245 | update_keymap(struct weston_seat *seat) |
| 1246 | { |
| 1247 | } |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1248 | #endif |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1249 | |
| 1250 | WL_EXPORT void |
| 1251 | notify_key(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 1252 | enum wl_keyboard_key_state state, |
| 1253 | enum weston_key_state_update update_state) |
| 1254 | { |
| 1255 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1256 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1257 | struct weston_keyboard_grab *grab = keyboard->grab; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1258 | uint32_t *k, *end; |
| 1259 | |
| 1260 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1261 | weston_compositor_idle_inhibit(compositor); |
| 1262 | keyboard->grab_key = key; |
| 1263 | keyboard->grab_time = time; |
| 1264 | } else { |
| 1265 | weston_compositor_idle_release(compositor); |
| 1266 | } |
| 1267 | |
| 1268 | end = keyboard->keys.data + keyboard->keys.size; |
| 1269 | for (k = keyboard->keys.data; k < end; k++) { |
| 1270 | if (*k == key) { |
| 1271 | /* Ignore server-generated repeats. */ |
| 1272 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 1273 | return; |
| 1274 | *k = *--end; |
| 1275 | } |
| 1276 | } |
| 1277 | keyboard->keys.size = (void *) end - keyboard->keys.data; |
| 1278 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
| 1279 | k = wl_array_add(&keyboard->keys, sizeof *k); |
| 1280 | *k = key; |
| 1281 | } |
| 1282 | |
| 1283 | if (grab == &keyboard->default_grab || |
| 1284 | grab == &keyboard->input_method_grab) { |
| 1285 | weston_compositor_run_key_binding(compositor, seat, time, key, |
| 1286 | state); |
| 1287 | grab = keyboard->grab; |
| 1288 | } |
| 1289 | |
| 1290 | grab->interface->key(grab, time, key, state); |
| 1291 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1292 | if (keyboard->pending_keymap && |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1293 | keyboard->keys.size == 0) |
| 1294 | update_keymap(seat); |
| 1295 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1296 | if (update_state == STATE_UPDATE_AUTOMATIC) { |
| 1297 | update_modifier_state(seat, |
| 1298 | wl_display_get_serial(compositor->wl_display), |
| 1299 | key, |
| 1300 | state); |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | WL_EXPORT void |
| 1305 | notify_pointer_focus(struct weston_seat *seat, struct weston_output *output, |
| 1306 | wl_fixed_t x, wl_fixed_t y) |
| 1307 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1308 | if (output) { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1309 | weston_pointer_move(seat->pointer, x, y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1310 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1311 | /* FIXME: We should call weston_pointer_set_focus(seat, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1312 | * NULL) here, but somehow that breaks re-entry... */ |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | static void |
| 1317 | destroy_device_saved_kbd_focus(struct wl_listener *listener, void *data) |
| 1318 | { |
| 1319 | struct weston_seat *ws; |
| 1320 | |
| 1321 | ws = container_of(listener, struct weston_seat, |
| 1322 | saved_kbd_focus_listener); |
| 1323 | |
| 1324 | ws->saved_kbd_focus = NULL; |
| 1325 | } |
| 1326 | |
| 1327 | WL_EXPORT void |
| 1328 | notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys, |
| 1329 | enum weston_key_state_update update_state) |
| 1330 | { |
| 1331 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1332 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 1333 | struct weston_surface *surface; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1334 | uint32_t *k, serial; |
| 1335 | |
| 1336 | serial = wl_display_next_serial(compositor->wl_display); |
| 1337 | wl_array_copy(&keyboard->keys, keys); |
| 1338 | wl_array_for_each(k, &keyboard->keys) { |
| 1339 | weston_compositor_idle_inhibit(compositor); |
| 1340 | if (update_state == STATE_UPDATE_AUTOMATIC) |
| 1341 | update_modifier_state(seat, serial, *k, |
| 1342 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 1343 | } |
| 1344 | |
| 1345 | /* Run key bindings after we've updated the state. */ |
| 1346 | wl_array_for_each(k, &keyboard->keys) { |
| 1347 | weston_compositor_run_key_binding(compositor, seat, 0, *k, |
| 1348 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 1349 | } |
| 1350 | |
| 1351 | surface = seat->saved_kbd_focus; |
| 1352 | |
| 1353 | if (surface) { |
| 1354 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 1355 | weston_keyboard_set_focus(keyboard, surface); |
| 1356 | seat->saved_kbd_focus = NULL; |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | WL_EXPORT void |
| 1361 | notify_keyboard_focus_out(struct weston_seat *seat) |
| 1362 | { |
| 1363 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1364 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1365 | uint32_t *k, serial; |
| 1366 | |
| 1367 | serial = wl_display_next_serial(compositor->wl_display); |
| 1368 | wl_array_for_each(k, &keyboard->keys) { |
| 1369 | weston_compositor_idle_release(compositor); |
| 1370 | update_modifier_state(seat, serial, *k, |
| 1371 | WL_KEYBOARD_KEY_STATE_RELEASED); |
| 1372 | } |
| 1373 | |
| 1374 | seat->modifier_state = 0; |
| 1375 | |
| 1376 | if (keyboard->focus) { |
| 1377 | seat->saved_kbd_focus = keyboard->focus; |
| 1378 | seat->saved_kbd_focus_listener.notify = |
| 1379 | destroy_device_saved_kbd_focus; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1380 | wl_signal_add(&keyboard->focus->destroy_signal, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1381 | &seat->saved_kbd_focus_listener); |
| 1382 | } |
| 1383 | |
| 1384 | weston_keyboard_set_focus(keyboard, NULL); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1385 | weston_keyboard_cancel_grab(keyboard); |
Kristian Høgsberg | ebd5fd4 | 2013-11-22 21:12:19 -0800 | [diff] [blame] | 1386 | if (seat->pointer) |
| 1387 | weston_pointer_cancel_grab(seat->pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1388 | } |
| 1389 | |
Michael Fu | a2bb791 | 2013-07-23 15:51:06 +0800 | [diff] [blame] | 1390 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1391 | 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] | 1392 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1393 | struct wl_list *focus_resource_list; |
| 1394 | |
| 1395 | focus_resource_list = &seat->touch->focus_resource_list; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1396 | |
Kristian Høgsberg | c3244d7 | 2013-10-24 14:21:53 -0700 | [diff] [blame] | 1397 | if (view && seat->touch->focus && |
| 1398 | seat->touch->focus->surface == view->surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1399 | seat->touch->focus = view; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1400 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1401 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1402 | |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1403 | wl_list_remove(&seat->touch->focus_resource_listener.link); |
| 1404 | wl_list_init(&seat->touch->focus_resource_listener.link); |
| 1405 | wl_list_remove(&seat->touch->focus_view_listener.link); |
| 1406 | wl_list_init(&seat->touch->focus_view_listener.link); |
| 1407 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1408 | if (!wl_list_empty(focus_resource_list)) { |
| 1409 | move_resources(&seat->touch->resource_list, |
| 1410 | focus_resource_list); |
| 1411 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1412 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1413 | if (view) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1414 | struct wl_client *surface_client = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1415 | wl_resource_get_client(view->surface->resource); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1416 | move_resources_for_client(focus_resource_list, |
| 1417 | &seat->touch->resource_list, |
| 1418 | surface_client); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1419 | wl_resource_add_destroy_listener(view->surface->resource, |
| 1420 | &seat->touch->focus_resource_listener); |
| 1421 | wl_signal_add(&view->destroy_signal, &seat->touch->focus_view_listener); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1422 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1423 | seat->touch->focus = view; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * notify_touch - emulates button touches and notifies surfaces accordingly. |
| 1428 | * |
| 1429 | * It assumes always the correct cycle sequence until it gets here: touch_down |
| 1430 | * → touch_update → ... → touch_update → touch_end. The driver is responsible |
| 1431 | * for sending along such order. |
| 1432 | * |
| 1433 | */ |
| 1434 | WL_EXPORT void |
| 1435 | notify_touch(struct weston_seat *seat, uint32_t time, int touch_id, |
| 1436 | wl_fixed_t x, wl_fixed_t y, int touch_type) |
| 1437 | { |
| 1438 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1439 | struct weston_touch *touch = seat->touch; |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 1440 | struct weston_touch_grab *grab = touch->grab; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1441 | struct weston_view *ev; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1442 | wl_fixed_t sx, sy; |
| 1443 | |
| 1444 | /* Update grab's global coordinates. */ |
Neil Roberts | 306fe08 | 2013-10-03 16:43:06 +0100 | [diff] [blame] | 1445 | if (touch_id == touch->grab_touch_id && touch_type != WL_TOUCH_UP) { |
| 1446 | touch->grab_x = x; |
| 1447 | touch->grab_y = y; |
| 1448 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1449 | |
| 1450 | switch (touch_type) { |
| 1451 | case WL_TOUCH_DOWN: |
| 1452 | weston_compositor_idle_inhibit(ec); |
| 1453 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1454 | touch->num_tp++; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1455 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1456 | /* the first finger down picks the view, and all further go |
| 1457 | * 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] | 1458 | * until all touch points are up again. */ |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1459 | if (touch->num_tp == 1) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1460 | ev = weston_compositor_pick_view(ec, x, y, &sx, &sy); |
| 1461 | weston_touch_set_focus(seat, ev); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1462 | } else if (touch->focus) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1463 | ev = touch->focus; |
| 1464 | weston_view_from_global_fixed(ev, x, y, &sx, &sy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1465 | } else { |
| 1466 | /* Unexpected condition: We have non-initial touch but |
| 1467 | * there is no focused surface. |
| 1468 | */ |
| 1469 | weston_log("touch event received with %d points down" |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1470 | "but no surface focused\n", touch->num_tp); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1471 | return; |
| 1472 | } |
| 1473 | |
Kristian Høgsberg | c896401 | 2014-02-05 14:25:18 -0800 | [diff] [blame] | 1474 | weston_compositor_run_touch_binding(ec, seat, |
| 1475 | time, touch_type); |
| 1476 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1477 | grab->interface->down(grab, time, touch_id, sx, sy); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1478 | if (touch->num_tp == 1) { |
Rusty Lynch | f1407ff | 2013-08-08 21:13:57 -0700 | [diff] [blame] | 1479 | touch->grab_serial = |
| 1480 | wl_display_get_serial(ec->wl_display); |
Neil Roberts | 306fe08 | 2013-10-03 16:43:06 +0100 | [diff] [blame] | 1481 | touch->grab_touch_id = touch_id; |
Rusty Lynch | f1407ff | 2013-08-08 21:13:57 -0700 | [diff] [blame] | 1482 | touch->grab_time = time; |
| 1483 | touch->grab_x = x; |
| 1484 | touch->grab_y = y; |
| 1485 | } |
| 1486 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1487 | break; |
| 1488 | case WL_TOUCH_MOTION: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1489 | ev = touch->focus; |
| 1490 | if (!ev) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1491 | break; |
| 1492 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1493 | weston_view_from_global_fixed(ev, x, y, &sx, &sy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1494 | grab->interface->motion(grab, time, touch_id, sx, sy); |
| 1495 | break; |
| 1496 | case WL_TOUCH_UP: |
Kristian Høgsberg | a30e29a | 2014-01-08 22:29:20 -0800 | [diff] [blame] | 1497 | if (touch->num_tp == 0) { |
| 1498 | /* This can happen if we start out with one or |
| 1499 | * more fingers on the touch screen, in which |
| 1500 | * case we didn't get the corresponding down |
| 1501 | * event. */ |
| 1502 | weston_log("unmatched touch up event\n"); |
| 1503 | break; |
| 1504 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1505 | weston_compositor_idle_release(ec); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1506 | touch->num_tp--; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1507 | |
| 1508 | grab->interface->up(grab, time, touch_id); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1509 | if (touch->num_tp == 0) |
Michael Fu | a2bb791 | 2013-07-23 15:51:06 +0800 | [diff] [blame] | 1510 | weston_touch_set_focus(seat, NULL); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1511 | break; |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1516 | pointer_cursor_surface_configure(struct weston_surface *es, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1517 | int32_t dx, int32_t dy) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1518 | { |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1519 | struct weston_pointer *pointer = es->configure_private; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1520 | int x, y; |
| 1521 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1522 | if (es->width == 0) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1523 | return; |
| 1524 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1525 | assert(es == pointer->sprite->surface); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1526 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1527 | pointer->hotspot_x -= dx; |
| 1528 | pointer->hotspot_y -= dy; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1529 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1530 | x = wl_fixed_to_int(pointer->x) - pointer->hotspot_x; |
| 1531 | y = wl_fixed_to_int(pointer->y) - pointer->hotspot_y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1532 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1533 | weston_view_set_position(pointer->sprite, x, y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1534 | |
| 1535 | empty_region(&es->pending.input); |
Ander Conselvan de Oliveira | 23900f7 | 2014-01-31 16:07:51 +0200 | [diff] [blame] | 1536 | empty_region(&es->input); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1537 | |
| 1538 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1539 | wl_list_insert(&es->compositor->cursor_layer.view_list, |
| 1540 | &pointer->sprite->layer_link); |
| 1541 | weston_view_update_transform(pointer->sprite); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1546 | pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, |
| 1547 | uint32_t serial, struct wl_resource *surface_resource, |
| 1548 | int32_t x, int32_t y) |
| 1549 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1550 | struct weston_pointer *pointer = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1551 | struct weston_surface *surface = NULL; |
| 1552 | |
| 1553 | if (surface_resource) |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1554 | surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1555 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1556 | if (pointer->focus == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1557 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1558 | /* pointer->focus->surface->resource can be NULL. Surfaces like the |
Giulio Camuffo | 1fd4b01 | 2013-06-20 18:13:07 +0200 | [diff] [blame] | 1559 | black_surface used in shell.c for fullscreen don't have |
| 1560 | a resource, but can still have focus */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1561 | if (pointer->focus->surface->resource == NULL) |
Giulio Camuffo | 1fd4b01 | 2013-06-20 18:13:07 +0200 | [diff] [blame] | 1562 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1563 | if (wl_resource_get_client(pointer->focus->surface->resource) != client) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1564 | return; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1565 | if (pointer->focus_serial - serial > UINT32_MAX / 2) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1566 | return; |
| 1567 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1568 | if (surface && pointer->sprite && surface != pointer->sprite->surface) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1569 | if (surface->configure) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1570 | wl_resource_post_error(surface->resource, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1571 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1572 | "surface->configure already " |
| 1573 | "set"); |
| 1574 | return; |
| 1575 | } |
| 1576 | } |
| 1577 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1578 | if (pointer->sprite) |
| 1579 | pointer_unmap_sprite(pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1580 | |
| 1581 | if (!surface) |
| 1582 | return; |
| 1583 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1584 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1585 | &pointer->sprite_destroy_listener); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1586 | |
| 1587 | surface->configure = pointer_cursor_surface_configure; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1588 | surface->configure_private = pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1589 | pointer->sprite = weston_view_create(surface); |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1590 | pointer->hotspot_x = x; |
| 1591 | pointer->hotspot_y = y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1592 | |
| 1593 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1594 | pointer_cursor_surface_configure(surface, 0, 0); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1595 | } |
| 1596 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1597 | static void |
| 1598 | pointer_release(struct wl_client *client, struct wl_resource *resource) |
| 1599 | { |
| 1600 | wl_resource_destroy(resource); |
| 1601 | } |
| 1602 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1603 | static const struct wl_pointer_interface pointer_interface = { |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1604 | pointer_set_cursor, |
| 1605 | pointer_release |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1606 | }; |
| 1607 | |
| 1608 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1609 | seat_get_pointer(struct wl_client *client, struct wl_resource *resource, |
| 1610 | uint32_t id) |
| 1611 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1612 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1613 | struct wl_resource *cr; |
| 1614 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1615 | if (!seat->pointer) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1616 | return; |
| 1617 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1618 | cr = wl_resource_create(client, &wl_pointer_interface, |
| 1619 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 1620 | if (cr == NULL) { |
| 1621 | wl_client_post_no_memory(client); |
| 1622 | return; |
| 1623 | } |
| 1624 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1625 | /* May be moved to focused list later by either |
| 1626 | * weston_pointer_set_focus or directly if this client is already |
| 1627 | * focused */ |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1628 | wl_list_insert(&seat->pointer->resource_list, wl_resource_get_link(cr)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1629 | wl_resource_set_implementation(cr, &pointer_interface, seat->pointer, |
| 1630 | unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1631 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1632 | if (seat->pointer->focus && seat->pointer->focus->surface->resource && |
| 1633 | wl_resource_get_client(seat->pointer->focus->surface->resource) == client) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1634 | wl_fixed_t sx, sy; |
| 1635 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1636 | weston_view_from_global_fixed(seat->pointer->focus, |
| 1637 | seat->pointer->x, |
| 1638 | seat->pointer->y, |
| 1639 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1640 | |
| 1641 | wl_list_remove(wl_resource_get_link(cr)); |
| 1642 | wl_list_insert(&seat->pointer->focus_resource_list, |
| 1643 | wl_resource_get_link(cr)); |
| 1644 | wl_pointer_send_enter(cr, |
| 1645 | seat->pointer->focus_serial, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1646 | seat->pointer->focus->surface->resource, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1647 | sx, sy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | static void |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1652 | keyboard_release(struct wl_client *client, struct wl_resource *resource) |
| 1653 | { |
| 1654 | wl_resource_destroy(resource); |
| 1655 | } |
| 1656 | |
| 1657 | static const struct wl_keyboard_interface keyboard_interface = { |
| 1658 | keyboard_release |
| 1659 | }; |
| 1660 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1661 | static int |
| 1662 | should_send_modifiers_to_client(struct weston_seat *seat, |
| 1663 | struct wl_client *client) |
| 1664 | { |
| 1665 | if (seat->keyboard && |
| 1666 | seat->keyboard->focus && |
Jason Ekstrand | 42133d4 | 2013-11-14 20:06:16 -0600 | [diff] [blame] | 1667 | seat->keyboard->focus->resource && |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1668 | wl_resource_get_client(seat->keyboard->focus->resource) == client) |
| 1669 | return 1; |
| 1670 | |
| 1671 | if (seat->pointer && |
| 1672 | seat->pointer->focus && |
Jason Ekstrand | 42133d4 | 2013-11-14 20:06:16 -0600 | [diff] [blame] | 1673 | seat->pointer->focus->surface->resource && |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1674 | wl_resource_get_client(seat->pointer->focus->surface->resource) == client) |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1675 | return 1; |
| 1676 | |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1680 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1681 | seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, |
| 1682 | uint32_t id) |
| 1683 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1684 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1685 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1686 | struct wl_resource *cr; |
| 1687 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1688 | if (!seat->keyboard) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1689 | return; |
| 1690 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1691 | cr = wl_resource_create(client, &wl_keyboard_interface, |
| 1692 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 1693 | if (cr == NULL) { |
| 1694 | wl_client_post_no_memory(client); |
| 1695 | return; |
| 1696 | } |
| 1697 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1698 | /* May be moved to focused list later by either |
| 1699 | * weston_keyboard_set_focus or directly if this client is already |
| 1700 | * focused */ |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1701 | 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] | 1702 | wl_resource_set_implementation(cr, &keyboard_interface, |
| 1703 | seat, unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1704 | |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1705 | if (seat->compositor->use_xkbcommon) { |
| 1706 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1707 | keyboard->xkb_info->keymap_fd, |
| 1708 | keyboard->xkb_info->keymap_size); |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1709 | } else { |
| 1710 | int null_fd = open("/dev/null", O_RDONLY); |
| 1711 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, |
| 1712 | null_fd, |
| 1713 | 0); |
| 1714 | close(null_fd); |
| 1715 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1716 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1717 | if (should_send_modifiers_to_client(seat, client)) { |
| 1718 | send_modifiers_to_resource(seat->keyboard, |
| 1719 | cr, |
| 1720 | seat->keyboard->focus_serial); |
| 1721 | } |
| 1722 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1723 | if (seat->keyboard->focus && |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1724 | wl_resource_get_client(seat->keyboard->focus->resource) == client) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1725 | struct weston_surface *surface = |
| 1726 | (struct weston_surface *) seat->keyboard->focus; |
| 1727 | |
| 1728 | wl_list_remove(wl_resource_get_link(cr)); |
| 1729 | wl_list_insert(&seat->keyboard->focus_resource_list, |
| 1730 | wl_resource_get_link(cr)); |
| 1731 | wl_keyboard_send_enter(cr, |
| 1732 | seat->keyboard->focus_serial, |
| 1733 | surface->resource, |
| 1734 | &seat->keyboard->keys); |
| 1735 | |
| 1736 | /* If this is the first keyboard resource for this |
| 1737 | * client... */ |
| 1738 | if (seat->keyboard->focus_resource_list.prev == |
| 1739 | wl_resource_get_link(cr)) |
| 1740 | wl_data_device_set_keyboard_focus(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | static void |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1745 | touch_release(struct wl_client *client, struct wl_resource *resource) |
| 1746 | { |
| 1747 | wl_resource_destroy(resource); |
| 1748 | } |
| 1749 | |
| 1750 | static const struct wl_touch_interface touch_interface = { |
| 1751 | touch_release |
| 1752 | }; |
| 1753 | |
| 1754 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1755 | seat_get_touch(struct wl_client *client, struct wl_resource *resource, |
| 1756 | uint32_t id) |
| 1757 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1758 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1759 | struct wl_resource *cr; |
| 1760 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1761 | if (!seat->touch) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1762 | return; |
| 1763 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1764 | cr = wl_resource_create(client, &wl_touch_interface, |
| 1765 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 1766 | if (cr == NULL) { |
| 1767 | wl_client_post_no_memory(client); |
| 1768 | return; |
| 1769 | } |
| 1770 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1771 | if (seat->touch->focus && |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1772 | wl_resource_get_client(seat->touch->focus->surface->resource) == client) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1773 | wl_list_insert(&seat->touch->resource_list, |
| 1774 | wl_resource_get_link(cr)); |
| 1775 | } else { |
| 1776 | wl_list_insert(&seat->touch->focus_resource_list, |
| 1777 | wl_resource_get_link(cr)); |
| 1778 | } |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1779 | wl_resource_set_implementation(cr, &touch_interface, |
| 1780 | seat, unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | static const struct wl_seat_interface seat_interface = { |
| 1784 | seat_get_pointer, |
| 1785 | seat_get_keyboard, |
| 1786 | seat_get_touch, |
| 1787 | }; |
| 1788 | |
| 1789 | static void |
| 1790 | bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 1791 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1792 | struct weston_seat *seat = data; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1793 | struct wl_resource *resource; |
| 1794 | enum wl_seat_capability caps = 0; |
| 1795 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1796 | resource = wl_resource_create(client, |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1797 | &wl_seat_interface, MIN(version, 3), id); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1798 | wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1799 | wl_resource_set_implementation(resource, &seat_interface, data, |
| 1800 | unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1801 | |
| 1802 | if (seat->pointer) |
| 1803 | caps |= WL_SEAT_CAPABILITY_POINTER; |
| 1804 | if (seat->keyboard) |
| 1805 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
| 1806 | if (seat->touch) |
| 1807 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 1808 | |
| 1809 | wl_seat_send_capabilities(resource, caps); |
Rob Bradford | e445ae6 | 2013-05-31 18:09:51 +0100 | [diff] [blame] | 1810 | if (version >= 2) |
| 1811 | wl_seat_send_name(resource, seat->seat_name); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1814 | #ifdef ENABLE_XKBCOMMON |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1815 | int |
| 1816 | weston_compositor_xkb_init(struct weston_compositor *ec, |
| 1817 | struct xkb_rule_names *names) |
| 1818 | { |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1819 | ec->use_xkbcommon = 1; |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1820 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1821 | if (ec->xkb_context == NULL) { |
| 1822 | ec->xkb_context = xkb_context_new(0); |
| 1823 | if (ec->xkb_context == NULL) { |
| 1824 | weston_log("failed to create XKB context\n"); |
| 1825 | return -1; |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | if (names) |
| 1830 | ec->xkb_names = *names; |
| 1831 | if (!ec->xkb_names.rules) |
| 1832 | ec->xkb_names.rules = strdup("evdev"); |
| 1833 | if (!ec->xkb_names.model) |
| 1834 | ec->xkb_names.model = strdup("pc105"); |
| 1835 | if (!ec->xkb_names.layout) |
| 1836 | ec->xkb_names.layout = strdup("us"); |
| 1837 | |
| 1838 | return 0; |
| 1839 | } |
| 1840 | |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1841 | static void |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1842 | weston_xkb_info_destroy(struct weston_xkb_info *xkb_info) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1843 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1844 | if (--xkb_info->ref_count > 0) |
| 1845 | return; |
| 1846 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1847 | if (xkb_info->keymap) |
| 1848 | xkb_map_unref(xkb_info->keymap); |
| 1849 | |
| 1850 | if (xkb_info->keymap_area) |
| 1851 | munmap(xkb_info->keymap_area, xkb_info->keymap_size); |
| 1852 | if (xkb_info->keymap_fd >= 0) |
| 1853 | close(xkb_info->keymap_fd); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1854 | free(xkb_info); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | void |
| 1858 | weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 1859 | { |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1860 | /* |
| 1861 | * If we're operating in raw keyboard mode, we never initialized |
| 1862 | * libxkbcommon so there's no cleanup to do either. |
| 1863 | */ |
| 1864 | if (!ec->use_xkbcommon) |
| 1865 | return; |
| 1866 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1867 | free((char *) ec->xkb_names.rules); |
| 1868 | free((char *) ec->xkb_names.model); |
| 1869 | free((char *) ec->xkb_names.layout); |
| 1870 | free((char *) ec->xkb_names.variant); |
| 1871 | free((char *) ec->xkb_names.options); |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1872 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1873 | if (ec->xkb_info) |
| 1874 | weston_xkb_info_destroy(ec->xkb_info); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1875 | xkb_context_unref(ec->xkb_context); |
| 1876 | } |
| 1877 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1878 | static struct weston_xkb_info * |
| 1879 | weston_xkb_info_create(struct xkb_keymap *keymap) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1880 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1881 | struct weston_xkb_info *xkb_info = zalloc(sizeof *xkb_info); |
| 1882 | if (xkb_info == NULL) |
| 1883 | return NULL; |
| 1884 | |
| 1885 | xkb_info->keymap = xkb_map_ref(keymap); |
| 1886 | xkb_info->ref_count = 1; |
| 1887 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1888 | char *keymap_str; |
| 1889 | |
| 1890 | xkb_info->shift_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1891 | XKB_MOD_NAME_SHIFT); |
| 1892 | xkb_info->caps_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1893 | XKB_MOD_NAME_CAPS); |
| 1894 | xkb_info->ctrl_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1895 | XKB_MOD_NAME_CTRL); |
| 1896 | xkb_info->alt_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1897 | XKB_MOD_NAME_ALT); |
| 1898 | xkb_info->mod2_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod2"); |
| 1899 | xkb_info->mod3_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod3"); |
| 1900 | xkb_info->super_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1901 | XKB_MOD_NAME_LOGO); |
| 1902 | xkb_info->mod5_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod5"); |
| 1903 | |
| 1904 | xkb_info->num_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1905 | XKB_LED_NAME_NUM); |
| 1906 | xkb_info->caps_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1907 | XKB_LED_NAME_CAPS); |
| 1908 | xkb_info->scroll_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1909 | XKB_LED_NAME_SCROLL); |
| 1910 | |
| 1911 | keymap_str = xkb_map_get_as_string(xkb_info->keymap); |
| 1912 | if (keymap_str == NULL) { |
| 1913 | weston_log("failed to get string version of keymap\n"); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1914 | goto err_keymap; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1915 | } |
| 1916 | xkb_info->keymap_size = strlen(keymap_str) + 1; |
| 1917 | |
| 1918 | xkb_info->keymap_fd = os_create_anonymous_file(xkb_info->keymap_size); |
| 1919 | if (xkb_info->keymap_fd < 0) { |
| 1920 | weston_log("creating a keymap file for %lu bytes failed: %m\n", |
| 1921 | (unsigned long) xkb_info->keymap_size); |
| 1922 | goto err_keymap_str; |
| 1923 | } |
| 1924 | |
| 1925 | xkb_info->keymap_area = mmap(NULL, xkb_info->keymap_size, |
| 1926 | PROT_READ | PROT_WRITE, |
| 1927 | MAP_SHARED, xkb_info->keymap_fd, 0); |
| 1928 | if (xkb_info->keymap_area == MAP_FAILED) { |
| 1929 | weston_log("failed to mmap() %lu bytes\n", |
| 1930 | (unsigned long) xkb_info->keymap_size); |
| 1931 | goto err_dev_zero; |
| 1932 | } |
| 1933 | strcpy(xkb_info->keymap_area, keymap_str); |
| 1934 | free(keymap_str); |
| 1935 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1936 | return xkb_info; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1937 | |
| 1938 | err_dev_zero: |
| 1939 | close(xkb_info->keymap_fd); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1940 | err_keymap_str: |
| 1941 | free(keymap_str); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1942 | err_keymap: |
| 1943 | xkb_map_unref(xkb_info->keymap); |
| 1944 | free(xkb_info); |
| 1945 | return NULL; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static int |
| 1949 | weston_compositor_build_global_keymap(struct weston_compositor *ec) |
| 1950 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1951 | struct xkb_keymap *keymap; |
| 1952 | |
| 1953 | if (ec->xkb_info != NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1954 | return 0; |
| 1955 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1956 | keymap = xkb_map_new_from_names(ec->xkb_context, |
| 1957 | &ec->xkb_names, |
| 1958 | 0); |
| 1959 | if (keymap == NULL) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1960 | weston_log("failed to compile global XKB keymap\n"); |
| 1961 | weston_log(" tried rules %s, model %s, layout %s, variant %s, " |
| 1962 | "options %s\n", |
| 1963 | ec->xkb_names.rules, ec->xkb_names.model, |
| 1964 | ec->xkb_names.layout, ec->xkb_names.variant, |
| 1965 | ec->xkb_names.options); |
| 1966 | return -1; |
| 1967 | } |
| 1968 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1969 | ec->xkb_info = weston_xkb_info_create(keymap); |
Rui Matos | 73d9395 | 2013-10-24 19:28:41 +0200 | [diff] [blame] | 1970 | xkb_keymap_unref(keymap); |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1971 | if (ec->xkb_info == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1972 | return -1; |
| 1973 | |
| 1974 | return 0; |
| 1975 | } |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1976 | #else |
| 1977 | int |
| 1978 | weston_compositor_xkb_init(struct weston_compositor *ec, |
| 1979 | struct xkb_rule_names *names) |
| 1980 | { |
| 1981 | return 0; |
| 1982 | } |
| 1983 | |
| 1984 | void |
| 1985 | weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 1986 | { |
| 1987 | } |
| 1988 | #endif |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1989 | |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1990 | WL_EXPORT void |
| 1991 | weston_seat_update_keymap(struct weston_seat *seat, struct xkb_keymap *keymap) |
| 1992 | { |
| 1993 | if (!seat->keyboard || !keymap) |
| 1994 | return; |
| 1995 | |
| 1996 | #ifdef ENABLE_XKBCOMMON |
| 1997 | if (!seat->compositor->use_xkbcommon) |
| 1998 | return; |
| 1999 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2000 | xkb_keymap_unref(seat->keyboard->pending_keymap); |
| 2001 | seat->keyboard->pending_keymap = xkb_keymap_ref(keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2002 | |
| 2003 | if (seat->keyboard->keys.size == 0) |
| 2004 | update_keymap(seat); |
| 2005 | #endif |
| 2006 | } |
| 2007 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2008 | WL_EXPORT int |
| 2009 | weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap) |
| 2010 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2011 | struct weston_keyboard *keyboard; |
| 2012 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2013 | if (seat->keyboard) { |
| 2014 | seat->keyboard_device_count += 1; |
| 2015 | if (seat->keyboard_device_count == 1) |
| 2016 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2017 | return 0; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2018 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2019 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2020 | keyboard = weston_keyboard_create(); |
| 2021 | if (keyboard == NULL) { |
| 2022 | weston_log("failed to allocate weston keyboard struct\n"); |
| 2023 | return -1; |
| 2024 | } |
| 2025 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2026 | #ifdef ENABLE_XKBCOMMON |
| 2027 | if (seat->compositor->use_xkbcommon) { |
| 2028 | if (keymap != NULL) { |
| 2029 | keyboard->xkb_info = weston_xkb_info_create(keymap); |
| 2030 | if (keyboard->xkb_info == NULL) |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2031 | goto err; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2032 | } else { |
| 2033 | if (weston_compositor_build_global_keymap(seat->compositor) < 0) |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2034 | goto err; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2035 | keyboard->xkb_info = seat->compositor->xkb_info; |
| 2036 | keyboard->xkb_info->ref_count++; |
| 2037 | } |
| 2038 | |
| 2039 | keyboard->xkb_state.state = xkb_state_new(keyboard->xkb_info->keymap); |
| 2040 | if (keyboard->xkb_state.state == NULL) { |
| 2041 | weston_log("failed to initialise XKB state\n"); |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2042 | goto err; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | keyboard->xkb_state.leds = 0; |
| 2046 | } |
| 2047 | #endif |
| 2048 | |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2049 | seat->keyboard = keyboard; |
| 2050 | seat->keyboard_device_count = 1; |
| 2051 | keyboard->seat = seat; |
| 2052 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2053 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2054 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2055 | return 0; |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 2056 | |
| 2057 | err: |
| 2058 | if (keyboard->xkb_info) |
| 2059 | weston_xkb_info_destroy(keyboard->xkb_info); |
| 2060 | free(keyboard); |
| 2061 | |
| 2062 | return -1; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2063 | } |
| 2064 | |
Jonas Ådahl | 91fed54 | 2013-12-03 09:14:27 +0100 | [diff] [blame] | 2065 | static void |
| 2066 | weston_keyboard_reset_state(struct weston_keyboard *keyboard) |
| 2067 | { |
| 2068 | struct weston_seat *seat = keyboard->seat; |
| 2069 | struct xkb_state *state; |
| 2070 | |
| 2071 | #ifdef ENABLE_XKBCOMMON |
| 2072 | if (seat->compositor->use_xkbcommon) { |
| 2073 | state = xkb_state_new(keyboard->xkb_info->keymap); |
| 2074 | if (!state) { |
| 2075 | weston_log("failed to reset XKB state\n"); |
| 2076 | return; |
| 2077 | } |
| 2078 | xkb_state_unref(keyboard->xkb_state.state); |
| 2079 | keyboard->xkb_state.state = state; |
| 2080 | |
| 2081 | keyboard->xkb_state.leds = 0; |
| 2082 | } |
| 2083 | #endif |
| 2084 | |
| 2085 | seat->modifier_state = 0; |
| 2086 | } |
| 2087 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2088 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2089 | weston_seat_release_keyboard(struct weston_seat *seat) |
| 2090 | { |
| 2091 | seat->keyboard_device_count--; |
| 2092 | if (seat->keyboard_device_count == 0) { |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2093 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2094 | weston_keyboard_cancel_grab(seat->keyboard); |
Jonas Ådahl | 91fed54 | 2013-12-03 09:14:27 +0100 | [diff] [blame] | 2095 | weston_keyboard_reset_state(seat->keyboard); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2096 | seat_send_updated_caps(seat); |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | WL_EXPORT void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2101 | weston_seat_init_pointer(struct weston_seat *seat) |
| 2102 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2103 | struct weston_pointer *pointer; |
| 2104 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2105 | if (seat->pointer) { |
| 2106 | seat->pointer_device_count += 1; |
| 2107 | if (seat->pointer_device_count == 1) |
| 2108 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2109 | return; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2110 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2111 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 2112 | pointer = weston_pointer_create(seat); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2113 | if (pointer == NULL) |
| 2114 | return; |
| 2115 | |
| 2116 | seat->pointer = pointer; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2117 | seat->pointer_device_count = 1; |
| 2118 | pointer->seat = seat; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2119 | |
| 2120 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2124 | weston_seat_release_pointer(struct weston_seat *seat) |
| 2125 | { |
| 2126 | struct weston_pointer *pointer = seat->pointer; |
| 2127 | |
| 2128 | seat->pointer_device_count--; |
| 2129 | if (seat->pointer_device_count == 0) { |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2130 | weston_pointer_set_focus(pointer, NULL, |
| 2131 | wl_fixed_from_int(0), |
| 2132 | wl_fixed_from_int(0)); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2133 | weston_pointer_cancel_grab(pointer); |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2134 | |
Jonas Ådahl | a493274 | 2013-10-17 23:04:07 +0200 | [diff] [blame] | 2135 | if (pointer->sprite) |
| 2136 | pointer_unmap_sprite(pointer); |
| 2137 | |
Jonas Ådahl | 3e12e63 | 2013-12-02 22:05:05 +0100 | [diff] [blame] | 2138 | weston_pointer_reset_state(pointer); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2139 | seat_send_updated_caps(seat); |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | WL_EXPORT void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2144 | weston_seat_init_touch(struct weston_seat *seat) |
| 2145 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2146 | struct weston_touch *touch; |
| 2147 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2148 | if (seat->touch) { |
| 2149 | seat->touch_device_count += 1; |
| 2150 | if (seat->touch_device_count == 1) |
| 2151 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2152 | return; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2153 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2154 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2155 | touch = weston_touch_create(); |
| 2156 | if (touch == NULL) |
| 2157 | return; |
| 2158 | |
| 2159 | seat->touch = touch; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2160 | seat->touch_device_count = 1; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2161 | touch->seat = seat; |
| 2162 | |
| 2163 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2167 | weston_seat_release_touch(struct weston_seat *seat) |
| 2168 | { |
| 2169 | seat->touch_device_count--; |
| 2170 | if (seat->touch_device_count == 0) { |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2171 | weston_touch_set_focus(seat, NULL); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2172 | weston_touch_cancel_grab(seat->touch); |
Jonas Ådahl | cbfa7f7 | 2013-12-02 22:05:04 +0100 | [diff] [blame] | 2173 | weston_touch_reset_state(seat->touch); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2174 | seat_send_updated_caps(seat); |
| 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | WL_EXPORT void |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 2179 | weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec, |
| 2180 | const char *seat_name) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2181 | { |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 2182 | memset(seat, 0, sizeof *seat); |
| 2183 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2184 | seat->selection_data_source = NULL; |
| 2185 | wl_list_init(&seat->base_resource_list); |
| 2186 | wl_signal_init(&seat->selection_signal); |
| 2187 | wl_list_init(&seat->drag_resource_list); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2188 | wl_signal_init(&seat->destroy_signal); |
Jason Ekstrand | a4ab542 | 2014-04-02 19:53:45 -0500 | [diff] [blame^] | 2189 | wl_signal_init(&seat->updated_caps_signal); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 2190 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 2191 | 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] | 2192 | seat, bind_seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2193 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2194 | seat->compositor = ec; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2195 | seat->modifier_state = 0; |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 2196 | seat->seat_name = strdup(seat_name); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2197 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2198 | wl_list_insert(ec->seat_list.prev, &seat->link); |
| 2199 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2200 | clipboard_create(seat); |
| 2201 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2202 | wl_signal_emit(&ec->seat_created_signal, seat); |
| 2203 | } |
| 2204 | |
| 2205 | WL_EXPORT void |
| 2206 | weston_seat_release(struct weston_seat *seat) |
| 2207 | { |
| 2208 | wl_list_remove(&seat->link); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2209 | |
Jonas Ådahl | 1afb238 | 2014-01-03 19:46:51 +0100 | [diff] [blame] | 2210 | if (seat->saved_kbd_focus) |
| 2211 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 2212 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2213 | if (seat->pointer) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2214 | weston_pointer_destroy(seat->pointer); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2215 | if (seat->keyboard) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2216 | weston_keyboard_destroy(seat->keyboard); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2217 | if (seat->touch) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2218 | weston_touch_destroy(seat->touch); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 2219 | |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 2220 | free (seat->seat_name); |
| 2221 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 2222 | wl_global_destroy(seat->global); |
Kristian Høgsberg | aaadc77 | 2013-07-08 16:20:31 -0400 | [diff] [blame] | 2223 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2224 | wl_signal_emit(&seat->destroy_signal, seat); |
| 2225 | } |