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