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