END_TEST START_TEST(device_sendevents_config_touchpad_superset) { struct litest_device *dev = litest_current_device(); struct libinput_device *device; enum libinput_config_status status; uint32_t modes; /* The wacom devices in the test suite are external */ if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM || libevdev_get_id_bustype(dev->evdev) == BUS_BLUETOOTH) return; device = dev->libinput_device; modes = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED | LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; status = libinput_device_config_send_events_set_mode(device, modes); ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); /* DISABLED supersedes the rest, expect the rest to be dropped */ modes = libinput_device_config_send_events_get_mode(device); ck_assert_int_eq(modes, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); }
int main (int argc, char **argv) { int rc; int fd; const char *path; struct libevdev *dev; struct measurements measurements = {0}; if (argc < 2) return usage(); path = argv[1]; if (path[0] == '-') return usage(); fd = open(path, O_RDONLY|O_NONBLOCK); if (fd < 0) { fprintf(stderr, "Error opening the device: %s\n", strerror(errno)); return 1; } rc = libevdev_new_from_fd(fd, &dev); if (rc != 0) { fprintf(stderr, "Error fetching the device info: %s\n", strerror(-rc)); return 1; } if (libevdev_grab(dev, LIBEVDEV_GRAB) != 0) { fprintf(stderr, "Error: cannot grab the device, something else is grabbing it.\n"); fprintf(stderr, "Use 'fuser -v %s' to find processes with an open fd\n", path); return 1; } libevdev_grab(dev, LIBEVDEV_UNGRAB); printf("Mouse %s on %s\n", libevdev_get_name(dev), path); printf("Move the device 250mm/10in or more along the x-axis.\n"); printf("Pause 3 seconds before movement to reset, Ctrl+C to exit.\n"); setbuf(stdout, NULL); rc = mainloop(dev, &measurements); printf("\n"); print_summary(&measurements); printf("\n"); printf("Entry for hwdb match (replace XXX with the resolution in DPI):\n" "mouse:%s:v%04xp%04x:name:%s:\n" " MOUSE_DPI=XXX@%d\n", bustype(libevdev_get_id_bustype(dev)), libevdev_get_id_vendor(dev), libevdev_get_id_product(dev), libevdev_get_name(dev), (int)measurements.max_frequency); libevdev_free(dev); close(fd); return rc; }
void joystick_linux::open_joystick(const char *p_path) { int joy_num = get_free_joy_slot(); int fd = open(p_path, O_RDONLY | O_NONBLOCK); if (fd != -1 && joy_num != -1) { int rc = libevdev_new_from_fd(fd, &joysticks[joy_num].dev); if (rc < 0) { fprintf(stderr, "Failed to init libevdev (%s)\n", strerror(-rc)); return; } libevdev *dev = joysticks[joy_num].dev; //check if the device supports basic gamepad events, prevents certain keyboards from //being detected as joysticks if (libevdev_has_event_type(dev, EV_ABS) && libevdev_has_event_type(dev, EV_KEY) && (libevdev_has_event_code(dev, EV_KEY, BTN_A) || libevdev_has_event_code(dev, EV_KEY, BTN_THUMBL) || libevdev_has_event_code(dev, EV_KEY, BTN_TOP))) { char uid[128]; String name = libevdev_get_name(dev); uint16_t bus = __bswap_16(libevdev_get_id_bustype(dev)); uint16_t vendor = __bswap_16(libevdev_get_id_vendor(dev)); uint16_t product = __bswap_16(libevdev_get_id_product(dev)); uint16_t version = __bswap_16(libevdev_get_id_version(dev)); joysticks[joy_num].reset(); Joystick &joy = joysticks[joy_num]; joy.fd = fd; joy.devpath = String(p_path); setup_joystick_properties(joy_num); sprintf(uid, "%04x%04x", bus, 0); if (vendor && product && version) { sprintf(uid + String(uid).length(), "%04x%04x%04x%04x%04x%04x", vendor,0,product,0,version,0); input->joy_connection_changed(joy_num, true, name, uid); } else { String uidname = uid; int uidlen = MIN(name.length(), 11); for (int i=0; i<uidlen; i++) { uidname = uidname + _hex_str(name[i]); } uidname += "00"; input->joy_connection_changed(joy_num, true, name, uidname); } } else { //device is not a gamepad, clean up libevdev_free(dev); close(fd); } } }
int tp_init_buttons(struct tp_dispatch *tp, struct evdev_device *device) { struct libinput *libinput = tp_libinput_context(tp); struct tp_touch *t; const struct input_absinfo *absinfo_x, *absinfo_y; tp->buttons.is_clickpad = libevdev_has_property(device->evdev, INPUT_PROP_BUTTONPAD); tp->buttons.has_topbuttons = libevdev_has_property(device->evdev, INPUT_PROP_TOPBUTTONPAD); if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE) || libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) { if (tp->buttons.is_clickpad) log_bug_kernel(libinput, "%s: clickpad advertising right button\n", device->devname); } else if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_LEFT) && !tp->buttons.is_clickpad && libevdev_get_id_vendor(device->evdev) != VENDOR_ID_APPLE) { log_bug_kernel(libinput, "%s: non clickpad without right button?\n", device->devname); } absinfo_x = device->abs.absinfo_x; absinfo_y = device->abs.absinfo_y; /* pinned-finger motion threshold, see tp_unpin_finger. */ tp->buttons.motion_dist.x_scale_coeff = 1.0/absinfo_x->resolution; tp->buttons.motion_dist.y_scale_coeff = 1.0/absinfo_y->resolution; tp->buttons.config_method.get_methods = tp_button_config_click_get_methods; tp->buttons.config_method.set_method = tp_button_config_click_set_method; tp->buttons.config_method.get_method = tp_button_config_click_get_method; tp->buttons.config_method.get_default_method = tp_button_config_click_get_default_method; tp->device->base.config.click_method = &tp->buttons.config_method; tp->buttons.click_method = tp_click_get_default_method(tp); tp_switch_click_method(tp); tp_init_top_softbuttons(tp, device, 1.0); tp_init_middlebutton_emulation(tp, device); tp_for_each_touch(tp, t) { t->button.state = BUTTON_STATE_NONE; libinput_timer_init(&t->button.timer, tp_libinput_context(tp), tp_button_handle_timeout, t); }
END_TEST START_TEST(device_ids) { struct litest_device *dev = litest_current_device(); const char *name; unsigned int pid, vid; name = libevdev_get_name(dev->evdev); pid = libevdev_get_id_product(dev->evdev); vid = libevdev_get_id_vendor(dev->evdev); ck_assert_str_eq(name, libinput_device_get_name(dev->libinput_device)); ck_assert_int_eq(pid, libinput_device_get_id_product(dev->libinput_device)); ck_assert_int_eq(vid, libinput_device_get_id_vendor(dev->libinput_device)); }
static enum libinput_config_click_method tp_click_get_default_method(struct tp_dispatch *tp) { struct evdev_device *device = tp->device; uint32_t clickfinger_models = EVDEV_MODEL_CHROMEBOOK | EVDEV_MODEL_SYSTEM76_BONOBO | EVDEV_MODEL_SYSTEM76_GALAGO | EVDEV_MODEL_SYSTEM76_KUDU | EVDEV_MODEL_CLEVO_W740SU; if (!tp->buttons.is_clickpad) return LIBINPUT_CONFIG_CLICK_METHOD_NONE; else if (libevdev_get_id_vendor(tp->device->evdev) == VENDOR_ID_APPLE) return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; if (device->model_flags & clickfinger_models) return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; return LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; }
END_TEST START_TEST(device_udev_tag_apple) { struct litest_device *dev = litest_current_device(); struct libinput_device *device = dev->libinput_device; struct udev_device *d; const char *prop; d = libinput_device_get_udev_device(device); prop = udev_device_get_property_value(d, "LIBINPUT_MODEL_WACOM_TOUCHPAD"); if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM) ck_assert_notnull(prop); else ck_assert(prop == NULL); udev_device_unref(d); }
END_TEST START_TEST(device_sendevents_config_touchpad) { struct litest_device *dev = litest_current_device(); struct libinput_device *device; uint32_t modes, expected; expected = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; /* The wacom devices in the test suite are external */ if (libevdev_get_id_vendor(dev->evdev) != VENDOR_ID_WACOM && libevdev_get_id_bustype(dev->evdev) != BUS_BLUETOOTH) expected |= LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; device = dev->libinput_device; modes = libinput_device_config_send_events_get_modes(device); ck_assert_int_eq(modes, expected); }
static enum libinput_config_click_method tp_click_get_default_method(struct tp_dispatch *tp) { struct evdev_device *device = tp->device; if (!tp->buttons.is_clickpad) return LIBINPUT_CONFIG_CLICK_METHOD_NONE; else if (libevdev_get_id_vendor(tp->device->evdev) == VENDOR_ID_APPLE) return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; switch (device->model) { case EVDEV_MODEL_CHROMEBOOK: case EVDEV_MODEL_SYSTEM76_BONOBO: case EVDEV_MODEL_SYSTEM76_GALAGO: case EVDEV_MODEL_SYSTEM76_KUDU: case EVDEV_MODEL_CLEVO_W740SU: return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; default: break; } return LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; }
int main(int argc, char const *argv[]) { if (argc < 5) { printf("Usage: evmpd HOSTNAME PORT DEVICE HALT_COMMAND\n"); return EXIT_FAILURE; } struct mpd_connection *client = connect(argv[1], strtol(argv[2], NULL, 10)); struct libevdev *dev = NULL; int fd; int rc = 1; fd = open(argv[3], O_RDONLY | O_NONBLOCK); rc = libevdev_new_from_fd(fd, &dev); if (rc < 0) { fprintf(stderr, "Failed to init libevdev (%d)\n", strerror(-rc)); return EXIT_FAILURE; } printf("Input device name: \"%s\"\n", libevdev_get_name(dev)); printf("Input device ID: bus %#x vendor %#x product %#x\n", libevdev_get_id_bustype(dev), libevdev_get_id_vendor(dev), libevdev_get_id_product(dev)); do { struct input_event ev; rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); if (rc == 0 && ev.value == 0) { if (libevdev_event_is_code(&ev, EV_KEY, KEY_F4)) { system(argv[4]); printf("shutdown\n"); } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_PLAYPAUSE)) { struct mpd_status *status = mpd_run_status(client); enum mpd_state state = mpd_status_get_state(status); if (state != MPD_STATE_PLAY && state != MPD_STATE_PAUSE) { mpd_run_play(client); printf("play\n"); } else { mpd_run_toggle_pause(client); printf("toggle-pause\n"); } } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_STOPCD)) { mpd_run_stop(client); printf("stop\n"); } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_PREVIOUSSONG)) { mpd_run_previous(client); printf("previous\n"); } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_NEXTSONG)) { mpd_run_next(client); printf("next\n"); } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_VOLUMEUP)) { struct mpd_status *status = mpd_run_status(client); int volume = mpd_status_get_volume(status); volume += 5; if (volume > 100) { volume = 100; } mpd_run_set_volume(client, volume); printf("set-volume %d\n", volume); } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_VOLUMEDOWN)) { struct mpd_status *status = mpd_run_status(client); int volume = mpd_status_get_volume(status); volume -= 5; if (volume < 0) { volume = 0; } mpd_run_set_volume(client, volume); printf("set-volume %d\n", volume); } else { printf("Event: %s %s %d\n", libevdev_event_type_get_name(ev.type), libevdev_event_code_get_name(ev.type, ev.code), ev.value); } } } while (rc == LIBEVDEV_READ_STATUS_SUCCESS || rc == LIBEVDEV_READ_STATUS_SYNC || rc == -EAGAIN); printf("rc: %d\n", rc); if (client != NULL) { mpd_connection_free(client); } return EXIT_SUCCESS; }