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 | |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame^] | 71 | /* Only enabled outputs with connected heads. |
| 72 | * This means force-enabled outputs but with disconnected heads |
| 73 | * will be ignored; if the touchscreen doesn't have a video signal, |
| 74 | * touching it is meaningless. |
| 75 | */ |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame] | 76 | wl_list_for_each(output, &compositor->output_list, link) { |
| 77 | wl_list_for_each(head, &output->head_list, output_link) { |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame^] | 78 | if (!weston_head_is_connected(head)) |
| 79 | continue; |
| 80 | |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame] | 81 | if (strcmp(head_name, head->name) == 0) |
| 82 | return output; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return NULL; |
| 87 | } |
| 88 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 89 | static void |
| 90 | device_added(struct udev_input *input, struct libinput_device *libinput_device) |
| 91 | { |
| 92 | struct weston_compositor *c; |
| 93 | struct evdev_device *device; |
| 94 | struct weston_output *output; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 95 | const char *output_name; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 96 | struct weston_seat *seat; |
| 97 | struct udev_seat *udev_seat; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 98 | struct weston_pointer *pointer; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 99 | |
| 100 | c = input->compositor; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 101 | |
Derek Foreman | a6714fa | 2015-05-05 15:01:51 -0500 | [diff] [blame] | 102 | udev_seat = get_udev_seat(input, libinput_device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 103 | if (!udev_seat) |
| 104 | return; |
| 105 | |
| 106 | seat = &udev_seat->base; |
| 107 | device = evdev_device_create(libinput_device, seat); |
| 108 | if (device == NULL) |
| 109 | return; |
| 110 | |
Giulio Camuffo | 8aedf7b | 2016-06-02 21:48:12 +0300 | [diff] [blame] | 111 | if (input->configure_device != NULL) |
| 112 | input->configure_device(c, device->device); |
| 113 | evdev_device_set_calibration(device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 114 | udev_seat = (struct udev_seat *) seat; |
| 115 | wl_list_insert(udev_seat->devices_list.prev, &device->link); |
| 116 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 117 | pointer = weston_seat_get_pointer(seat); |
| 118 | if (seat->output && pointer) |
| 119 | weston_pointer_clamp(pointer, |
| 120 | &pointer->x, |
| 121 | &pointer->y); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 122 | |
| 123 | output_name = libinput_device_get_output_name(libinput_device); |
| 124 | if (output_name) { |
| 125 | device->output_name = strdup(output_name); |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame] | 126 | output = output_find_by_head_name(c, output_name); |
| 127 | evdev_device_set_output(device, output); |
| 128 | } else if (!wl_list_empty(&c->output_list)) { |
| 129 | /* default assignment to an arbitrary output */ |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 130 | output = container_of(c->output_list.next, |
| 131 | struct weston_output, link); |
| 132 | evdev_device_set_output(device, output); |
| 133 | } |
| 134 | |
| 135 | if (!input->suspended) |
| 136 | weston_seat_repick(seat); |
| 137 | } |
| 138 | |
| 139 | static void |
Derek Foreman | 6b557a7 | 2015-05-05 15:01:52 -0500 | [diff] [blame] | 140 | device_removed(struct udev_input *input, struct libinput_device *libinput_device) |
| 141 | { |
| 142 | struct evdev_device *device; |
Derek Foreman | 0b7da01 | 2015-09-30 13:34:57 -0500 | [diff] [blame] | 143 | |
Derek Foreman | 6b557a7 | 2015-05-05 15:01:52 -0500 | [diff] [blame] | 144 | device = libinput_device_get_user_data(libinput_device); |
| 145 | evdev_device_destroy(device); |
| 146 | } |
| 147 | |
| 148 | static void |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 149 | udev_seat_remove_devices(struct udev_seat *seat) |
| 150 | { |
| 151 | struct evdev_device *device, *next; |
| 152 | |
| 153 | wl_list_for_each_safe(device, next, &seat->devices_list, link) { |
| 154 | evdev_device_destroy(device); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | void |
| 159 | udev_input_disable(struct udev_input *input) |
| 160 | { |
| 161 | if (input->suspended) |
| 162 | return; |
| 163 | |
Derek Foreman | 0e4e570 | 2017-07-25 16:39:20 -0500 | [diff] [blame] | 164 | wl_event_source_remove(input->libinput_source); |
| 165 | input->libinput_source = NULL; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 166 | libinput_suspend(input->libinput); |
| 167 | process_events(input); |
| 168 | input->suspended = 1; |
| 169 | } |
| 170 | |
| 171 | static int |
| 172 | udev_input_process_event(struct libinput_event *event) |
| 173 | { |
| 174 | struct libinput *libinput = libinput_event_get_context(event); |
| 175 | struct libinput_device *libinput_device = |
| 176 | libinput_event_get_device(event); |
| 177 | struct udev_input *input = libinput_get_user_data(libinput); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 178 | int handled = 1; |
| 179 | |
| 180 | switch (libinput_event_get_type(event)) { |
| 181 | case LIBINPUT_EVENT_DEVICE_ADDED: |
| 182 | device_added(input, libinput_device); |
| 183 | break; |
| 184 | case LIBINPUT_EVENT_DEVICE_REMOVED: |
Derek Foreman | 6b557a7 | 2015-05-05 15:01:52 -0500 | [diff] [blame] | 185 | device_removed(input, libinput_device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 186 | break; |
| 187 | default: |
| 188 | handled = 0; |
| 189 | } |
| 190 | |
| 191 | return handled; |
| 192 | } |
| 193 | |
| 194 | static void |
| 195 | process_event(struct libinput_event *event) |
| 196 | { |
| 197 | if (udev_input_process_event(event)) |
| 198 | return; |
| 199 | if (evdev_device_process_event(event)) |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | static void |
| 204 | process_events(struct udev_input *input) |
| 205 | { |
| 206 | struct libinput_event *event; |
| 207 | |
| 208 | while ((event = libinput_get_event(input->libinput))) { |
| 209 | process_event(event); |
| 210 | libinput_event_destroy(event); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | static int |
| 215 | udev_input_dispatch(struct udev_input *input) |
| 216 | { |
| 217 | if (libinput_dispatch(input->libinput) != 0) |
| 218 | weston_log("libinput: Failed to dispatch libinput\n"); |
| 219 | |
| 220 | process_events(input); |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static int |
| 226 | libinput_source_dispatch(int fd, uint32_t mask, void *data) |
| 227 | { |
| 228 | struct udev_input *input = data; |
| 229 | |
| 230 | return udev_input_dispatch(input) != 0; |
| 231 | } |
| 232 | |
| 233 | static int |
| 234 | open_restricted(const char *path, int flags, void *user_data) |
| 235 | { |
| 236 | struct udev_input *input = user_data; |
| 237 | struct weston_launcher *launcher = input->compositor->launcher; |
| 238 | |
| 239 | return weston_launcher_open(launcher, path, flags); |
| 240 | } |
| 241 | |
| 242 | static void |
| 243 | close_restricted(int fd, void *user_data) |
| 244 | { |
| 245 | struct udev_input *input = user_data; |
| 246 | struct weston_launcher *launcher = input->compositor->launcher; |
| 247 | |
| 248 | weston_launcher_close(launcher, fd); |
| 249 | } |
| 250 | |
| 251 | const struct libinput_interface libinput_interface = { |
| 252 | open_restricted, |
| 253 | close_restricted, |
| 254 | }; |
| 255 | |
| 256 | int |
| 257 | udev_input_enable(struct udev_input *input) |
| 258 | { |
| 259 | struct wl_event_loop *loop; |
| 260 | struct weston_compositor *c = input->compositor; |
| 261 | int fd; |
| 262 | struct udev_seat *seat; |
| 263 | int devices_found = 0; |
| 264 | |
| 265 | loop = wl_display_get_event_loop(c->wl_display); |
| 266 | fd = libinput_get_fd(input->libinput); |
| 267 | input->libinput_source = |
| 268 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 269 | libinput_source_dispatch, input); |
| 270 | if (!input->libinput_source) { |
| 271 | return -1; |
| 272 | } |
| 273 | |
| 274 | if (input->suspended) { |
| 275 | if (libinput_resume(input->libinput) != 0) { |
| 276 | wl_event_source_remove(input->libinput_source); |
| 277 | input->libinput_source = NULL; |
| 278 | return -1; |
| 279 | } |
| 280 | input->suspended = 0; |
| 281 | process_events(input); |
| 282 | } |
| 283 | |
| 284 | wl_list_for_each(seat, &input->compositor->seat_list, base.link) { |
| 285 | evdev_notify_keyboard_focus(&seat->base, &seat->devices_list); |
| 286 | |
| 287 | if (!wl_list_empty(&seat->devices_list)) |
| 288 | devices_found = 1; |
| 289 | } |
| 290 | |
Daniel Díaz | 75b7197 | 2016-10-21 14:03:13 -0500 | [diff] [blame] | 291 | if (devices_found == 0 && !c->require_input) { |
| 292 | weston_log("warning: no input devices found, but none required " |
| 293 | "as per configuration.\n"); |
| 294 | return 0; |
| 295 | } |
| 296 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 297 | if (devices_found == 0) { |
| 298 | weston_log( |
| 299 | "warning: no input devices on entering Weston. " |
| 300 | "Possible causes:\n" |
| 301 | "\t- no permissions to read /dev/input/event*\n" |
| 302 | "\t- seats misconfigured " |
| 303 | "(Weston backend option 'seat', " |
| 304 | "udev device property ID_SEAT)\n"); |
| 305 | return -1; |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
U. Artie Eoff | 71db0fd | 2014-04-17 07:53:22 -0700 | [diff] [blame] | 311 | static void |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 312 | libinput_log_func(struct libinput *libinput, |
| 313 | enum libinput_log_priority priority, |
| 314 | const char *format, va_list args) |
U. Artie Eoff | 71db0fd | 2014-04-17 07:53:22 -0700 | [diff] [blame] | 315 | { |
| 316 | weston_vlog(format, args); |
| 317 | } |
| 318 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 319 | int |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 320 | udev_input_init(struct udev_input *input, struct weston_compositor *c, |
Giulio Camuffo | 8aedf7b | 2016-06-02 21:48:12 +0300 | [diff] [blame] | 321 | struct udev *udev, const char *seat_id, |
| 322 | udev_configure_device_t configure_device) |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 323 | { |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 324 | enum libinput_log_priority priority = LIBINPUT_LOG_PRIORITY_INFO; |
U. Artie Eoff | c81c424 | 2014-04-17 07:53:23 -0700 | [diff] [blame] | 325 | const char *log_priority = NULL; |
| 326 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 327 | memset(input, 0, sizeof *input); |
| 328 | |
| 329 | input->compositor = c; |
Giulio Camuffo | 8aedf7b | 2016-06-02 21:48:12 +0300 | [diff] [blame] | 330 | input->configure_device = configure_device; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 331 | |
U. Artie Eoff | c81c424 | 2014-04-17 07:53:23 -0700 | [diff] [blame] | 332 | log_priority = getenv("WESTON_LIBINPUT_LOG_PRIORITY"); |
U. Artie Eoff | 24713f6 | 2014-05-09 11:24:40 -0700 | [diff] [blame] | 333 | |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 334 | input->libinput = libinput_udev_create_context(&libinput_interface, |
| 335 | input, udev); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 336 | if (!input->libinput) { |
| 337 | return -1; |
| 338 | } |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 339 | |
| 340 | libinput_log_set_handler(input->libinput, &libinput_log_func); |
| 341 | |
| 342 | if (log_priority) { |
| 343 | if (strcmp(log_priority, "debug") == 0) { |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 344 | priority = LIBINPUT_LOG_PRIORITY_DEBUG; |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 345 | } else if (strcmp(log_priority, "info") == 0) { |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 346 | priority = LIBINPUT_LOG_PRIORITY_INFO; |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 347 | } else if (strcmp(log_priority, "error") == 0) { |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 348 | priority = LIBINPUT_LOG_PRIORITY_ERROR; |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
Pekka Paalanen | eb4fd35 | 2014-09-12 12:07:43 +0300 | [diff] [blame] | 352 | libinput_log_set_priority(input->libinput, priority); |
| 353 | |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 354 | if (libinput_udev_assign_seat(input->libinput, seat_id) != 0) { |
| 355 | libinput_unref(input->libinput); |
| 356 | return -1; |
| 357 | } |
| 358 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 359 | process_events(input); |
| 360 | |
| 361 | return udev_input_enable(input); |
| 362 | } |
| 363 | |
| 364 | void |
| 365 | udev_input_destroy(struct udev_input *input) |
| 366 | { |
| 367 | struct udev_seat *seat, *next; |
| 368 | |
Derek Foreman | 0e4e570 | 2017-07-25 16:39:20 -0500 | [diff] [blame] | 369 | if (input->libinput_source) |
| 370 | wl_event_source_remove(input->libinput_source); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 371 | wl_list_for_each_safe(seat, next, &input->compositor->seat_list, base.link) |
| 372 | udev_seat_destroy(seat); |
Peter Hutterer | 3b843d3 | 2014-06-25 14:07:36 +1000 | [diff] [blame] | 373 | libinput_unref(input->libinput); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | static void |
| 377 | udev_seat_led_update(struct weston_seat *seat_base, enum weston_led leds) |
| 378 | { |
| 379 | struct udev_seat *seat = (struct udev_seat *) seat_base; |
| 380 | struct evdev_device *device; |
| 381 | |
| 382 | wl_list_for_each(device, &seat->devices_list, link) |
| 383 | evdev_led_update(device, leds); |
| 384 | } |
| 385 | |
| 386 | static void |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame^] | 387 | udev_seat_output_changed(struct udev_seat *seat, struct weston_output *output) |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 388 | { |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 389 | struct evdev_device *device; |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame] | 390 | struct weston_output *found; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 391 | |
Ander Conselvan de Oliveira | a7caef9 | 2014-04-24 15:11:17 +0300 | [diff] [blame] | 392 | wl_list_for_each(device, &seat->devices_list, link) { |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame] | 393 | /* If we find any input device without an associated output |
| 394 | * or an output name to associate with, just tie it with the |
| 395 | * output we got here - the default assingment. |
| 396 | */ |
| 397 | if (!device->output_name) { |
| 398 | if (!device->output) |
| 399 | evdev_device_set_output(device, output); |
| 400 | |
| 401 | continue; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 402 | } |
Ander Conselvan de Oliveira | a7caef9 | 2014-04-24 15:11:17 +0300 | [diff] [blame] | 403 | |
Pekka Paalanen | fd02efb | 2018-03-19 14:55:41 +0200 | [diff] [blame] | 404 | /* Update all devices' output associations, may they gain or |
| 405 | * lose it. |
| 406 | */ |
| 407 | found = output_find_by_head_name(output->compositor, |
| 408 | device->output_name); |
| 409 | evdev_device_set_output(device, found); |
Ander Conselvan de Oliveira | a7caef9 | 2014-04-24 15:11:17 +0300 | [diff] [blame] | 410 | } |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame^] | 413 | static void |
| 414 | notify_output_create(struct wl_listener *listener, void *data) |
| 415 | { |
| 416 | struct udev_seat *seat = container_of(listener, struct udev_seat, |
| 417 | output_create_listener); |
| 418 | struct weston_output *output = data; |
| 419 | |
| 420 | udev_seat_output_changed(seat, output); |
| 421 | } |
| 422 | |
| 423 | static void |
| 424 | notify_output_heads_changed(struct wl_listener *listener, void *data) |
| 425 | { |
| 426 | struct udev_seat *seat = container_of(listener, struct udev_seat, |
| 427 | output_heads_listener); |
| 428 | struct weston_output *output = data; |
| 429 | |
| 430 | udev_seat_output_changed(seat, output); |
| 431 | } |
| 432 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 433 | static struct udev_seat * |
| 434 | udev_seat_create(struct udev_input *input, const char *seat_name) |
| 435 | { |
| 436 | struct weston_compositor *c = input->compositor; |
| 437 | struct udev_seat *seat; |
| 438 | |
| 439 | seat = zalloc(sizeof *seat); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 440 | if (!seat) |
| 441 | return NULL; |
Bryce W. Harrington | bfd74f4 | 2014-04-21 23:51:02 +0000 | [diff] [blame] | 442 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 443 | weston_seat_init(&seat->base, c, seat_name); |
| 444 | seat->base.led_update = udev_seat_led_update; |
| 445 | |
| 446 | seat->output_create_listener.notify = notify_output_create; |
| 447 | wl_signal_add(&c->output_created_signal, |
| 448 | &seat->output_create_listener); |
| 449 | |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame^] | 450 | seat->output_heads_listener.notify = notify_output_heads_changed; |
| 451 | wl_signal_add(&c->output_heads_changed_signal, |
| 452 | &seat->output_heads_listener); |
| 453 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 454 | wl_list_init(&seat->devices_list); |
| 455 | |
| 456 | return seat; |
| 457 | } |
| 458 | |
| 459 | static void |
| 460 | udev_seat_destroy(struct udev_seat *seat) |
| 461 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 462 | struct weston_keyboard *keyboard = |
| 463 | weston_seat_get_keyboard(&seat->base); |
| 464 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 465 | if (keyboard) |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 466 | notify_keyboard_focus_out(&seat->base); |
Derek Foreman | 87c862a | 2015-08-06 12:19:51 -0500 | [diff] [blame] | 467 | |
| 468 | udev_seat_remove_devices(seat); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 469 | weston_seat_release(&seat->base); |
| 470 | wl_list_remove(&seat->output_create_listener.link); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame^] | 471 | wl_list_remove(&seat->output_heads_listener.link); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 472 | free(seat); |
| 473 | } |
| 474 | |
| 475 | struct udev_seat * |
| 476 | udev_seat_get_named(struct udev_input *input, const char *seat_name) |
| 477 | { |
| 478 | struct udev_seat *seat; |
| 479 | |
| 480 | wl_list_for_each(seat, &input->compositor->seat_list, base.link) { |
| 481 | if (strcmp(seat->base.seat_name, seat_name) == 0) |
| 482 | return seat; |
| 483 | } |
| 484 | |
| 485 | return udev_seat_create(input, seat_name); |
| 486 | } |