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