blob: cfd76599e43ecf250ddf2bb4ab935009aae8f3a5 [file] [log] [blame]
Jonas Ådahle0de3c22014-03-12 22:08:42 +01001/*
2 * Copyright © 2010 Intel Corporation
3 * Copyright © 2013 Jonas Ådahl
4 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -07005 * 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 Ådahle0de3c22014-03-12 22:08:42 +010012 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -070013 * 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 Ådahle0de3c22014-03-12 22:08:42 +010025 */
26
27#include "config.h"
28
29#include <errno.h>
30#include <stdlib.h>
31#include <string.h>
32#include <linux/input.h>
33#include <unistd.h>
34#include <fcntl.h>
35#include <mtdev.h>
36#include <assert.h>
37#include <libinput.h>
38
39#include "compositor.h"
40#include "libinput-device.h"
Jon Cruz867d50e2015-06-15 15:37:10 -070041#include "shared/helpers.h"
Jonas Ådahle0de3c22014-03-12 22:08:42 +010042
Jonas Ådahle0de3c22014-03-12 22:08:42 +010043void
44evdev_led_update(struct evdev_device *device, enum weston_led weston_leds)
45{
46 enum libinput_led leds = 0;
47
48 if (weston_leds & LED_NUM_LOCK)
49 leds |= LIBINPUT_LED_NUM_LOCK;
50 if (weston_leds & LED_CAPS_LOCK)
51 leds |= LIBINPUT_LED_CAPS_LOCK;
52 if (weston_leds & LED_SCROLL_LOCK)
53 leds |= LIBINPUT_LED_SCROLL_LOCK;
54
55 libinput_device_led_update(device->device, leds);
56}
57
58static void
59handle_keyboard_key(struct libinput_device *libinput_device,
60 struct libinput_event_keyboard *keyboard_event)
61{
62 struct evdev_device *device =
63 libinput_device_get_user_data(libinput_device);
Jonas Ådahl90d1ac82015-01-30 12:23:00 +080064 int key_state =
65 libinput_event_keyboard_get_key_state(keyboard_event);
66 int seat_key_count =
67 libinput_event_keyboard_get_seat_key_count(keyboard_event);
68
69 /* Ignore key events that are not seat wide state changes. */
70 if ((key_state == LIBINPUT_KEY_STATE_PRESSED &&
71 seat_key_count != 1) ||
72 (key_state == LIBINPUT_KEY_STATE_RELEASED &&
73 seat_key_count != 0))
74 return;
Jonas Ådahle0de3c22014-03-12 22:08:42 +010075
76 notify_key(device->seat,
77 libinput_event_keyboard_get_time(keyboard_event),
78 libinput_event_keyboard_get_key(keyboard_event),
Chris Michael7e7f7932016-02-22 08:47:24 -050079 key_state, STATE_UPDATE_AUTOMATIC);
Jonas Ådahle0de3c22014-03-12 22:08:42 +010080}
81
Peter Hutterer87743e92016-01-18 16:38:22 +100082static bool
Jonas Ådahle0de3c22014-03-12 22:08:42 +010083handle_pointer_motion(struct libinput_device *libinput_device,
84 struct libinput_event_pointer *pointer_event)
85{
86 struct evdev_device *device =
87 libinput_device_get_user_data(libinput_device);
Jonas Ådahld2510102014-10-05 21:39:14 +020088 struct weston_pointer_motion_event event = { 0 };
Jonas Ådahl3845b322014-10-21 23:51:29 +020089 double dx_unaccel, dy_unaccel;
90
91 dx_unaccel = libinput_event_pointer_get_dx_unaccelerated(pointer_event);
92 dy_unaccel = libinput_event_pointer_get_dy_unaccelerated(pointer_event);
Jonas Ådahle0de3c22014-03-12 22:08:42 +010093
Jonas Ådahld2510102014-10-05 21:39:14 +020094 event = (struct weston_pointer_motion_event) {
Jonas Ådahl3845b322014-10-21 23:51:29 +020095 .mask = WESTON_POINTER_MOTION_REL |
96 WESTON_POINTER_MOTION_REL_UNACCEL,
Jonas Ådahld2510102014-10-05 21:39:14 +020097 .dx = libinput_event_pointer_get_dx(pointer_event),
98 .dy = libinput_event_pointer_get_dy(pointer_event),
Jonas Ådahl3845b322014-10-21 23:51:29 +020099 .dx_unaccel = dx_unaccel,
100 .dy_unaccel = dy_unaccel,
Jonas Ådahld2510102014-10-05 21:39:14 +0200101 };
102
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100103 notify_motion(device->seat,
104 libinput_event_pointer_get_time(pointer_event),
Jonas Ådahld2510102014-10-05 21:39:14 +0200105 &event);
Peter Hutterer87743e92016-01-18 16:38:22 +1000106
107 return true;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100108}
109
Peter Hutterer87743e92016-01-18 16:38:22 +1000110static bool
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100111handle_pointer_motion_absolute(
112 struct libinput_device *libinput_device,
113 struct libinput_event_pointer *pointer_event)
114{
115 struct evdev_device *device =
116 libinput_device_get_user_data(libinput_device);
117 struct weston_output *output = device->output;
118 uint32_t time;
Giulio Camuffo90a6fc62016-03-22 17:44:54 +0200119 double x, y;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100120 uint32_t width, height;
121
122 if (!output)
Peter Hutterer87743e92016-01-18 16:38:22 +1000123 return false;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100124
125 time = libinput_event_pointer_get_time(pointer_event);
126 width = device->output->current_mode->width;
127 height = device->output->current_mode->height;
128
Giulio Camuffo90a6fc62016-03-22 17:44:54 +0200129 x = libinput_event_pointer_get_absolute_x_transformed(pointer_event,
130 width);
131 y = libinput_event_pointer_get_absolute_y_transformed(pointer_event,
132 height);
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100133
134 weston_output_transform_coordinate(device->output, x, y, &x, &y);
135 notify_motion_absolute(device->seat, time, x, y);
Peter Hutterer87743e92016-01-18 16:38:22 +1000136
137 return true;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100138}
139
Peter Hutterer87743e92016-01-18 16:38:22 +1000140static bool
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100141handle_pointer_button(struct libinput_device *libinput_device,
142 struct libinput_event_pointer *pointer_event)
143{
144 struct evdev_device *device =
145 libinput_device_get_user_data(libinput_device);
Jonas Ådahle90b9e92015-01-30 12:22:59 +0800146 int button_state =
147 libinput_event_pointer_get_button_state(pointer_event);
148 int seat_button_count =
149 libinput_event_pointer_get_seat_button_count(pointer_event);
150
151 /* Ignore button events that are not seat wide state changes. */
152 if ((button_state == LIBINPUT_BUTTON_STATE_PRESSED &&
153 seat_button_count != 1) ||
154 (button_state == LIBINPUT_BUTTON_STATE_RELEASED &&
155 seat_button_count != 0))
Peter Hutterer87743e92016-01-18 16:38:22 +1000156 return false;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100157
158 notify_button(device->seat,
159 libinput_event_pointer_get_time(pointer_event),
160 libinput_event_pointer_get_button(pointer_event),
Christopher Michaele1719c72016-02-19 11:07:00 -0500161 button_state);
162
Peter Hutterer87743e92016-01-18 16:38:22 +1000163 return true;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100164}
165
Peter Hutterer5dddd412015-01-15 13:14:43 +1000166static double
167normalize_scroll(struct libinput_event_pointer *pointer_event,
168 enum libinput_pointer_axis axis)
169{
Peter Hutterer5dddd412015-01-15 13:14:43 +1000170 enum libinput_pointer_axis_source source;
Peter Hutterer87743e92016-01-18 16:38:22 +1000171 double value = 0.0;
Peter Hutterer5dddd412015-01-15 13:14:43 +1000172
173 source = libinput_event_pointer_get_axis_source(pointer_event);
174 /* libinput < 0.8 sent wheel click events with value 10. Since 0.8
175 the value is the angle of the click in degrees. To keep
176 backwards-compat with existing clients, we just send multiples of
177 the click count.
178 */
179 switch (source) {
180 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
181 value = 10 * libinput_event_pointer_get_axis_value_discrete(
182 pointer_event,
183 axis);
184 break;
185 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
186 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
187 value = libinput_event_pointer_get_axis_value(pointer_event,
188 axis);
189 break;
Peter Hutterer5dddd412015-01-15 13:14:43 +1000190 }
191
192 return value;
193}
194
Peter Hutterer87743e92016-01-18 16:38:22 +1000195static int32_t
196get_axis_discrete(struct libinput_event_pointer *pointer_event,
197 enum libinput_pointer_axis axis)
198{
199 enum libinput_pointer_axis_source source;
200
201 source = libinput_event_pointer_get_axis_source(pointer_event);
202
203 if (source != LIBINPUT_POINTER_AXIS_SOURCE_WHEEL)
204 return 0;
205
206 return libinput_event_pointer_get_axis_value_discrete(pointer_event,
207 axis);
208}
209
210static bool
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100211handle_pointer_axis(struct libinput_device *libinput_device,
212 struct libinput_event_pointer *pointer_event)
213{
Peter Hutterer87743e92016-01-18 16:38:22 +1000214 static int warned;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100215 struct evdev_device *device =
216 libinput_device_get_user_data(libinput_device);
Peter Hutterer87743e92016-01-18 16:38:22 +1000217 double vert, horiz;
218 int32_t vert_discrete, horiz_discrete;
Peter Huttererc54f23d2015-01-13 11:55:37 +1000219 enum libinput_pointer_axis axis;
Peter Hutterer89b6a492016-01-18 15:58:17 +1000220 struct weston_pointer_axis_event weston_event;
Peter Hutterer87743e92016-01-18 16:38:22 +1000221 enum libinput_pointer_axis_source source;
222 uint32_t wl_axis_source;
223 bool has_vert, has_horiz;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100224
Peter Hutterer87743e92016-01-18 16:38:22 +1000225 has_vert = libinput_event_pointer_has_axis(pointer_event,
226 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
227 has_horiz = libinput_event_pointer_has_axis(pointer_event,
228 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
229
230 if (!has_vert && !has_horiz)
231 return false;
232
233 source = libinput_event_pointer_get_axis_source(pointer_event);
234 switch (source) {
235 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
236 wl_axis_source = WL_POINTER_AXIS_SOURCE_WHEEL;
237 break;
238 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
239 wl_axis_source = WL_POINTER_AXIS_SOURCE_FINGER;
240 break;
241 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
242 wl_axis_source = WL_POINTER_AXIS_SOURCE_CONTINUOUS;
243 break;
244 default:
245 if (warned < 5) {
246 weston_log("Unknown scroll source %d.\n", source);
247 warned++;
248 }
249 return false;
250 }
251
252 notify_axis_source(device->seat, wl_axis_source);
253
254 if (has_vert) {
255 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
256 vert_discrete = get_axis_discrete(pointer_event, axis);
257 vert = normalize_scroll(pointer_event, axis);
258
Peter Hutterer89b6a492016-01-18 15:58:17 +1000259 weston_event.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
Giulio Camuffo90a6fc62016-03-22 17:44:54 +0200260 weston_event.value = vert;
Peter Hutterer87743e92016-01-18 16:38:22 +1000261 weston_event.discrete = vert_discrete;
262 weston_event.has_discrete = (vert_discrete != 0);
263
Peter Huttererc54f23d2015-01-13 11:55:37 +1000264 notify_axis(device->seat,
265 libinput_event_pointer_get_time(pointer_event),
Peter Hutterer89b6a492016-01-18 15:58:17 +1000266 &weston_event);
Peter Huttererc54f23d2015-01-13 11:55:37 +1000267 }
268
Peter Hutterer87743e92016-01-18 16:38:22 +1000269 if (has_horiz) {
270 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
271 horiz_discrete = get_axis_discrete(pointer_event, axis);
272 horiz = normalize_scroll(pointer_event, axis);
273
Peter Hutterer89b6a492016-01-18 15:58:17 +1000274 weston_event.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
Giulio Camuffo90a6fc62016-03-22 17:44:54 +0200275 weston_event.value = horiz;
Peter Hutterer87743e92016-01-18 16:38:22 +1000276 weston_event.discrete = horiz_discrete;
277 weston_event.has_discrete = (horiz_discrete != 0);
278
Peter Huttererc54f23d2015-01-13 11:55:37 +1000279 notify_axis(device->seat,
280 libinput_event_pointer_get_time(pointer_event),
Peter Hutterer89b6a492016-01-18 15:58:17 +1000281 &weston_event);
Peter Huttererc54f23d2015-01-13 11:55:37 +1000282 }
Peter Hutterer87743e92016-01-18 16:38:22 +1000283
284 return true;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100285}
286
287static void
288handle_touch_with_coords(struct libinput_device *libinput_device,
289 struct libinput_event_touch *touch_event,
290 int touch_type)
291{
292 struct evdev_device *device =
293 libinput_device_get_user_data(libinput_device);
Giulio Camuffo90a6fc62016-03-22 17:44:54 +0200294 double x;
295 double y;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100296 uint32_t width, height;
297 uint32_t time;
298 int32_t slot;
299
Ander Conselvan de Oliveiraf957dfb2014-04-24 15:11:14 +0300300 if (!device->output)
301 return;
302
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100303 time = libinput_event_touch_get_time(touch_event);
304 slot = libinput_event_touch_get_seat_slot(touch_event);
305
306 width = device->output->current_mode->width;
307 height = device->output->current_mode->height;
Giulio Camuffo90a6fc62016-03-22 17:44:54 +0200308 x = libinput_event_touch_get_x_transformed(touch_event, width);
309 y = libinput_event_touch_get_y_transformed(touch_event, height);
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100310
311 weston_output_transform_coordinate(device->output,
312 x, y, &x, &y);
313
314 notify_touch(device->seat, time, slot, x, y, touch_type);
315}
316
317static void
318handle_touch_down(struct libinput_device *device,
319 struct libinput_event_touch *touch_event)
320{
321 handle_touch_with_coords(device, touch_event, WL_TOUCH_DOWN);
322}
323
324static void
325handle_touch_motion(struct libinput_device *device,
326 struct libinput_event_touch *touch_event)
327{
328 handle_touch_with_coords(device, touch_event, WL_TOUCH_MOTION);
329}
330
331static void
332handle_touch_up(struct libinput_device *libinput_device,
333 struct libinput_event_touch *touch_event)
334{
335 struct evdev_device *device =
336 libinput_device_get_user_data(libinput_device);
337 uint32_t time = libinput_event_touch_get_time(touch_event);
338 int32_t slot = libinput_event_touch_get_seat_slot(touch_event);
339
340 notify_touch(device->seat, time, slot, 0, 0, WL_TOUCH_UP);
341}
342
Jonas Ådahl1679f232014-04-12 09:39:51 +0200343static void
344handle_touch_frame(struct libinput_device *libinput_device,
345 struct libinput_event_touch *touch_event)
346{
347 struct evdev_device *device =
348 libinput_device_get_user_data(libinput_device);
349 struct weston_seat *seat = device->seat;
350
351 notify_touch_frame(seat);
352}
353
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100354int
355evdev_device_process_event(struct libinput_event *event)
356{
357 struct libinput_device *libinput_device =
358 libinput_event_get_device(event);
Peter Hutterer87743e92016-01-18 16:38:22 +1000359 struct evdev_device *device =
360 libinput_device_get_user_data(libinput_device);
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100361 int handled = 1;
Peter Hutterer87743e92016-01-18 16:38:22 +1000362 bool need_frame = false;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100363
364 switch (libinput_event_get_type(event)) {
365 case LIBINPUT_EVENT_KEYBOARD_KEY:
366 handle_keyboard_key(libinput_device,
367 libinput_event_get_keyboard_event(event));
368 break;
369 case LIBINPUT_EVENT_POINTER_MOTION:
Peter Hutterer87743e92016-01-18 16:38:22 +1000370 need_frame = handle_pointer_motion(libinput_device,
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100371 libinput_event_get_pointer_event(event));
372 break;
373 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
Peter Hutterer87743e92016-01-18 16:38:22 +1000374 need_frame = handle_pointer_motion_absolute(
375 libinput_device,
376 libinput_event_get_pointer_event(event));
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100377 break;
378 case LIBINPUT_EVENT_POINTER_BUTTON:
Peter Hutterer87743e92016-01-18 16:38:22 +1000379 need_frame = handle_pointer_button(libinput_device,
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100380 libinput_event_get_pointer_event(event));
381 break;
382 case LIBINPUT_EVENT_POINTER_AXIS:
Peter Hutterer87743e92016-01-18 16:38:22 +1000383 need_frame = handle_pointer_axis(
384 libinput_device,
385 libinput_event_get_pointer_event(event));
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100386 break;
387 case LIBINPUT_EVENT_TOUCH_DOWN:
388 handle_touch_down(libinput_device,
389 libinput_event_get_touch_event(event));
390 break;
391 case LIBINPUT_EVENT_TOUCH_MOTION:
392 handle_touch_motion(libinput_device,
393 libinput_event_get_touch_event(event));
394 break;
395 case LIBINPUT_EVENT_TOUCH_UP:
396 handle_touch_up(libinput_device,
397 libinput_event_get_touch_event(event));
U. Artie Eoffcd9e5452014-04-17 07:53:24 -0700398 break;
Jonas Ådahl1679f232014-04-12 09:39:51 +0200399 case LIBINPUT_EVENT_TOUCH_FRAME:
400 handle_touch_frame(libinput_device,
401 libinput_event_get_touch_event(event));
402 break;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100403 default:
404 handled = 0;
405 weston_log("unknown libinput event %d\n",
406 libinput_event_get_type(event));
407 }
408
Peter Hutterer87743e92016-01-18 16:38:22 +1000409 if (need_frame)
410 notify_pointer_frame(device->seat);
411
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100412 return handled;
413}
414
415static void
416notify_output_destroy(struct wl_listener *listener, void *data)
417{
418 struct evdev_device *device =
419 container_of(listener,
420 struct evdev_device, output_destroy_listener);
421 struct weston_compositor *c = device->seat->compositor;
422 struct weston_output *output;
423
Ander Conselvan de Oliveiraa7caef92014-04-24 15:11:17 +0300424 if (!device->output_name && !wl_list_empty(&c->output_list)) {
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100425 output = container_of(c->output_list.next,
426 struct weston_output, link);
427 evdev_device_set_output(device, output);
428 } else {
429 device->output = NULL;
430 }
431}
432
Peter Hutterer3fbba492014-09-09 13:02:25 +1000433/**
434 * The WL_CALIBRATION property requires a pixel-specific matrix to be
435 * applied after scaling device coordinates to screen coordinates. libinput
436 * can't do that, so we need to convert the calibration to the normalized
437 * format libinput expects.
438 */
Giulio Camuffo8aedf7b2016-06-02 21:48:12 +0300439void
Peter Hutterer3fbba492014-09-09 13:02:25 +1000440evdev_device_set_calibration(struct evdev_device *device)
441{
442 struct udev *udev;
443 struct udev_device *udev_device = NULL;
444 const char *sysname = libinput_device_get_sysname(device->device);
445 const char *calibration_values;
446 uint32_t width, height;
447 float calibration[6];
448 enum libinput_config_status status;
449
450 if (!device->output)
451 return;
452
453 width = device->output->width;
454 height = device->output->height;
455 if (width == 0 || height == 0)
456 return;
457
458 /* If libinput has a pre-set calibration matrix, don't override it */
459 if (!libinput_device_config_calibration_has_matrix(device->device) ||
460 libinput_device_config_calibration_get_default_matrix(
461 device->device,
462 calibration) != 0)
463 return;
464
465 udev = udev_new();
466 if (!udev)
467 return;
468
469 udev_device = udev_device_new_from_subsystem_sysname(udev,
470 "input",
471 sysname);
472 if (!udev_device)
473 goto out;
474
475 calibration_values =
476 udev_device_get_property_value(udev_device,
477 "WL_CALIBRATION");
478
479 if (!calibration_values || sscanf(calibration_values,
480 "%f %f %f %f %f %f",
481 &calibration[0],
482 &calibration[1],
483 &calibration[2],
484 &calibration[3],
485 &calibration[4],
486 &calibration[5]) != 6)
487 goto out;
488
489 weston_log("Applying calibration: %f %f %f %f %f %f "
490 "(normalized %f %f)\n",
491 calibration[0],
492 calibration[1],
493 calibration[2],
494 calibration[3],
495 calibration[4],
496 calibration[5],
497 calibration[2] / width,
498 calibration[5] / height);
499
500 /* normalize to a format libinput can use. There is a chance of
501 this being wrong if the width/height don't match the device
502 width/height but I'm not sure how to fix that */
503 calibration[2] /= width;
504 calibration[5] /= height;
505
506 status = libinput_device_config_calibration_set_matrix(device->device,
507 calibration);
508 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
509 weston_log("Failed to apply calibration.\n");
510
511out:
512 if (udev_device)
513 udev_device_unref(udev_device);
514 udev_unref(udev);
515}
516
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100517void
518evdev_device_set_output(struct evdev_device *device,
519 struct weston_output *output)
520{
U. Artie Eoff161c6c52014-04-17 07:53:25 -0700521 if (device->output_destroy_listener.notify) {
522 wl_list_remove(&device->output_destroy_listener.link);
523 device->output_destroy_listener.notify = NULL;
524 }
525
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100526 device->output = output;
527 device->output_destroy_listener.notify = notify_output_destroy;
528 wl_signal_add(&output->destroy_signal,
529 &device->output_destroy_listener);
Peter Hutterer3fbba492014-09-09 13:02:25 +1000530 evdev_device_set_calibration(device);
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100531}
532
533struct evdev_device *
534evdev_device_create(struct libinput_device *libinput_device,
535 struct weston_seat *seat)
536{
537 struct evdev_device *device;
538
539 device = zalloc(sizeof *device);
540 if (device == NULL)
541 return NULL;
542
543 device->seat = seat;
544 wl_list_init(&device->link);
545 device->device = libinput_device;
546
547 if (libinput_device_has_capability(libinput_device,
548 LIBINPUT_DEVICE_CAP_KEYBOARD)) {
549 weston_seat_init_keyboard(seat, NULL);
550 device->seat_caps |= EVDEV_SEAT_KEYBOARD;
551 }
552 if (libinput_device_has_capability(libinput_device,
553 LIBINPUT_DEVICE_CAP_POINTER)) {
554 weston_seat_init_pointer(seat);
555 device->seat_caps |= EVDEV_SEAT_POINTER;
556 }
557 if (libinput_device_has_capability(libinput_device,
558 LIBINPUT_DEVICE_CAP_TOUCH)) {
559 weston_seat_init_touch(seat);
560 device->seat_caps |= EVDEV_SEAT_TOUCH;
561 }
562
563 libinput_device_set_user_data(libinput_device, device);
564 libinput_device_ref(libinput_device);
565
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100566 return device;
567}
568
569void
570evdev_device_destroy(struct evdev_device *device)
571{
572 if (device->seat_caps & EVDEV_SEAT_POINTER)
573 weston_seat_release_pointer(device->seat);
574 if (device->seat_caps & EVDEV_SEAT_KEYBOARD)
575 weston_seat_release_keyboard(device->seat);
576 if (device->seat_caps & EVDEV_SEAT_TOUCH)
577 weston_seat_release_touch(device->seat);
578
579 if (device->output)
580 wl_list_remove(&device->output_destroy_listener.link);
581 wl_list_remove(&device->link);
582 libinput_device_unref(device->device);
583 free(device->devnode);
584 free(device->output_name);
585 free(device);
586}
587
588void
589evdev_notify_keyboard_focus(struct weston_seat *seat,
590 struct wl_list *evdev_devices)
591{
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100592 struct wl_array keys;
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100593
Derek Foremand621df22014-11-19 11:04:12 -0600594 if (seat->keyboard_device_count == 0)
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100595 return;
596
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100597 wl_array_init(&keys);
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100598 notify_keyboard_focus_in(seat, &keys, STATE_UPDATE_AUTOMATIC);
Jonas Ådahle0de3c22014-03-12 22:08:42 +0100599 wl_array_release(&keys);
600}