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: |
Kristian Høgsberg | a30e29a | 2014-01-08 22:29:20 -0800 | [diff] [blame] | 1491 | if (touch->num_tp == 0) { |
| 1492 | /* This can happen if we start out with one or |
| 1493 | * more fingers on the touch screen, in which |
| 1494 | * case we didn't get the corresponding down |
| 1495 | * event. */ |
| 1496 | weston_log("unmatched touch up event\n"); |
| 1497 | break; |
| 1498 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1499 | weston_compositor_idle_release(ec); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1500 | touch->num_tp--; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1501 | |
| 1502 | grab->interface->up(grab, time, touch_id); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1503 | if (touch->num_tp == 0) |
Michael Fu | a2bb791 | 2013-07-23 15:51:06 +0800 | [diff] [blame] | 1504 | weston_touch_set_focus(seat, NULL); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1505 | break; |
| 1506 | } |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 1507 | |
| 1508 | weston_compositor_run_touch_binding(ec, seat, time, touch_type); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1512 | pointer_cursor_surface_configure(struct weston_surface *es, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1513 | int32_t dx, int32_t dy) |
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 | struct weston_pointer *pointer = es->configure_private; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1516 | int x, y; |
| 1517 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1518 | if (es->width == 0) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1519 | return; |
| 1520 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1521 | assert(es == pointer->sprite->surface); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1522 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1523 | pointer->hotspot_x -= dx; |
| 1524 | pointer->hotspot_y -= dy; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1525 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1526 | x = wl_fixed_to_int(pointer->x) - pointer->hotspot_x; |
| 1527 | y = wl_fixed_to_int(pointer->y) - pointer->hotspot_y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1528 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1529 | weston_view_set_position(pointer->sprite, x, y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1530 | |
| 1531 | empty_region(&es->pending.input); |
Ander Conselvan de Oliveira | 23900f7 | 2014-01-31 16:07:51 +0200 | [diff] [blame] | 1532 | empty_region(&es->input); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1533 | |
| 1534 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1535 | wl_list_insert(&es->compositor->cursor_layer.view_list, |
| 1536 | &pointer->sprite->layer_link); |
| 1537 | weston_view_update_transform(pointer->sprite); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1542 | pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, |
| 1543 | uint32_t serial, struct wl_resource *surface_resource, |
| 1544 | int32_t x, int32_t y) |
| 1545 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1546 | struct weston_pointer *pointer = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1547 | struct weston_surface *surface = NULL; |
| 1548 | |
| 1549 | if (surface_resource) |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1550 | surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1551 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1552 | if (pointer->focus == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1553 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1554 | /* pointer->focus->surface->resource can be NULL. Surfaces like the |
Giulio Camuffo | 1fd4b01 | 2013-06-20 18:13:07 +0200 | [diff] [blame] | 1555 | black_surface used in shell.c for fullscreen don't have |
| 1556 | a resource, but can still have focus */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1557 | if (pointer->focus->surface->resource == NULL) |
Giulio Camuffo | 1fd4b01 | 2013-06-20 18:13:07 +0200 | [diff] [blame] | 1558 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1559 | if (wl_resource_get_client(pointer->focus->surface->resource) != client) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1560 | return; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1561 | if (pointer->focus_serial - serial > UINT32_MAX / 2) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1562 | return; |
| 1563 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1564 | if (surface && pointer->sprite && surface != pointer->sprite->surface) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1565 | if (surface->configure) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1566 | wl_resource_post_error(surface->resource, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1567 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1568 | "surface->configure already " |
| 1569 | "set"); |
| 1570 | return; |
| 1571 | } |
| 1572 | } |
| 1573 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1574 | if (pointer->sprite) |
| 1575 | pointer_unmap_sprite(pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1576 | |
| 1577 | if (!surface) |
| 1578 | return; |
| 1579 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1580 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1581 | &pointer->sprite_destroy_listener); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1582 | |
| 1583 | surface->configure = pointer_cursor_surface_configure; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1584 | surface->configure_private = pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1585 | pointer->sprite = weston_view_create(surface); |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1586 | pointer->hotspot_x = x; |
| 1587 | pointer->hotspot_y = y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1588 | |
| 1589 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1590 | pointer_cursor_surface_configure(surface, 0, 0); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1591 | } |
| 1592 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1593 | static void |
| 1594 | pointer_release(struct wl_client *client, struct wl_resource *resource) |
| 1595 | { |
| 1596 | wl_resource_destroy(resource); |
| 1597 | } |
| 1598 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1599 | static const struct wl_pointer_interface pointer_interface = { |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1600 | pointer_set_cursor, |
| 1601 | pointer_release |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1602 | }; |
| 1603 | |
| 1604 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1605 | seat_get_pointer(struct wl_client *client, struct wl_resource *resource, |
| 1606 | uint32_t id) |
| 1607 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1608 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1609 | struct wl_resource *cr; |
| 1610 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1611 | if (!seat->pointer) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1612 | return; |
| 1613 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1614 | cr = wl_resource_create(client, &wl_pointer_interface, |
| 1615 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 1616 | if (cr == NULL) { |
| 1617 | wl_client_post_no_memory(client); |
| 1618 | return; |
| 1619 | } |
| 1620 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1621 | /* May be moved to focused list later by either |
| 1622 | * weston_pointer_set_focus or directly if this client is already |
| 1623 | * focused */ |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1624 | wl_list_insert(&seat->pointer->resource_list, wl_resource_get_link(cr)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1625 | wl_resource_set_implementation(cr, &pointer_interface, seat->pointer, |
| 1626 | unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1627 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1628 | if (seat->pointer->focus && seat->pointer->focus->surface->resource && |
| 1629 | wl_resource_get_client(seat->pointer->focus->surface->resource) == client) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1630 | wl_fixed_t sx, sy; |
| 1631 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1632 | weston_view_from_global_fixed(seat->pointer->focus, |
| 1633 | seat->pointer->x, |
| 1634 | seat->pointer->y, |
| 1635 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1636 | |
| 1637 | wl_list_remove(wl_resource_get_link(cr)); |
| 1638 | wl_list_insert(&seat->pointer->focus_resource_list, |
| 1639 | wl_resource_get_link(cr)); |
| 1640 | wl_pointer_send_enter(cr, |
| 1641 | seat->pointer->focus_serial, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1642 | seat->pointer->focus->surface->resource, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1643 | sx, sy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | static void |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1648 | keyboard_release(struct wl_client *client, struct wl_resource *resource) |
| 1649 | { |
| 1650 | wl_resource_destroy(resource); |
| 1651 | } |
| 1652 | |
| 1653 | static const struct wl_keyboard_interface keyboard_interface = { |
| 1654 | keyboard_release |
| 1655 | }; |
| 1656 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1657 | static int |
| 1658 | should_send_modifiers_to_client(struct weston_seat *seat, |
| 1659 | struct wl_client *client) |
| 1660 | { |
| 1661 | if (seat->keyboard && |
| 1662 | seat->keyboard->focus && |
Jason Ekstrand | 42133d4 | 2013-11-14 20:06:16 -0600 | [diff] [blame] | 1663 | seat->keyboard->focus->resource && |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1664 | wl_resource_get_client(seat->keyboard->focus->resource) == client) |
| 1665 | return 1; |
| 1666 | |
| 1667 | if (seat->pointer && |
| 1668 | seat->pointer->focus && |
Jason Ekstrand | 42133d4 | 2013-11-14 20:06:16 -0600 | [diff] [blame] | 1669 | seat->pointer->focus->surface->resource && |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1670 | wl_resource_get_client(seat->pointer->focus->surface->resource) == client) |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1671 | return 1; |
| 1672 | |
| 1673 | return 0; |
| 1674 | } |
| 1675 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1676 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1677 | seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, |
| 1678 | uint32_t id) |
| 1679 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1680 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1681 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1682 | struct wl_resource *cr; |
| 1683 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1684 | if (!seat->keyboard) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1685 | return; |
| 1686 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1687 | cr = wl_resource_create(client, &wl_keyboard_interface, |
| 1688 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 1689 | if (cr == NULL) { |
| 1690 | wl_client_post_no_memory(client); |
| 1691 | return; |
| 1692 | } |
| 1693 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1694 | /* May be moved to focused list later by either |
| 1695 | * weston_keyboard_set_focus or directly if this client is already |
| 1696 | * focused */ |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1697 | 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] | 1698 | wl_resource_set_implementation(cr, &keyboard_interface, |
| 1699 | seat, unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1700 | |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1701 | if (seat->compositor->use_xkbcommon) { |
| 1702 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1703 | keyboard->xkb_info->keymap_fd, |
| 1704 | keyboard->xkb_info->keymap_size); |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1705 | } else { |
| 1706 | int null_fd = open("/dev/null", O_RDONLY); |
| 1707 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, |
| 1708 | null_fd, |
| 1709 | 0); |
| 1710 | close(null_fd); |
| 1711 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1712 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1713 | if (should_send_modifiers_to_client(seat, client)) { |
| 1714 | send_modifiers_to_resource(seat->keyboard, |
| 1715 | cr, |
| 1716 | seat->keyboard->focus_serial); |
| 1717 | } |
| 1718 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1719 | if (seat->keyboard->focus && |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1720 | wl_resource_get_client(seat->keyboard->focus->resource) == client) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1721 | struct weston_surface *surface = |
| 1722 | (struct weston_surface *) seat->keyboard->focus; |
| 1723 | |
| 1724 | wl_list_remove(wl_resource_get_link(cr)); |
| 1725 | wl_list_insert(&seat->keyboard->focus_resource_list, |
| 1726 | wl_resource_get_link(cr)); |
| 1727 | wl_keyboard_send_enter(cr, |
| 1728 | seat->keyboard->focus_serial, |
| 1729 | surface->resource, |
| 1730 | &seat->keyboard->keys); |
| 1731 | |
| 1732 | /* If this is the first keyboard resource for this |
| 1733 | * client... */ |
| 1734 | if (seat->keyboard->focus_resource_list.prev == |
| 1735 | wl_resource_get_link(cr)) |
| 1736 | wl_data_device_set_keyboard_focus(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | static void |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1741 | touch_release(struct wl_client *client, struct wl_resource *resource) |
| 1742 | { |
| 1743 | wl_resource_destroy(resource); |
| 1744 | } |
| 1745 | |
| 1746 | static const struct wl_touch_interface touch_interface = { |
| 1747 | touch_release |
| 1748 | }; |
| 1749 | |
| 1750 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1751 | seat_get_touch(struct wl_client *client, struct wl_resource *resource, |
| 1752 | uint32_t id) |
| 1753 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1754 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1755 | struct wl_resource *cr; |
| 1756 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1757 | if (!seat->touch) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1758 | return; |
| 1759 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1760 | cr = wl_resource_create(client, &wl_touch_interface, |
| 1761 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 1762 | if (cr == NULL) { |
| 1763 | wl_client_post_no_memory(client); |
| 1764 | return; |
| 1765 | } |
| 1766 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1767 | if (seat->touch->focus && |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1768 | wl_resource_get_client(seat->touch->focus->surface->resource) == client) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1769 | wl_list_insert(&seat->touch->resource_list, |
| 1770 | wl_resource_get_link(cr)); |
| 1771 | } else { |
| 1772 | wl_list_insert(&seat->touch->focus_resource_list, |
| 1773 | wl_resource_get_link(cr)); |
| 1774 | } |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1775 | wl_resource_set_implementation(cr, &touch_interface, |
| 1776 | seat, unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | static const struct wl_seat_interface seat_interface = { |
| 1780 | seat_get_pointer, |
| 1781 | seat_get_keyboard, |
| 1782 | seat_get_touch, |
| 1783 | }; |
| 1784 | |
| 1785 | static void |
| 1786 | bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 1787 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1788 | struct weston_seat *seat = data; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1789 | struct wl_resource *resource; |
| 1790 | enum wl_seat_capability caps = 0; |
| 1791 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1792 | resource = wl_resource_create(client, |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 1793 | &wl_seat_interface, MIN(version, 3), id); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1794 | wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1795 | wl_resource_set_implementation(resource, &seat_interface, data, |
| 1796 | unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1797 | |
| 1798 | if (seat->pointer) |
| 1799 | caps |= WL_SEAT_CAPABILITY_POINTER; |
| 1800 | if (seat->keyboard) |
| 1801 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
| 1802 | if (seat->touch) |
| 1803 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 1804 | |
| 1805 | wl_seat_send_capabilities(resource, caps); |
Rob Bradford | e445ae6 | 2013-05-31 18:09:51 +0100 | [diff] [blame] | 1806 | if (version >= 2) |
| 1807 | wl_seat_send_name(resource, seat->seat_name); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1810 | #ifdef ENABLE_XKBCOMMON |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1811 | int |
| 1812 | weston_compositor_xkb_init(struct weston_compositor *ec, |
| 1813 | struct xkb_rule_names *names) |
| 1814 | { |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1815 | ec->use_xkbcommon = 1; |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1816 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1817 | if (ec->xkb_context == NULL) { |
| 1818 | ec->xkb_context = xkb_context_new(0); |
| 1819 | if (ec->xkb_context == NULL) { |
| 1820 | weston_log("failed to create XKB context\n"); |
| 1821 | return -1; |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | if (names) |
| 1826 | ec->xkb_names = *names; |
| 1827 | if (!ec->xkb_names.rules) |
| 1828 | ec->xkb_names.rules = strdup("evdev"); |
| 1829 | if (!ec->xkb_names.model) |
| 1830 | ec->xkb_names.model = strdup("pc105"); |
| 1831 | if (!ec->xkb_names.layout) |
| 1832 | ec->xkb_names.layout = strdup("us"); |
| 1833 | |
| 1834 | return 0; |
| 1835 | } |
| 1836 | |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1837 | static void |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1838 | weston_xkb_info_destroy(struct weston_xkb_info *xkb_info) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1839 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1840 | if (--xkb_info->ref_count > 0) |
| 1841 | return; |
| 1842 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1843 | if (xkb_info->keymap) |
| 1844 | xkb_map_unref(xkb_info->keymap); |
| 1845 | |
| 1846 | if (xkb_info->keymap_area) |
| 1847 | munmap(xkb_info->keymap_area, xkb_info->keymap_size); |
| 1848 | if (xkb_info->keymap_fd >= 0) |
| 1849 | close(xkb_info->keymap_fd); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1850 | free(xkb_info); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | void |
| 1854 | weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 1855 | { |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 1856 | /* |
| 1857 | * If we're operating in raw keyboard mode, we never initialized |
| 1858 | * libxkbcommon so there's no cleanup to do either. |
| 1859 | */ |
| 1860 | if (!ec->use_xkbcommon) |
| 1861 | return; |
| 1862 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1863 | free((char *) ec->xkb_names.rules); |
| 1864 | free((char *) ec->xkb_names.model); |
| 1865 | free((char *) ec->xkb_names.layout); |
| 1866 | free((char *) ec->xkb_names.variant); |
| 1867 | free((char *) ec->xkb_names.options); |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1868 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1869 | if (ec->xkb_info) |
| 1870 | weston_xkb_info_destroy(ec->xkb_info); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1871 | xkb_context_unref(ec->xkb_context); |
| 1872 | } |
| 1873 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1874 | static struct weston_xkb_info * |
| 1875 | weston_xkb_info_create(struct xkb_keymap *keymap) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1876 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1877 | struct weston_xkb_info *xkb_info = zalloc(sizeof *xkb_info); |
| 1878 | if (xkb_info == NULL) |
| 1879 | return NULL; |
| 1880 | |
| 1881 | xkb_info->keymap = xkb_map_ref(keymap); |
| 1882 | xkb_info->ref_count = 1; |
| 1883 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1884 | char *keymap_str; |
| 1885 | |
| 1886 | xkb_info->shift_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1887 | XKB_MOD_NAME_SHIFT); |
| 1888 | xkb_info->caps_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1889 | XKB_MOD_NAME_CAPS); |
| 1890 | xkb_info->ctrl_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1891 | XKB_MOD_NAME_CTRL); |
| 1892 | xkb_info->alt_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1893 | XKB_MOD_NAME_ALT); |
| 1894 | xkb_info->mod2_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod2"); |
| 1895 | xkb_info->mod3_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod3"); |
| 1896 | xkb_info->super_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1897 | XKB_MOD_NAME_LOGO); |
| 1898 | xkb_info->mod5_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod5"); |
| 1899 | |
| 1900 | xkb_info->num_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1901 | XKB_LED_NAME_NUM); |
| 1902 | xkb_info->caps_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1903 | XKB_LED_NAME_CAPS); |
| 1904 | xkb_info->scroll_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1905 | XKB_LED_NAME_SCROLL); |
| 1906 | |
| 1907 | keymap_str = xkb_map_get_as_string(xkb_info->keymap); |
| 1908 | if (keymap_str == NULL) { |
| 1909 | weston_log("failed to get string version of keymap\n"); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1910 | goto err_keymap; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1911 | } |
| 1912 | xkb_info->keymap_size = strlen(keymap_str) + 1; |
| 1913 | |
| 1914 | xkb_info->keymap_fd = os_create_anonymous_file(xkb_info->keymap_size); |
| 1915 | if (xkb_info->keymap_fd < 0) { |
| 1916 | weston_log("creating a keymap file for %lu bytes failed: %m\n", |
| 1917 | (unsigned long) xkb_info->keymap_size); |
| 1918 | goto err_keymap_str; |
| 1919 | } |
| 1920 | |
| 1921 | xkb_info->keymap_area = mmap(NULL, xkb_info->keymap_size, |
| 1922 | PROT_READ | PROT_WRITE, |
| 1923 | MAP_SHARED, xkb_info->keymap_fd, 0); |
| 1924 | if (xkb_info->keymap_area == MAP_FAILED) { |
| 1925 | weston_log("failed to mmap() %lu bytes\n", |
| 1926 | (unsigned long) xkb_info->keymap_size); |
| 1927 | goto err_dev_zero; |
| 1928 | } |
| 1929 | strcpy(xkb_info->keymap_area, keymap_str); |
| 1930 | free(keymap_str); |
| 1931 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1932 | return xkb_info; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1933 | |
| 1934 | err_dev_zero: |
| 1935 | close(xkb_info->keymap_fd); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1936 | err_keymap_str: |
| 1937 | free(keymap_str); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1938 | err_keymap: |
| 1939 | xkb_map_unref(xkb_info->keymap); |
| 1940 | free(xkb_info); |
| 1941 | return NULL; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | static int |
| 1945 | weston_compositor_build_global_keymap(struct weston_compositor *ec) |
| 1946 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1947 | struct xkb_keymap *keymap; |
| 1948 | |
| 1949 | if (ec->xkb_info != NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1950 | return 0; |
| 1951 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1952 | keymap = xkb_map_new_from_names(ec->xkb_context, |
| 1953 | &ec->xkb_names, |
| 1954 | 0); |
| 1955 | if (keymap == NULL) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1956 | weston_log("failed to compile global XKB keymap\n"); |
| 1957 | weston_log(" tried rules %s, model %s, layout %s, variant %s, " |
| 1958 | "options %s\n", |
| 1959 | ec->xkb_names.rules, ec->xkb_names.model, |
| 1960 | ec->xkb_names.layout, ec->xkb_names.variant, |
| 1961 | ec->xkb_names.options); |
| 1962 | return -1; |
| 1963 | } |
| 1964 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 1965 | ec->xkb_info = weston_xkb_info_create(keymap); |
Rui Matos | 73d9395 | 2013-10-24 19:28:41 +0200 | [diff] [blame] | 1966 | xkb_keymap_unref(keymap); |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1967 | if (ec->xkb_info == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1968 | return -1; |
| 1969 | |
| 1970 | return 0; |
| 1971 | } |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 1972 | #else |
| 1973 | int |
| 1974 | weston_compositor_xkb_init(struct weston_compositor *ec, |
| 1975 | struct xkb_rule_names *names) |
| 1976 | { |
| 1977 | return 0; |
| 1978 | } |
| 1979 | |
| 1980 | void |
| 1981 | weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 1982 | { |
| 1983 | } |
| 1984 | #endif |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1985 | |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1986 | WL_EXPORT void |
| 1987 | weston_seat_update_keymap(struct weston_seat *seat, struct xkb_keymap *keymap) |
| 1988 | { |
| 1989 | if (!seat->keyboard || !keymap) |
| 1990 | return; |
| 1991 | |
| 1992 | #ifdef ENABLE_XKBCOMMON |
| 1993 | if (!seat->compositor->use_xkbcommon) |
| 1994 | return; |
| 1995 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1996 | xkb_keymap_unref(seat->keyboard->pending_keymap); |
| 1997 | seat->keyboard->pending_keymap = xkb_keymap_ref(keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 1998 | |
| 1999 | if (seat->keyboard->keys.size == 0) |
| 2000 | update_keymap(seat); |
| 2001 | #endif |
| 2002 | } |
| 2003 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2004 | WL_EXPORT int |
| 2005 | weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap) |
| 2006 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2007 | struct weston_keyboard *keyboard; |
| 2008 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2009 | if (seat->keyboard) { |
| 2010 | seat->keyboard_device_count += 1; |
| 2011 | if (seat->keyboard_device_count == 1) |
| 2012 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2013 | return 0; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2014 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2015 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2016 | keyboard = weston_keyboard_create(); |
| 2017 | if (keyboard == NULL) { |
| 2018 | weston_log("failed to allocate weston keyboard struct\n"); |
| 2019 | return -1; |
| 2020 | } |
| 2021 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2022 | #ifdef ENABLE_XKBCOMMON |
| 2023 | if (seat->compositor->use_xkbcommon) { |
| 2024 | if (keymap != NULL) { |
| 2025 | keyboard->xkb_info = weston_xkb_info_create(keymap); |
| 2026 | if (keyboard->xkb_info == NULL) |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame^] | 2027 | goto err; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2028 | } else { |
| 2029 | if (weston_compositor_build_global_keymap(seat->compositor) < 0) |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame^] | 2030 | goto err; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2031 | keyboard->xkb_info = seat->compositor->xkb_info; |
| 2032 | keyboard->xkb_info->ref_count++; |
| 2033 | } |
| 2034 | |
| 2035 | keyboard->xkb_state.state = xkb_state_new(keyboard->xkb_info->keymap); |
| 2036 | if (keyboard->xkb_state.state == NULL) { |
| 2037 | weston_log("failed to initialise XKB state\n"); |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame^] | 2038 | goto err; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | keyboard->xkb_state.leds = 0; |
| 2042 | } |
| 2043 | #endif |
| 2044 | |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame^] | 2045 | seat->keyboard = keyboard; |
| 2046 | seat->keyboard_device_count = 1; |
| 2047 | keyboard->seat = seat; |
| 2048 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2049 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2050 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2051 | return 0; |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame^] | 2052 | |
| 2053 | err: |
| 2054 | if (keyboard->xkb_info) |
| 2055 | weston_xkb_info_destroy(keyboard->xkb_info); |
| 2056 | free(keyboard); |
| 2057 | |
| 2058 | return -1; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2059 | } |
| 2060 | |
Jonas Ådahl | 91fed54 | 2013-12-03 09:14:27 +0100 | [diff] [blame] | 2061 | static void |
| 2062 | weston_keyboard_reset_state(struct weston_keyboard *keyboard) |
| 2063 | { |
| 2064 | struct weston_seat *seat = keyboard->seat; |
| 2065 | struct xkb_state *state; |
| 2066 | |
| 2067 | #ifdef ENABLE_XKBCOMMON |
| 2068 | if (seat->compositor->use_xkbcommon) { |
| 2069 | state = xkb_state_new(keyboard->xkb_info->keymap); |
| 2070 | if (!state) { |
| 2071 | weston_log("failed to reset XKB state\n"); |
| 2072 | return; |
| 2073 | } |
| 2074 | xkb_state_unref(keyboard->xkb_state.state); |
| 2075 | keyboard->xkb_state.state = state; |
| 2076 | |
| 2077 | keyboard->xkb_state.leds = 0; |
| 2078 | } |
| 2079 | #endif |
| 2080 | |
| 2081 | seat->modifier_state = 0; |
| 2082 | } |
| 2083 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2084 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2085 | weston_seat_release_keyboard(struct weston_seat *seat) |
| 2086 | { |
| 2087 | seat->keyboard_device_count--; |
| 2088 | if (seat->keyboard_device_count == 0) { |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2089 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2090 | weston_keyboard_cancel_grab(seat->keyboard); |
Jonas Ådahl | 91fed54 | 2013-12-03 09:14:27 +0100 | [diff] [blame] | 2091 | weston_keyboard_reset_state(seat->keyboard); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2092 | seat_send_updated_caps(seat); |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | WL_EXPORT void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2097 | weston_seat_init_pointer(struct weston_seat *seat) |
| 2098 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2099 | struct weston_pointer *pointer; |
| 2100 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2101 | if (seat->pointer) { |
| 2102 | seat->pointer_device_count += 1; |
| 2103 | if (seat->pointer_device_count == 1) |
| 2104 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2105 | return; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2106 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2107 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 2108 | pointer = weston_pointer_create(seat); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2109 | if (pointer == NULL) |
| 2110 | return; |
| 2111 | |
| 2112 | seat->pointer = pointer; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2113 | seat->pointer_device_count = 1; |
| 2114 | pointer->seat = seat; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2115 | |
| 2116 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2120 | weston_seat_release_pointer(struct weston_seat *seat) |
| 2121 | { |
| 2122 | struct weston_pointer *pointer = seat->pointer; |
| 2123 | |
| 2124 | seat->pointer_device_count--; |
| 2125 | if (seat->pointer_device_count == 0) { |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2126 | weston_pointer_set_focus(pointer, NULL, |
| 2127 | wl_fixed_from_int(0), |
| 2128 | wl_fixed_from_int(0)); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2129 | weston_pointer_cancel_grab(pointer); |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2130 | |
Jonas Ådahl | a493274 | 2013-10-17 23:04:07 +0200 | [diff] [blame] | 2131 | if (pointer->sprite) |
| 2132 | pointer_unmap_sprite(pointer); |
| 2133 | |
Jonas Ådahl | 3e12e63 | 2013-12-02 22:05:05 +0100 | [diff] [blame] | 2134 | weston_pointer_reset_state(pointer); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2135 | seat_send_updated_caps(seat); |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | WL_EXPORT void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2140 | weston_seat_init_touch(struct weston_seat *seat) |
| 2141 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2142 | struct weston_touch *touch; |
| 2143 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2144 | if (seat->touch) { |
| 2145 | seat->touch_device_count += 1; |
| 2146 | if (seat->touch_device_count == 1) |
| 2147 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2148 | return; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2149 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2150 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2151 | touch = weston_touch_create(); |
| 2152 | if (touch == NULL) |
| 2153 | return; |
| 2154 | |
| 2155 | seat->touch = touch; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2156 | seat->touch_device_count = 1; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2157 | touch->seat = seat; |
| 2158 | |
| 2159 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2163 | weston_seat_release_touch(struct weston_seat *seat) |
| 2164 | { |
| 2165 | seat->touch_device_count--; |
| 2166 | if (seat->touch_device_count == 0) { |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 2167 | weston_touch_set_focus(seat, NULL); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2168 | weston_touch_cancel_grab(seat->touch); |
Jonas Ådahl | cbfa7f7 | 2013-12-02 22:05:04 +0100 | [diff] [blame] | 2169 | weston_touch_reset_state(seat->touch); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 2170 | seat_send_updated_caps(seat); |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | WL_EXPORT void |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 2175 | weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec, |
| 2176 | const char *seat_name) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2177 | { |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 2178 | memset(seat, 0, sizeof *seat); |
| 2179 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2180 | seat->selection_data_source = NULL; |
| 2181 | wl_list_init(&seat->base_resource_list); |
| 2182 | wl_signal_init(&seat->selection_signal); |
| 2183 | wl_list_init(&seat->drag_resource_list); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2184 | wl_signal_init(&seat->destroy_signal); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 2185 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 2186 | 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] | 2187 | seat, bind_seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2188 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2189 | seat->compositor = ec; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2190 | seat->modifier_state = 0; |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 2191 | seat->seat_name = strdup(seat_name); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2192 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2193 | wl_list_insert(ec->seat_list.prev, &seat->link); |
| 2194 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2195 | clipboard_create(seat); |
| 2196 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2197 | wl_signal_emit(&ec->seat_created_signal, seat); |
| 2198 | } |
| 2199 | |
| 2200 | WL_EXPORT void |
| 2201 | weston_seat_release(struct weston_seat *seat) |
| 2202 | { |
| 2203 | wl_list_remove(&seat->link); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2204 | |
Jonas Ådahl | 1afb238 | 2014-01-03 19:46:51 +0100 | [diff] [blame] | 2205 | if (seat->saved_kbd_focus) |
| 2206 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 2207 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2208 | if (seat->pointer) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2209 | weston_pointer_destroy(seat->pointer); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2210 | if (seat->keyboard) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2211 | weston_keyboard_destroy(seat->keyboard); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2212 | if (seat->touch) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 2213 | weston_touch_destroy(seat->touch); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 2214 | |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 2215 | free (seat->seat_name); |
| 2216 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 2217 | wl_global_destroy(seat->global); |
Kristian Høgsberg | aaadc77 | 2013-07-08 16:20:31 -0400 | [diff] [blame] | 2218 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2219 | wl_signal_emit(&seat->destroy_signal, seat); |
| 2220 | } |