Lines Matching refs:device

105 parse_udev_flag(struct evdev_device *device,
117 evdev_log_error(device,
128 evdev_update_key_down_count(struct evdev_device *device,
136 key_count = ++device->key_count[code];
138 if (device->key_count[code] > 0) {
139 key_count = --device->key_count[code];
141 evdev_log_bug_libinput(device,
144 device->key_count[code]);
149 evdev_log_bug_libinput(device,
158 evdev_device_switch_get_state(struct evdev_device *device,
161 struct evdev_dispatch *dispatch = device->dispatch;
169 evdev_pointer_notify_physical_button(struct evdev_device *device,
174 if (evdev_middlebutton_filter_button(device,
180 evdev_pointer_notify_button(device,
187 evdev_pointer_post_button(struct evdev_device *device,
194 down_count = evdev_update_key_down_count(device, button, state);
198 pointer_notify_button(&device->base, time, button, state);
201 if (device->left_handed.change_to_enabled)
202 device->left_handed.change_to_enabled(device);
204 if (device->scroll.change_scroll_method)
205 device->scroll.change_scroll_method(device);
214 struct evdev_device *device = data;
216 device->scroll.button_scroll_state = BUTTONSCROLL_READY;
220 evdev_button_scroll_button(struct evdev_device *device,
226 switch (device->scroll.lock_state) {
231 device->scroll.lock_state = BUTTONSCROLL_LOCK_FIRSTDOWN;
232 evdev_log_debug(device, "scroll lock: first down\n");
236 device->scroll.lock_state = BUTTONSCROLL_LOCK_FIRSTUP;
237 evdev_log_debug(device, "scroll lock: first up\n");
241 device->scroll.lock_state = BUTTONSCROLL_LOCK_SECONDDOWN;
242 evdev_log_debug(device, "scroll lock: second down\n");
246 device->scroll.lock_state = BUTTONSCROLL_LOCK_IDLE;
247 evdev_log_debug(device, "scroll lock: idle\n");
252 if (device->scroll.button < BTN_MOUSE + 5) {
257 device->scroll.button_scroll_state = BUTTONSCROLL_BUTTON_DOWN;
266 if (device->middlebutton.enabled &&
267 (device->scroll.button == BTN_LEFT ||
268 device->scroll.button == BTN_RIGHT)) {
272 libinput_timer_set_flags(&device->scroll.timer,
279 device->scroll.button_scroll_state = BUTTONSCROLL_READY;
281 device->scroll.button_down_time = time;
282 evdev_log_debug(device, "btnscroll: down\n");
284 libinput_timer_cancel(&device->scroll.timer);
285 switch(device->scroll.button_scroll_state) {
287 evdev_log_bug_libinput(device,
292 evdev_log_debug(device, "btnscroll: cancel\n");
297 evdev_pointer_post_button(device,
298 device->scroll.button_down_time,
299 device->scroll.button,
301 evdev_pointer_post_button(device, time,
302 device->scroll.button,
306 evdev_log_debug(device, "btnscroll: up\n");
307 evdev_stop_scroll(device, time,
312 device->scroll.button_scroll_state = BUTTONSCROLL_IDLE;
317 evdev_pointer_notify_button(struct evdev_device *device,
322 if (device->scroll.method == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN &&
323 button == device->scroll.button) {
324 evdev_button_scroll_button(device, time, state);
328 evdev_pointer_post_button(device, time, button, state);
332 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds)
345 if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD))
357 i = write(device->fd, ev, sizeof ev);
362 evdev_transform_absolute(struct evdev_device *device,
365 if (!device->abs.apply_calibration)
368 matrix_mult_vec(&device->abs.calibration, &point->x, &point->y);
372 evdev_transform_relative(struct evdev_device *device,
377 if (!device->abs.apply_calibration)
380 matrix_to_relative(&rel_matrix, &device->abs.calibration);
391 evdev_device_transform_x(struct evdev_device *device,
395 return scale_axis(device->abs.absinfo_x, x, width);
399 evdev_device_transform_y(struct evdev_device *device,
403 return scale_axis(device->abs.absinfo_y, y, height);
407 evdev_notify_axis_legacy_wheel(struct evdev_device *device,
416 if (device->scroll.invert_horizontal_scrolling) {
421 if (device->scroll.natural_scrolling_enabled) {
428 pointer_notify_axis_legacy_wheel(&device->base,
436 evdev_notify_axis_wheel(struct evdev_device *device,
445 if (device->scroll.invert_horizontal_scrolling) {
450 if (device->scroll.natural_scrolling_enabled) {
457 pointer_notify_axis_wheel(&device->base,
465 evdev_notify_axis_finger(struct evdev_device *device,
472 if (device->scroll.natural_scrolling_enabled) {
477 pointer_notify_axis_finger(&device->base,
484 evdev_notify_axis_continous(struct evdev_device *device,
491 if (device->scroll.natural_scrolling_enabled) {
496 pointer_notify_axis_continuous(&device->base,
503 evdev_tag_external_mouse(struct evdev_device *device,
508 bustype = libevdev_get_id_bustype(device->evdev);
510 device->tags |= EVDEV_TAG_EXTERNAL_MOUSE;
514 evdev_tag_trackpoint(struct evdev_device *device,
521 if (!libevdev_has_property(device->evdev,
523 !parse_udev_flag(device, udev_device, "ID_INPUT_POINTINGSTICK"))
526 device->tags |= EVDEV_TAG_TRACKPOINT;
528 quirks = evdev_libinput_context(device)->quirks;
529 q = quirks_fetch_for_device(quirks, device->udev_device);
534 device->tags |= EVDEV_TAG_EXTERNAL_MOUSE;
535 evdev_log_info(device,
538 evdev_log_info(device,
548 evdev_tag_keyboard_internal(struct evdev_device *device)
550 device->tags |= EVDEV_TAG_INTERNAL_KEYBOARD;
551 device->tags &= ~EVDEV_TAG_EXTERNAL_KEYBOARD;
555 evdev_tag_keyboard_external(struct evdev_device *device)
557 device->tags |= EVDEV_TAG_EXTERNAL_KEYBOARD;
558 device->tags &= ~EVDEV_TAG_INTERNAL_KEYBOARD;
562 evdev_tag_keyboard(struct evdev_device *device,
570 if (!libevdev_has_event_type(device->evdev, EV_KEY))
574 if (!libevdev_has_event_code(device->evdev,
580 quirks = evdev_libinput_context(device)->quirks;
581 q = quirks_fetch_for_device(quirks, device->udev_device);
584 evdev_tag_keyboard_internal(device);
586 evdev_tag_keyboard_external(device);
588 evdev_log_info(device,
596 device->tags |= EVDEV_TAG_KEYBOARD;
600 evdev_tag_tablet_touchpad(struct evdev_device *device)
602 device->tags |= EVDEV_TAG_TABLET_TOUCHPAD;
608 struct evdev_device *device = evdev_device(libinput_device);
610 return device->abs.absinfo_x && device->abs.absinfo_y;
617 struct evdev_device *device = evdev_device(libinput_device);
619 evdev_device_calibrate(device, matrix);
628 struct evdev_device *device = evdev_device(libinput_device);
630 matrix_to_farray6(&device->abs.usermatrix, matrix);
632 return !matrix_is_identity(&device->abs.usermatrix);
639 struct evdev_device *device = evdev_device(libinput_device);
641 matrix_to_farray6(&device->abs.default_calibration, matrix);
643 return !matrix_is_identity(&device->abs.default_calibration);
647 evdev_sendevents_get_modes(struct libinput_device *device)
653 evdev_sendevents_set_mode(struct libinput_device *device,
656 struct evdev_device *evdev = evdev_device(device);
679 evdev_sendevents_get_mode(struct libinput_device *device)
681 struct evdev_device *evdev = evdev_device(device);
688 evdev_sendevents_get_default_mode(struct libinput_device *device)
694 evdev_left_handed_has(struct libinput_device *device)
702 evdev_left_handed_set(struct libinput_device *device, int left_handed)
704 struct evdev_device *evdev = evdev_device(device);
714 evdev_left_handed_get(struct libinput_device *device)
716 struct evdev_device *evdev = evdev_device(device);
724 evdev_left_handed_get_default(struct libinput_device *device)
730 evdev_init_left_handed(struct evdev_device *device,
733 device->left_handed.config.has = evdev_left_handed_has;
734 device->left_handed.config.set = evdev_left_handed_set;
735 device->left_handed.config.get = evdev_left_handed_get;
736 device->left_handed.config.get_default = evdev_left_handed_get_default;
737 device->base.config.left_handed = &device->left_handed.config;
738 device->left_handed.enabled = false;
739 device->left_handed.want_enabled = false;
740 device->left_handed.change_to_enabled = change_to_left_handed;
744 evdev_scroll_get_methods(struct libinput_device *device)
750 evdev_scroll_set_method(struct libinput_device *device,
753 struct evdev_device *evdev = evdev_device(device);
762 evdev_scroll_get_method(struct libinput_device *device)
764 struct evdev_device *evdev = evdev_device(device);
772 evdev_scroll_get_default_method(struct libinput_device *device)
774 struct evdev_device *evdev = evdev_device(device);
790 evdev_scroll_set_button(struct libinput_device *device,
793 struct evdev_device *evdev = evdev_device(device);
802 evdev_scroll_get_button(struct libinput_device *device)
804 struct evdev_device *evdev = evdev_device(device);
812 evdev_scroll_get_default_button(struct libinput_device *device)
814 struct evdev_device *evdev = evdev_device(device);
832 evdev_scroll_set_button_lock(struct libinput_device *device,
835 struct evdev_device *evdev = evdev_device(device);
854 evdev_scroll_get_button_lock(struct libinput_device *device)
856 struct evdev_device *evdev = evdev_device(device);
865 evdev_scroll_get_default_button_lock(struct libinput_device *device)
871 evdev_set_button_scroll_lock_enabled(struct evdev_device *device,
875 device->scroll.lock_state = BUTTONSCROLL_LOCK_IDLE;
877 device->scroll.lock_state = BUTTONSCROLL_LOCK_DISABLED;
881 evdev_init_button_scroll(struct evdev_device *device,
889 evdev_device_get_sysname(device));
890 libinput_timer_init(&device->scroll.timer,
891 evdev_libinput_context(device),
893 evdev_button_scroll_timeout, device);
894 device->scroll.config.get_methods = evdev_scroll_get_methods;
895 device->scroll.config.set_method = evdev_scroll_set_method;
896 device->scroll.config.get_method = evdev_scroll_get_method;
897 device->scroll.config.get_default_method = evdev_scroll_get_default_method;
898 device->scroll.config.set_button = evdev_scroll_set_button;
899 device->scroll.config.get_button = evdev_scroll_get_button;
900 device->scroll.config.get_default_button = evdev_scroll_get_default_button;
901 device->scroll.config.set_button_lock = evdev_scroll_set_button_lock;
902 device->scroll.config.get_button_lock = evdev_scroll_get_button_lock;
903 device->scroll.config.get_default_button_lock = evdev_scroll_get_default_button_lock;
904 device->base.config.scroll_method = &device->scroll.config;
905 device->scroll.method = evdev_scroll_get_default_method((struct libinput_device *)device);
906 device->scroll.want_method = device->scroll.method;
907 device->scroll.button = evdev_scroll_get_default_button((struct libinput_device *)device);
908 device->scroll.want_button = device->scroll.button;
909 device->scroll.change_scroll_method = change_scroll_method;
913 evdev_init_calibration(struct evdev_device *device,
916 device->base.config.calibration = calibration;
925 evdev_init_sendevents(struct evdev_device *device,
928 device->base.config.sendevents = &dispatch->sendevents.config;
938 evdev_scroll_config_natural_has(struct libinput_device *device)
944 evdev_scroll_config_natural_set(struct libinput_device *device,
947 struct evdev_device *dev = evdev_device(device);
955 evdev_scroll_config_natural_get(struct libinput_device *device)
957 struct evdev_device *dev = evdev_device(device);
963 evdev_scroll_config_natural_get_default(struct libinput_device *device)
970 evdev_init_natural_scroll(struct evdev_device *device)
972 device->scroll.config_natural.has = evdev_scroll_config_natural_has;
973 device->scroll.config_natural.set_enabled = evdev_scroll_config_natural_set;
974 device->scroll.config_natural.get_enabled = evdev_scroll_config_natural_get;
975 device->scroll.config_natural.get_default_enabled = evdev_scroll_config_natural_get_default;
976 device->scroll.natural_scrolling_enabled = false;
977 device->base.config.natural_scroll = &device->scroll.config_natural;
981 evdev_need_mtdev(struct evdev_device *device)
983 struct libevdev *evdev = device->evdev;
994 evdev_is_fake_mt_device(struct evdev_device *device)
996 struct libevdev *evdev = device->evdev;
1003 evdev_read_switch_reliability_prop(struct evdev_device *device)
1010 quirks = evdev_libinput_context(device)->quirks;
1011 q = quirks_fetch_for_device(quirks, device->udev_device);
1015 evdev_log_error(device,
1017 device->devname,
1021 evdev_log_info(device, "will write switch open events\n");
1031 evdev_print_event(struct evdev_device *device,
1046 evdev_log_debug(device,
1054 evdev_log_debug(device,
1065 evdev_process_event(struct evdev_device *device, struct input_event *e)
1067 struct evdev_dispatch *dispatch = device->dispatch;
1071 evdev_print_event(device, e);
1074 libinput_timer_flush(evdev_libinput_context(device), time);
1076 dispatch->interface->process(dispatch, device, e, time);
1080 evdev_device_dispatch_one(struct evdev_device *device,
1083 if (!device->mtdev) {
1084 evdev_process_event(device, ev);
1086 mtdev_put_event(device->mtdev, ev);
1088 while (!mtdev_empty(device->mtdev)) {
1090 mtdev_get_event(device->mtdev, &e);
1091 evdev_process_event(device, &e);
1098 evdev_sync_device(struct evdev_device *device)
1104 rc = libevdev_next_event(device->evdev,
1108 evdev_device_dispatch_one(device, &ev);
1115 evdev_note_time_delay(struct evdev_device *device,
1118 struct libinput *libinput = evdev_libinput_context(device);
1134 evdev_log_bug_client_ratelimit(device,
1135 &device->delay_warning_limit,
1144 struct evdev_device *device = data;
1145 struct libinput *libinput = evdev_libinput_context(device);
1154 rc = libevdev_next_event(device->evdev,
1157 evdev_log_info_ratelimit(device,
1158 &device->syn_drop_limit,
1165 evdev_device_dispatch_one(device, &ev);
1167 rc = evdev_sync_device(device);
1172 evdev_note_time_delay(device, &ev);
1175 evdev_device_dispatch_one(device, &ev);
1177 evdev_device_remove(device);
1183 libinput_remove_source(libinput, device->source);
1184 device->source = NULL;
1189 evdev_init_accel(struct evdev_device *device,
1196 else if (device->tags & EVDEV_TAG_TRACKPOINT) {
1198 filter = create_pointer_accelerator_filter_trackpoint_flat(device->trackpoint_multiplier);
1200 filter = create_pointer_accelerator_filter_trackpoint(device->trackpoint_multiplier,
1201 device->use_velocity_averaging);
1204 filter = create_pointer_accelerator_filter_flat(device->dpi);
1205 else if (device->dpi < DEFAULT_MOUSE_DPI)
1206 filter = create_pointer_accelerator_filter_linear_low_dpi(device->dpi,
1207 device->use_velocity_averaging);
1211 filter = create_pointer_accelerator_filter_linear(device->dpi,
1212 device->use_velocity_averaging);
1217 evdev_device_init_pointer_acceleration(device, filter);
1223 evdev_accel_config_available(struct libinput_device *device)
1231 evdev_accel_config_set_speed(struct libinput_device *device, double speed)
1233 struct evdev_device *dev = evdev_device(device);
1242 evdev_accel_config_get_speed(struct libinput_device *device)
1244 struct evdev_device *dev = evdev_device(device);
1250 evdev_accel_config_get_default_speed(struct libinput_device *device)
1258 struct evdev_device *device = evdev_device(libinput_device);
1260 if (!device->pointer.filter)
1272 struct evdev_device *device = evdev_device(libinput_device);
1276 filter = device->pointer.filter;
1281 device->pointer.filter = NULL;
1283 if (evdev_init_accel(device, profile)) {
1287 device->pointer.filter = filter;
1297 struct evdev_device *device = evdev_device(libinput_device);
1299 return filter_get_type(device->pointer.filter);
1305 struct evdev_device *device = evdev_device(libinput_device);
1307 if (!device->pointer.filter)
1310 /* No device has a flat profile as default */
1329 evdev_device_init_pointer_acceleration(struct evdev_device *device,
1332 device->pointer.filter = filter;
1334 if (device->base.config.accel == NULL) {
1337 device->pointer.config.available = evdev_accel_config_available;
1338 device->pointer.config.set_speed = evdev_accel_config_set_speed;
1339 device->pointer.config.get_speed = evdev_accel_config_get_speed;
1340 device->pointer.config.get_default_speed = evdev_accel_config_get_default_speed;
1341 device->pointer.config.get_profiles = evdev_accel_config_get_profiles;
1342 device->pointer.config.set_profile = evdev_accel_config_set_profile;
1343 device->pointer.config.get_profile = evdev_accel_config_get_profile;
1344 device->pointer.config.get_default_profile = evdev_accel_config_get_default_profile;
1345 device->pointer.config.set_accel_config = evdev_set_accel_config;
1346 device->base.config.accel = &device->pointer.config;
1348 default_speed = evdev_accel_config_get_default_speed(&device->base);
1349 evdev_accel_config_set_speed(&device->base, default_speed);
1354 evdev_read_wheel_click_prop(struct evdev_device *device,
1361 prop = udev_device_get_property_value(device->udev_device, prop);
1371 evdev_log_error(device,
1380 evdev_read_wheel_click_count_prop(struct evdev_device *device,
1386 prop = udev_device_get_property_value(device->udev_device, prop);
1396 evdev_log_error(device,
1406 evdev_read_wheel_click_props(struct evdev_device *device)
1415 if (evdev_read_wheel_click_count_prop(device, wheel_count, &angles.y) ||
1416 evdev_read_wheel_click_prop(device, wheel_angle, &angles.y)) {
1417 evdev_log_debug(device,
1420 if (evdev_read_wheel_click_count_prop(device, hwheel_count, &angles.x) ||
1421 evdev_read_wheel_click_prop(device, hwheel_angle, &angles.x)) {
1422 evdev_log_debug(device,
1432 evdev_get_trackpoint_multiplier(struct evdev_device *device)
1438 if (!(device->tags & EVDEV_TAG_TRACKPOINT))
1441 quirks = evdev_libinput_context(device)->quirks;
1442 q = quirks_fetch_for_device(quirks, device->udev_device);
1449 evdev_log_bug_libinput(device,
1456 evdev_log_info(device,
1464 evdev_need_velocity_averaging(struct evdev_device *device)
1470 quirks = evdev_libinput_context(device)->quirks;
1471 q = quirks_fetch_for_device(quirks, device->udev_device);
1480 evdev_log_info(device,
1487 evdev_read_dpi_prop(struct evdev_device *device)
1492 if (device->tags & EVDEV_TAG_TRACKPOINT)
1495 mouse_dpi = udev_device_get_property_value(device->udev_device,
1500 evdev_log_error(device,
1506 evdev_log_info(device,
1507 "device set to %d DPI\n",
1515 evdev_read_model_flags(struct evdev_device *device)
1538 quirks = evdev_libinput_context(device)->quirks;
1539 q = quirks_fetch_for_device(quirks, device->udev_device);
1550 evdev_log_debug(device,
1555 evdev_log_debug(device,
1567 if (parse_udev_flag(device,
1568 device->udev_device,
1570 evdev_log_debug(device, "tagged as trackball\n");
1579 if (parse_udev_flag(device,
1580 device->udev_device,
1582 evdev_log_debug(device, "tagged as trackball\n");
1586 if (parse_udev_flag(device, device->udev_device,
1588 evdev_log_debug(device, "is a test device\n");
1596 evdev_read_attr_res_prop(struct evdev_device *device,
1605 quirks = evdev_libinput_context(device)->quirks;
1606 q = quirks_fetch_for_device(quirks, device->udev_device);
1622 evdev_read_attr_size_prop(struct evdev_device *device,
1631 quirks = evdev_libinput_context(device)->quirks;
1632 q = quirks_fetch_for_device(quirks, device->udev_device);
1647 /* Return 1 if the device is set to the fake resolution or 0 otherwise */
1649 evdev_fix_abs_resolution(struct evdev_device *device,
1653 struct libevdev *evdev = device->evdev;
1661 evdev_log_bug_libinput(device,
1675 * If a device needs this, add it to 60-evdev.hwdb. The libinput
1679 if (!evdev_read_attr_res_prop(device, &xres, &yres) &&
1680 evdev_read_attr_size_prop(device, &widthmm, &heightmm)) {
1694 evdev_device_get_udev_tags(struct evdev_device *device,
1704 if (parse_udev_flag(device,
1716 evdev_fix_android_mt(struct evdev_device *device)
1718 struct libevdev *evdev = device->evdev;
1726 evdev_is_fake_mt_device(device))
1736 evdev_check_min_max(struct evdev_device *device, unsigned int code)
1738 struct libevdev *evdev = device->evdev;
1753 evdev_log_info(device,
1754 "disabling EV_ABS %#x on device (min == max == 0)\n",
1756 libevdev_disable_event_code(device->evdev,
1760 evdev_log_bug_kernel(device,
1761 "device has min == max on %s\n",
1771 evdev_reject_device(struct evdev_device *device)
1773 struct libevdev *evdev = device->evdev;
1785 if (!evdev_is_fake_mt_device(device) &&
1795 evdev_log_bug_kernel(device,
1801 if (!evdev_is_fake_mt_device(device) &&
1807 evdev_log_bug_kernel(device,
1820 if (!evdev_check_min_max(device, code))
1829 evdev_extract_abs_axes(struct evdev_device *device,
1832 struct libevdev *evdev = device->evdev;
1839 if (evdev_fix_abs_resolution(device, ABS_X, ABS_Y))
1840 device->abs.is_fake_resolution = true;
1843 fuzz = evdev_read_fuzz_prop(device, ABS_X);
1845 fuzz = evdev_read_fuzz_prop(device, ABS_Y);
1849 device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_X);
1850 device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_Y);
1851 device->abs.dimensions.x = abs((int)absinfo_range(device->abs.absinfo_x));
1852 device->abs.dimensions.y = abs((int)absinfo_range(device->abs.absinfo_y));
1854 if (evdev_is_fake_mt_device(device) ||
1859 if (evdev_fix_abs_resolution(device,
1862 device->abs.is_fake_resolution = true;
1864 if ((fuzz = evdev_read_fuzz_prop(device, ABS_MT_POSITION_X)))
1866 if ((fuzz = evdev_read_fuzz_prop(device, ABS_MT_POSITION_Y)))
1869 device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
1870 device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
1871 device->abs.dimensions.x = abs((int)absinfo_range(device->abs.absinfo_x));
1872 device->abs.dimensions.y = abs((int)absinfo_range(device->abs.absinfo_y));
1873 device->is_mt = 1;
1877 evdev_disable_accelerometer_axes(struct evdev_device *device)
1879 struct libevdev *evdev = device->evdev;
1891 evdev_device_is_joystick_or_gamepad(struct evdev_device *device)
1895 struct libevdev *evdev = device->evdev;
1906 * 1. The device is tagged as joystick but not as tablet
1907 * 2. The device doesn't have 4 well-known keyboard keys
1911 udev_tags = evdev_device_get_udev_tags(device, device->udev_device);
1969 evdev_configure_device(struct evdev_device *device)
1971 struct libevdev *evdev = device->evdev;
1976 udev_tags = evdev_device_get_udev_tags(device, device->udev_device);
1980 evdev_log_info(device,
1981 "not tagged as supported input device\n");
1985 evdev_log_info(device,
2002 evdev_log_info(device,
2003 "device is an accelerometer, ignoring\n");
2008 evdev_disable_accelerometer_axes(device);
2011 if (evdev_device_is_joystick_or_gamepad(device)) {
2012 evdev_log_info(device,
2013 "device is a joystick or a gamepad, ignoring\n");
2017 if (evdev_reject_device(device)) {
2018 evdev_log_info(device, "was rejected\n");
2022 if (!evdev_is_fake_mt_device(device))
2023 evdev_fix_android_mt(device);
2026 evdev_extract_abs_axes(device, udev_tags);
2028 if (evdev_is_fake_mt_device(device))
2032 if (evdev_device_has_model_quirk(device,
2034 dispatch = evdev_totem_create(device);
2035 device->seat_caps |= EVDEV_DEVICE_TABLET;
2036 evdev_log_info(device, "device is a totem\n");
2042 interface for the touch device */
2049 dispatch = evdev_tablet_pad_create(device);
2050 device->seat_caps |= EVDEV_DEVICE_TABLET_PAD;
2051 evdev_log_info(device, "device is a tablet pad\n");
2057 dispatch = evdev_tablet_create(device);
2058 device->seat_caps |= EVDEV_DEVICE_TABLET;
2059 evdev_log_info(device, "device is a tablet\n");
2065 evdev_tag_tablet_touchpad(device);
2067 device->use_velocity_averaging = evdev_need_velocity_averaging(device);
2068 dispatch = evdev_mt_touchpad_create(device);
2069 evdev_log_info(device, "device is a touchpad\n");
2075 evdev_tag_external_mouse(device, device->udev_device);
2076 evdev_tag_trackpoint(device, device->udev_device);
2077 if (device->tags & EVDEV_TAG_TRACKPOINT)
2078 device->trackpoint_multiplier = evdev_get_trackpoint_multiplier(device);
2080 device->dpi = evdev_read_dpi_prop(device);
2082 device->use_velocity_averaging = evdev_need_velocity_averaging(device);
2084 device->seat_caps |= EVDEV_DEVICE_POINTER;
2086 evdev_log_info(device, "device is a pointer\n");
2089 device->left_handed.want_enabled = true;
2091 device->scroll.natural_scrolling_enabled = true;
2095 device->scroll.want_button = 1;
2099 device->seat_caps |= EVDEV_DEVICE_KEYBOARD;
2100 evdev_log_info(device, "device is a keyboard\n");
2105 device->scroll.natural_scrolling_enabled = true;
2106 device->seat_caps |= EVDEV_DEVICE_POINTER;
2109 evdev_tag_keyboard(device, device->udev_device);
2113 device->seat_caps |= EVDEV_DEVICE_TOUCH;
2114 evdev_log_info(device, "device is a touch device\n");
2119 device->seat_caps |= EVDEV_DEVICE_SWITCH;
2120 device->tags |= EVDEV_TAG_LID_SWITCH;
2124 if (evdev_device_has_model_quirk(device,
2126 evdev_log_info(device,
2127 "device is an unreliable tablet mode switch, filtering events.\n");
2128 libevdev_disable_event_code(device->evdev,
2132 device->tags |= EVDEV_TAG_TABLET_MODE_SWITCH;
2133 device->seat_caps |= EVDEV_DEVICE_SWITCH;
2137 if (device->seat_caps & EVDEV_DEVICE_SWITCH)
2138 evdev_log_info(device, "device is a switch device\n");
2141 if (device->seat_caps & EVDEV_DEVICE_POINTER &&
2144 !evdev_init_accel(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE)) {
2145 evdev_log_error(device,
2150 if (evdev_device_has_model_quirk(device, QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING)) {
2151 device->scroll.invert_horizontal_scrolling = true;
2154 return fallback_dispatch_create(&device->base);
2158 evdev_notify_added_device(struct evdev_device *device)
2162 list_for_each(dev, &device->base.seat->devices_list, link) {
2164 if (dev == &device->base)
2167 /* Notify existing device d about addition of device */
2169 d->dispatch->interface->device_added(d, device);
2171 /* Notify new device about existing device d */
2172 if (device->dispatch->interface->device_added)
2173 device->dispatch->interface->device_added(device, d);
2175 /* Notify new device if existing device d is suspended */
2177 device->dispatch->interface->device_suspended)
2178 device->dispatch->interface->device_suspended(device, d);
2181 notify_added_device(&device->base);
2183 if (device->dispatch->interface->post_added)
2184 device->dispatch->interface->post_added(device,
2185 device->dispatch);
2212 evdev_set_device_group(struct evdev_device *device,
2215 struct libinput *libinput = evdev_libinput_context(device);
2228 libinput_device_set_device_group(&device->base, group);
2231 libinput_device_set_device_group(&device->base, group);
2249 evdev_pre_configure_model_quirks(struct evdev_device *device)
2258 if (evdev_device_has_model_quirk(device, QUIRK_MODEL_HP_ZBOOK_STUDIO_G3))
2259 libevdev_set_abs_maximum(device->evdev, ABS_MT_SLOT, 1);
2264 quirks = evdev_libinput_context(device)->quirks;
2265 q = quirks_fetch_for_device(quirks, device->udev_device);
2269 libevdev_disable_event_code(device->evdev, EV_MSC, MSC_TIMESTAMP);
2285 libevdev_enable_event_type(device->evdev, type);
2287 libevdev_disable_event_type(device->evdev, type);
2290 libevdev_enable_event_code(device->evdev,
2295 libevdev_disable_event_code(device->evdev,
2299 evdev_log_debug(device,
2315 libevdev_enable_property(device->evdev, p);
2319 libevdev_disable_property(device->evdev, p);
2321 evdev_log_error(device,
2322 "quirks: a quirk for this device requires newer libevdev than installed\n");
2325 evdev_log_debug(device,
2387 struct evdev_device *device = NULL;
2395 log_info(libinput, "%s: no device node associated\n", sysname);
2400 log_debug(libinput, "%s: device is ignored\n", sysname);
2411 "%s: opening input device '%s' failed (%s).\n",
2421 device = zalloc(sizeof *device);
2422 device->sysname = sysname;
2425 libinput_device_init(&device->base, seat);
2430 rc = libevdev_new_from_fd(fd, &device->evdev);
2434 libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC);
2435 libevdev_set_device_log_function(device->evdev,
2439 device->seat_caps = 0;
2440 device->is_mt = 0;
2441 device->mtdev = NULL;
2442 device->udev_device = udev_device_ref(udev_device);
2443 device->dispatch = NULL;
2444 device->fd = fd;
2445 device->devname = libevdev_get_name(device->evdev);
2448 device->log_prefix_name = str_sanitize(device->devname);
2449 device->scroll.threshold = 5.0; /* Default may be overridden */
2450 device->scroll.direction_lock_threshold = 5.0; /* Default may be overridden */
2451 device->scroll.direction = 0;
2452 device->scroll.wheel_click_angle =
2453 evdev_read_wheel_click_props(device);
2454 device->model_flags = evdev_read_model_flags(device);
2455 device->dpi = DEFAULT_MOUSE_DPI;
2458 ratelimit_init(&device->syn_drop_limit, s2us(30), 5);
2460 ratelimit_init(&device->delay_warning_limit, s2us(60 * 60), 5);
2462 ratelimit_init(&device->nonpointer_rel_limit, s2us(5), 5);
2464 matrix_init_identity(&device->abs.calibration);
2465 matrix_init_identity(&device->abs.usermatrix);
2466 matrix_init_identity(&device->abs.default_calibration);
2468 evdev_pre_configure_model_quirks(device);
2470 device->dispatch = evdev_configure_device(device);
2471 if (device->dispatch == NULL || device->seat_caps == 0)
2474 device->source =
2475 libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
2476 if (!device->source)
2479 if (!evdev_set_device_group(device, udev_device))
2482 list_insert(seat->devices_list.prev, &device->base.link);
2484 evdev_notify_added_device(device);
2486 return device;
2491 if (device) {
2492 unhandled_device = device->seat_caps == 0;
2493 evdev_device_destroy(device);
2503 evdev_device_get_output(struct evdev_device *device)
2505 return device->output_name;
2509 evdev_device_get_sysname(struct evdev_device *device)
2511 return device->sysname;
2515 evdev_device_get_name(struct evdev_device *device)
2517 return device->devname;
2521 evdev_device_get_id_product(struct evdev_device *device)
2523 return libevdev_get_id_product(device->evdev);
2527 evdev_device_get_id_vendor(struct evdev_device *device)
2529 return libevdev_get_id_vendor(device->evdev);
2533 evdev_device_get_udev_device(struct evdev_device *device)
2535 return udev_device_ref(device->udev_device);
2539 evdev_device_set_default_calibration(struct evdev_device *device,
2542 matrix_from_farray6(&device->abs.default_calibration, calibration);
2543 evdev_device_calibrate(device, calibration);
2547 evdev_device_calibrate(struct evdev_device *device,
2556 device->abs.apply_calibration = !matrix_is_identity(&transform);
2559 matrix_from_farray6(&device->abs.usermatrix, calibration);
2561 if (!device->abs.apply_calibration) {
2562 matrix_init_identity(&device->abs.calibration);
2566 sx = absinfo_range(device->abs.absinfo_x);
2567 sy = absinfo_range(device->abs.absinfo_y);
2576 * normalized to multiples of the device width and height,
2577 * respectively. e.g. c == 1 shifts one device-width to the right.
2582 * Normalize: scales the device coordinates to [0,1]
2584 * Un-Normalize: scales back up to device coordinates
2591 device->abs.absinfo_x->minimum,
2592 device->abs.absinfo_y->minimum);
2601 -device->abs.absinfo_x->minimum/sx,
2602 -device->abs.absinfo_y->minimum/sy);
2606 /* store final matrix in device */
2607 matrix_mult(&device->abs.calibration, &transform, &scale);
2611 evdev_read_calibration_prop(struct evdev_device *device)
2616 prop = udev_device_get_property_value(device->udev_device,
2622 if (!device->abs.absinfo_x || !device->abs.absinfo_y)
2628 evdev_device_set_default_calibration(device, calibration);
2629 evdev_log_info(device,
2640 evdev_read_fuzz_prop(struct evdev_device *device, unsigned int code)
2652 prop = udev_device_get_property_value(device->udev_device, name);
2654 evdev_log_bug_libinput(device,
2663 * device. Otherwise, the kernel will use the nonzero fuzz, we then
2667 abs = libevdev_get_abs_info(device->evdev, code);
2672 evdev_log_bug_libinput(device,
2677 evdev_log_bug_libinput(device,
2687 evdev_device_has_capability(struct evdev_device *device,
2692 return !!(device->seat_caps & EVDEV_DEVICE_POINTER);
2694 return !!(device->seat_caps & EVDEV_DEVICE_KEYBOARD);
2696 return !!(device->seat_caps & EVDEV_DEVICE_TOUCH);
2698 return !!(device->seat_caps & EVDEV_DEVICE_GESTURE);
2700 return !!(device->seat_caps & EVDEV_DEVICE_TABLET);
2702 return !!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD);
2704 return !!(device->seat_caps & EVDEV_DEVICE_SWITCH);
2711 evdev_device_get_size(const struct evdev_device *device,
2717 x = libevdev_get_abs_info(device->evdev, ABS_X);
2718 y = libevdev_get_abs_info(device->evdev, ABS_Y);
2720 if (!x || !y || device->abs.is_fake_resolution ||
2731 evdev_device_has_button(struct evdev_device *device, uint32_t code)
2733 if (!(device->seat_caps & EVDEV_DEVICE_POINTER))
2736 return libevdev_has_event_code(device->evdev, EV_KEY, code);
2740 evdev_device_has_key(struct evdev_device *device, uint32_t code)
2742 if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD))
2745 return libevdev_has_event_code(device->evdev, EV_KEY, code);
2749 evdev_device_get_touch_count(struct evdev_device *device)
2753 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
2756 ntouches = libevdev_get_num_slots(device->evdev);
2759 * how many. Otherwise, any touch device with num_slots of
2760 * -1 is a single-touch device */
2761 if (device->mtdev)
2771 evdev_device_has_switch(struct evdev_device *device,
2776 if (!(device->seat_caps & EVDEV_DEVICE_SWITCH))
2790 return libevdev_has_event_code(device->evdev, EV_SW, code);
2794 evdev_is_scrolling(const struct evdev_device *device,
2800 return (device->scroll.direction & bit(axis)) != 0;
2804 evdev_start_scrolling(struct evdev_device *device,
2810 device->scroll.direction |= bit(axis);
2814 evdev_post_scroll(struct evdev_device *device,
2822 if (!evdev_is_scrolling(device,
2824 device->scroll.buildup.y += delta->y;
2825 if (!evdev_is_scrolling(device,
2827 device->scroll.buildup.x += delta->x;
2829 trigger = &device->scroll.buildup;
2833 if (!evdev_is_scrolling(device,
2835 !evdev_is_scrolling(device,
2837 if (fabs(trigger->y) >= device->scroll.threshold)
2838 evdev_start_scrolling(device,
2840 if (fabs(trigger->x) >= device->scroll.threshold)
2841 evdev_start_scrolling(device,
2845 } else if (!evdev_is_scrolling(device,
2847 if (fabs(delta->y) >= device->scroll.direction_lock_threshold)
2848 evdev_start_scrolling(device,
2850 } else if (!evdev_is_scrolling(device,
2852 if (fabs(delta->x) >= device->scroll.direction_lock_threshold)
2853 evdev_start_scrolling(device,
2862 if (!evdev_is_scrolling(device,
2866 if (!evdev_is_scrolling(device,
2871 uint32_t axes = device->scroll.direction;
2880 evdev_notify_axis_finger(device, time, axes, &event);
2883 evdev_notify_axis_continous(device, time, axes, &event);
2886 evdev_log_bug_libinput(device,
2895 evdev_stop_scroll(struct evdev_device *device,
2902 if (device->scroll.direction != 0) {
2905 pointer_notify_axis_finger(&device->base,
2907 device->scroll.direction,
2911 pointer_notify_axis_continuous(&device->base,
2913 device->scroll.direction,
2917 evdev_log_bug_libinput(device,
2924 device->scroll.buildup.x = 0;
2925 device->scroll.buildup.y = 0;
2926 device->scroll.direction = 0;
2930 evdev_notify_suspended_device(struct evdev_device *device)
2934 if (device->is_suspended)
2937 list_for_each(it, &device->base.seat->devices_list, link) {
2939 if (it == &device->base)
2943 d->dispatch->interface->device_suspended(d, device);
2946 device->is_suspended = true;
2950 evdev_notify_resumed_device(struct evdev_device *device)
2954 if (!device->is_suspended)
2957 list_for_each(it, &device->base.seat->devices_list, link) {
2959 if (it == &device->base)
2963 d->dispatch->interface->device_resumed(d, device);
2966 device->is_suspended = false;
2970 evdev_device_suspend(struct evdev_device *device)
2972 struct libinput *libinput = evdev_libinput_context(device);
2974 evdev_notify_suspended_device(device);
2976 if (device->dispatch->interface->suspend)
2977 device->dispatch->interface->suspend(device->dispatch,
2978 device);
2980 if (device->source) {
2981 libinput_remove_source(libinput, device->source);
2982 device->source = NULL;
2985 if (device->mtdev) {
2986 mtdev_close_delete(device->mtdev);
2987 device->mtdev = NULL;
2990 if (device->fd != -1) {
2991 close_restricted(libinput, device->fd);
2992 device->fd = -1;
2997 evdev_device_resume(struct evdev_device *device)
2999 struct libinput *libinput = evdev_libinput_context(device);
3005 if (device->fd != -1)
3008 if (device->was_removed)
3011 devnode = udev_device_get_devnode(device->udev_device);
3021 if (!evdev_device_have_same_syspath(device->udev_device, fd)) {
3028 device->fd = fd;
3030 if (evdev_need_mtdev(device)) {
3031 device->mtdev = mtdev_new_open(device->fd);
3032 if (!device->mtdev)
3036 libevdev_change_fd(device->evdev, fd);
3037 libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC);
3039 /* re-sync libevdev's view of the device, but discard the actual
3040 events. Our device is in a neutral state already */
3041 libevdev_next_event(device->evdev,
3045 status = libevdev_next_event(device->evdev,
3050 device->source =
3051 libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
3052 if (!device->source) {
3053 mtdev_close_delete(device->mtdev);
3057 evdev_notify_resumed_device(device);
3063 evdev_device_remove(struct evdev_device *device)
3067 evdev_log_info(device, "device removed\n");
3069 libinput_timer_cancel(&device->scroll.timer);
3070 libinput_timer_cancel(&device->middlebutton.timer);
3072 list_for_each(dev, &device->base.seat->devices_list, link) {
3074 if (dev == &device->base)
3078 d->dispatch->interface->device_removed(d, device);
3081 evdev_device_suspend(device);
3083 if (device->dispatch->interface->remove)
3084 device->dispatch->interface->remove(device->dispatch);
3086 /* A device may be removed while suspended, mark it to
3087 * skip re-opening a different device with the same node */
3088 device->was_removed = true;
3090 list_remove(&device->base.link);
3092 notify_removed_device(&device->base);
3093 libinput_device_unref(&device->base);
3097 evdev_device_destroy(struct evdev_device *device)
3101 dispatch = device->dispatch;
3105 if (device->base.group)
3106 libinput_device_group_unref(device->base.group);
3108 free(device->log_prefix_name);
3109 free(device->sysname);
3110 free(device->output_name);
3111 filter_destroy(device->pointer.filter);
3112 libinput_timer_destroy(&device->scroll.timer);
3113 libinput_timer_destroy(&device->middlebutton.timer);
3114 libinput_seat_unref(device->base.seat);
3115 libevdev_free(device->evdev);
3116 udev_device_unref(device->udev_device);
3117 free(device);
3121 evdev_tablet_has_left_handed(struct evdev_device *device)
3125 struct libinput *li = evdev_libinput_context(device);
3136 devnode = udev_device_get_devnode(device->udev_device);
3146 evdev_log_info(device,
3148 device->devname);
3150 evdev_log_error(device,