Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Intel Corporation |
| 3 | * Copyright © 2013 Jonas Ådahl |
| 4 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 12 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include "config.h" |
| 28 | |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 29 | #include <stdint.h> |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <unistd.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <libinput.h> |
| 35 | #include <libudev.h> |
| 36 | |
| 37 | #include "compositor.h" |
| 38 | #include "launcher-util.h" |
| 39 | #include "libinput-seat.h" |
| 40 | #include "libinput-device.h" |
Jon Cruz | 867d50e | 2015-06-15 15:37:10 -0700 | [diff] [blame] | 41 | #include "shared/helpers.h" |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 42 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 43 | static void |
| 44 | process_events(struct udev_input *input); |
| 45 | static struct udev_seat * |
| 46 | udev_seat_create(struct udev_input *input, const char *seat_name); |
| 47 | static void |
| 48 | udev_seat_destroy(struct udev_seat *seat); |
| 49 | |
Derek Foreman | a6714fa | 2015-05-05 15:01:51 -0500 | [diff] [blame] | 50 | static struct udev_seat * |
| 51 | get_udev_seat(struct udev_input *input, struct libinput_device *device) |
| 52 | { |
| 53 | struct libinput_seat *libinput_seat; |
| 54 | const char *seat_name; |
| 55 | |
| 56 | libinput_seat = libinput_device_get_seat(device); |
| 57 | seat_name = libinput_seat_get_logical_name(libinput_seat); |
| 58 | return udev_seat_get_named(input, seat_name); |
| 59 | } |
| 60 | |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame^] | 61 | static struct weston_output * |
| 62 | output_find_by_head_name(struct weston_compositor *compositor, |
| 63 | const char *head_name) |
| 64 | { |
| 65 | struct weston_output *output; |
| 66 | struct weston_head *head; |
| 67 | |
| 68 | if (!head_name) |
| 69 | return NULL; |
| 70 | |
| 71 | /* only enabled outputs */ |
| 72 | wl_list_for_each(output, &compositor->output_list, link) { |
| 73 | wl_list_for_each(head, &output->head_list, output_link) { |
| 74 | if (strcmp(head_name, head->name) == 0) |
| 75 | return output; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return NULL; |
| 80 | } |
| 81 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 82 | static void |
| 83 | device_added(struct udev_input *input, struct libinput_device *libinput_device) |
| 84 | { |
| 85 | struct weston_compositor *c; |
| 86 | struct evdev_device *device; |
| 87 | struct weston_output *output; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 88 | const char *output_name; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 89 | struct weston_seat *seat; |
| 90 | struct udev_seat *udev_seat; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 91 | struct weston_pointer *pointer; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 92 | |
| 93 | c = input->compositor; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 94 | |
Derek Foreman | a6714fa | 2015-05-05 15:01:51 -0500 | [diff] [blame] | 95 | udev_seat = get_udev_seat(input, libinput_device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 96 | if (!udev_seat) |
| 97 | return; |
| 98 | |
| 99 | seat = &udev_seat->base; |
| 100 | device = evdev_device_create(libinput_device, seat); |
| 101 | if (device == NULL) |
| 102 | return; |
| 103 | |
Giulio Camuffo | 8aedf7b | 2016-06-02 21:48:12 +0300 | [diff] [blame] | 104 | if (input->configure_device != NULL) |
| 105 | input->configure_device(c, device->device); |
| 106 | evdev_device_set_calibration(device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 107 | udev_seat = (struct udev_seat *) seat; |
| 108 | wl_list_insert(udev_seat->devices_list.prev, &device->link); |
| 109 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 110 | pointer = weston_seat_get_pointer(seat); |
| 111 | if (seat->output && pointer) |
| 112 | weston_pointer_clamp(pointer, |
| 113 | &pointer->x, |
| 114 | &pointer->y); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 115 | |
| 116 | output_name = libinput_device_get_output_name(libinput_device); |
| 117 | if (output_name) { |
| 118 | device->output_name = strdup(output_name); |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame^] | 119 | output = output_find_by_head_name(c, output_name); |
| 120 | evdev_device_set_output(device, output); |
| 121 | } else if (!wl_list_empty(&c->output_list)) { |
| 122 | /* default assignment to an arbitrary output */ |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 123 | output = container_of(c->output_list.next, |
| 124 | struct weston_output, link); |
| 125 | evdev_device_set_output(device, output); |
| 126 | } |
| 127 | |
| 128 | if (!input->suspended) |
| 129 | weston_seat_repick(seat); |
| 130 | } |
| 131 | |
| 132 | static void |
Derek Foreman | 6b557a7 | 2015-05-05 15:01:52 -0500 | [diff] [blame] | 133 | device_removed(struct udev_input *input, struct libinput_device *libinput_device) |
| 134 | { |
| 135 | struct evdev_device *device; |
Derek Foreman | 0b7da01 | 2015-09-30 13:34:57 -0500 | [diff] [blame] | 136 | |
Derek Foreman | 6b557a7 | 2015-05-05 15:01:52 -0500 | [diff] [blame] | 137 | device = libinput_device_get_user_data(libinput_device); |
| 138 | evdev_device_destroy(device); |
| 139 | } |
| 140 | |
| 141 | static void |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 142 | udev_seat_remove_devices(struct udev_seat *seat) |
| 143 | { |
| 144 | struct evdev_device *device, *next; |
| 145 | |
| 146 | wl_list_for_each_safe(device, next, &seat->devices_list, link) { |
| 147 | evdev_device_destroy(device); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | void |
| 152 | udev_input_disable(struct udev_input *input) |
| 153 | { |
| 154 | if (input->suspended) |
| 155 | return; |
| 156 | |
Derek Foreman | 0e4e570 | 2017-07-25 16:39:20 -0500 | [diff] [blame] | 157 | wl_event_source_remove(input->libinput_source); |
| 158 | input->libinput_source = NULL; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 159 | libinput_suspend(input->libinput); |
| 160 | process_events(input); |
| 161 | input->suspended = 1; |
| 162 | } |
| 163 | |
| 164 | static int |
| 165 | udev_input_process_event(struct libinput_event *event) |
| 166 | { |
| 167 | struct libinput *libinput = libinput_event_get_context(event); |
| 168 | struct libinput_device *libinput_device = |
| 169 | libinput_event_get_device(event); |
| 170 | struct udev_input *input = libinput_get_user_data(libinput); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 171 | int handled = 1; |
| 172 | |
| 173 | switch (libinput_event_get_type(event)) { |
| 174 | case LIBINPUT_EVENT_DEVICE_ADDED: |
| 175 | device_added(input, libinput_device); |
| 176 | break; |
| 177 | case LIBINPUT_EVENT_DEVICE_REMOVED: |
Derek Foreman | 6b557a7 | 2015-05-05 15:01:52 -0500 | [diff] [blame] | 178 | device_removed(input, libinput_device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 179 | break; |
| 180 | default: |
| 181 | handled = 0; |
| 182 | } |
| 183 | |
| 184 | return handled; |
| 185 | } |
| 186 | |
| 187 | static void |
| 188 | process_event(struct libinput_event *event) |
| 189 | { |
| 190 | if (udev_input_process_event(event)) |
| 191 | return; |
| 192 | if (evdev_device_process_event(event)) |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | static void |
| 197 | process_events(struct udev_input *input) |
| 198 | { |
| 199 | struct libinput_event *event; |
| 200 | |
| 201 | while ((event = libinput_get_event(input->libinput))) { |
| 202 | process_event(event); |
| 203 | libinput_event_destroy(event); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | static int |
| 208 | udev_input_dispatch(struct udev_input *input) |
| 209 | { |
| 210 | if (libinput_dispatch(input->libinput) != 0) |
| 211 | weston_log("libinput: Failed to dispatch libinput\n"); |
| 212 | |
| 213 | process_events(input); |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static int |
| 219 | libinput_source_dispatch(int fd, uint32_t mask, void *data) |
| 220 | { |
| 221 | struct udev_input *input = data; |
| 222 | |
| 223 | return udev_input_dispatch(input) != 0; |
| 224 | } |
| 225 | |
| 226 | static int |
| 227 | open_restricted(const char *path, int flags, void *user_data) |
| 228 | { |
| 229 | struct udev_input *input = user_data; |
| 230 | struct weston_launcher *launcher = input->compositor->launcher; |
| 231 | |
| 232 | return weston_launcher_open(launcher, path, flags); |
| 233 | } |
| 234 | |
| 235 | static void |
| 236 | close_restricted(int fd, void *user_data) |
| 237 | { |
| 238 | struct udev_input *input = user_data; |
| 239 | struct weston_launcher *launcher = input->compositor->launcher; |
| 240 | |
| 241 | weston_launcher_close(launcher, fd); |
| 242 | } |
| 243 | |
| 244 | const struct libinput_interface libinput_interface = { |
| 245 | open_restricted, |
| 246 | close_restricted, |
| 247 | }; |
| 248 | |
| 249 | int |
| 250 | udev_input_enable(struct udev_input *input) |
| 251 | { |
| 252 | struct wl_event_loop *loop; |
| 253 | struct weston_compositor *c = input->compositor; |
| 254 | int fd; |
| 255 | struct udev_seat *seat; |
| 256 | int devices_found = 0; |
| 257 | |
| 258 | loop = wl_display_get_event_loop(c->wl_display); |
| 259 | fd = libinput_get_fd(input->libinput); |
| 260 | input->libinput_source = |
| 261 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 262 | libinput_source_dispatch, input); |
| 263 | if (!input->libinput_source) { |
| 264 | return -1; |
| 265 | } |
| 266 | |
| 267 | if (input->suspended) { |
| 268 | if (libinput_resume(input->libinput) != 0) { |
| 269 | wl_event_source_remove(input->libinput_source); |
| 270 | input->libinput_source = NULL; |
| 271 | return -1; |
| 272 | } |
| 273 | input->suspended = 0; |
| 274 | process_events(input); |
| 275 | } |
| 276 | |
| 277 | wl_list_for_each(seat, &input->compositor->seat_list, base.link) { |
| 278 | evdev_notify_keyboard_focus(&seat->base, &seat->devices_list); |
| 279 | |
| 280 | if (!wl_list_empty(&seat->devices_list)) |
| 281 | devices_found = 1; |
| 282 | } |
| 283 | |
Daniel Díaz | 75b7197 | 2016-10-21 14:03:13 -0500 | [diff] [blame] | 284 | if (devices_found == 0 && !c->require_input) { |
| 285 | weston_log("warning: no input devices found, but none required " |
| 286 | "as per configuration.\n"); |
| 287 | return 0; |
| 288 | } |
| 289 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 290 | if (devices_found == 0) { |
| 291 | weston_log( |
| 292 | "warning: no input devices on entering Weston. " |
| 293 | "Possible causes:\n" |
| 294 | "\t- no permissions to read /dev/input/event*\n" |
| 295 | "\t- seats misconfigured " |
| 296 | "(Weston backend option 'seat', " |
| 297 | "udev device property ID_SEAT)\n"); |
| 298 | return -1; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
U. Artie Eoff | 71db0fd | 2014-04-17 07:53:22 -0700 | [diff] [blame] | 304 | static void |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 305 | libinput_log_func(struct libinput *libinput, |
| 306 | enum libinput_log_priority priority, |
| 307 | const char *format, va_list args) |
U. Artie Eoff | 71db0fd | 2014-04-17 07:53:22 -0700 | [diff] [blame] | 308 | { |
| 309 | weston_vlog(format, args); |
| 310 | } |
| 311 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 312 | int |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 313 | udev_input_init(struct udev_input *input, struct weston_compositor *c, |
Giulio Camuffo | 8aedf7b | 2016-06-02 21:48:12 +0300 | [diff] [blame] | 314 | struct udev *udev, const char *seat_id, |
| 315 | udev_configure_device_t configure_device) |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 316 | { |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 317 | enum libinput_log_priority priority = LIBINPUT_LOG_PRIORITY_INFO; |
U. Artie Eoff | c81c424 | 2014-04-17 07:53:23 -0700 | [diff] [blame] | 318 | const char *log_priority = NULL; |
| 319 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 320 | memset(input, 0, sizeof *input); |
| 321 | |
| 322 | input->compositor = c; |
Giulio Camuffo | 8aedf7b | 2016-06-02 21:48:12 +0300 | [diff] [blame] | 323 | input->configure_device = configure_device; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 324 | |
U. Artie Eoff | c81c424 | 2014-04-17 07:53:23 -0700 | [diff] [blame] | 325 | log_priority = getenv("WESTON_LIBINPUT_LOG_PRIORITY"); |
U. Artie Eoff | 24713f6 | 2014-05-09 11:24:40 -0700 | [diff] [blame] | 326 | |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 327 | input->libinput = libinput_udev_create_context(&libinput_interface, |
| 328 | input, udev); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 329 | if (!input->libinput) { |
| 330 | return -1; |
| 331 | } |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 332 | |
| 333 | libinput_log_set_handler(input->libinput, &libinput_log_func); |
| 334 | |
| 335 | if (log_priority) { |
| 336 | if (strcmp(log_priority, "debug") == 0) { |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 337 | priority = LIBINPUT_LOG_PRIORITY_DEBUG; |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 338 | } else if (strcmp(log_priority, "info") == 0) { |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 339 | priority = LIBINPUT_LOG_PRIORITY_INFO; |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 340 | } else if (strcmp(log_priority, "error") == 0) { |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 341 | priority = LIBINPUT_LOG_PRIORITY_ERROR; |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 345 | libinput_log_set_priority(input->libinput, priority); |
| 346 | |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 347 | if (libinput_udev_assign_seat(input->libinput, seat_id) != 0) { |
| 348 | libinput_unref(input->libinput); |
| 349 | return -1; |
| 350 | } |
| 351 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 352 | process_events(input); |
| 353 | |
| 354 | return udev_input_enable(input); |
| 355 | } |
| 356 | |
| 357 | void |
| 358 | udev_input_destroy(struct udev_input *input) |
| 359 | { |
| 360 | struct udev_seat *seat, *next; |
| 361 | |
Derek Foreman | 0e4e570 | 2017-07-25 16:39:20 -0500 | [diff] [blame] | 362 | if (input->libinput_source) |
| 363 | wl_event_source_remove(input->libinput_source); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 364 | wl_list_for_each_safe(seat, next, &input->compositor->seat_list, base.link) |
| 365 | udev_seat_destroy(seat); |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 366 | libinput_unref(input->libinput); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | static void |
| 370 | udev_seat_led_update(struct weston_seat *seat_base, enum weston_led leds) |
| 371 | { |
| 372 | struct udev_seat *seat = (struct udev_seat *) seat_base; |
| 373 | struct evdev_device *device; |
| 374 | |
| 375 | wl_list_for_each(device, &seat->devices_list, link) |
| 376 | evdev_led_update(device, leds); |
| 377 | } |
| 378 | |
| 379 | static void |
| 380 | notify_output_create(struct wl_listener *listener, void *data) |
| 381 | { |
| 382 | struct udev_seat *seat = container_of(listener, struct udev_seat, |
| 383 | output_create_listener); |
| 384 | struct evdev_device *device; |
| 385 | struct weston_output *output = data; |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame^] | 386 | struct weston_output *found; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 387 | |
Ander Conselvan de Oliveira | a7caef9 | 2014-04-24 15:11:17 +0300 | [diff] [blame] | 388 | wl_list_for_each(device, &seat->devices_list, link) { |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame^] | 389 | /* If we find any input device without an associated output |
| 390 | * or an output name to associate with, just tie it with the |
| 391 | * output we got here - the default assingment. |
| 392 | */ |
| 393 | if (!device->output_name) { |
| 394 | if (!device->output) |
| 395 | evdev_device_set_output(device, output); |
| 396 | |
| 397 | continue; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 398 | } |
Ander Conselvan de Oliveira | a7caef9 | 2014-04-24 15:11:17 +0300 | [diff] [blame] | 399 | |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame^] | 400 | /* Update all devices' output associations, may they gain or |
| 401 | * lose it. |
| 402 | */ |
| 403 | found = output_find_by_head_name(output->compositor, |
| 404 | device->output_name); |
| 405 | evdev_device_set_output(device, found); |
Ander Conselvan de Oliveira | a7caef9 | 2014-04-24 15:11:17 +0300 | [diff] [blame] | 406 | } |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static struct udev_seat * |
| 410 | udev_seat_create(struct udev_input *input, const char *seat_name) |
| 411 | { |
| 412 | struct weston_compositor *c = input->compositor; |
| 413 | struct udev_seat *seat; |
| 414 | |
| 415 | seat = zalloc(sizeof *seat); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 416 | if (!seat) |
| 417 | return NULL; |
Bryce W. Harrington | bfd74f4 | 2014-04-21 23:51:02 +0000 | [diff] [blame] | 418 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 419 | weston_seat_init(&seat->base, c, seat_name); |
| 420 | seat->base.led_update = udev_seat_led_update; |
| 421 | |
| 422 | seat->output_create_listener.notify = notify_output_create; |
| 423 | wl_signal_add(&c->output_created_signal, |
| 424 | &seat->output_create_listener); |
| 425 | |
| 426 | wl_list_init(&seat->devices_list); |
| 427 | |
| 428 | return seat; |
| 429 | } |
| 430 | |
| 431 | static void |
| 432 | udev_seat_destroy(struct udev_seat *seat) |
| 433 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 434 | struct weston_keyboard *keyboard = |
| 435 | weston_seat_get_keyboard(&seat->base); |
| 436 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 437 | if (keyboard) |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 438 | notify_keyboard_focus_out(&seat->base); |
Derek Foreman | 87c862a | 2015-08-06 12:19:51 -0500 | [diff] [blame] | 439 | |
| 440 | udev_seat_remove_devices(seat); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 441 | weston_seat_release(&seat->base); |
| 442 | wl_list_remove(&seat->output_create_listener.link); |
| 443 | free(seat); |
| 444 | } |
| 445 | |
| 446 | struct udev_seat * |
| 447 | udev_seat_get_named(struct udev_input *input, const char *seat_name) |
| 448 | { |
| 449 | struct udev_seat *seat; |
| 450 | |
| 451 | wl_list_for_each(seat, &input->compositor->seat_list, base.link) { |
| 452 | if (strcmp(seat->base.seat_name, seat_name) == 0) |
| 453 | return seat; |
| 454 | } |
| 455 | |
| 456 | return udev_seat_create(input, seat_name); |
| 457 | } |