Esempio n. 1
0
END_TEST

START_TEST(udev_create_seat0)
{
	struct libinput *li;
	struct libinput_event *event;
	struct udev *udev;
	int fd;

	udev = udev_new();
	ck_assert(udev != NULL);

	li = libinput_udev_create_context(&simple_interface, NULL, udev);
	ck_assert(li != NULL);
	ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);

	fd = libinput_get_fd(li);
	ck_assert_int_ge(fd, 0);

	/* expect at least one event */
	libinput_dispatch(li);
	event = libinput_get_event(li);
	ck_assert(event != NULL);

	libinput_event_destroy(event);
	libinput_unref(li);
	udev_unref(udev);
}
Esempio n. 2
0
END_TEST

START_TEST(udev_device_sysname)
{
	struct libinput *li;
	struct libinput_event *ev;
	struct libinput_device *device;
	const char *sysname;
	struct udev *udev;

	udev = udev_new();
	ck_assert(udev != NULL);

	li = libinput_udev_create_context(&simple_interface, NULL, udev);
	ck_assert(li != NULL);
	ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);

	libinput_dispatch(li);

	while ((ev = libinput_get_event(li))) {
		if (libinput_event_get_type(ev) != LIBINPUT_EVENT_DEVICE_ADDED)
			continue;

		device = libinput_event_get_device(ev);
		sysname = libinput_device_get_sysname(device);
		ck_assert(sysname != NULL && strlen(sysname) > 1);
		ck_assert(strchr(sysname, '/') == NULL);
		ck_assert_int_eq(strncmp(sysname, "event", 5), 0);
		libinput_event_destroy(ev);
	}

	libinput_unref(li);
	udev_unref(udev);
}
Esempio n. 3
0
END_TEST

START_TEST(udev_create_empty_seat)
{
	struct libinput *li;
	struct libinput_event *event;
	struct udev *udev;
	int fd;

	udev = udev_new();
	ck_assert(udev != NULL);

	/* expect a libinput reference, but no events */
	li = libinput_udev_create_context(&simple_interface, NULL, udev);
	ck_assert(li != NULL);
	ck_assert_int_eq(libinput_udev_assign_seat(li, "seatdoesntexist"), 0);

	fd = libinput_get_fd(li);
	ck_assert_int_ge(fd, 0);

	libinput_dispatch(li);
	event = libinput_get_event(li);
	ck_assert(event == NULL);

	libinput_event_destroy(event);
	libinput_unref(li);
	udev_unref(udev);
}
Esempio n. 4
0
END_TEST

START_TEST(path_udev_assign_seat)
{
	struct litest_device *dev = litest_current_device();
	struct libinput *li = dev->libinput;
	int rc;

	litest_set_log_handler_bug(li);
	rc = libinput_udev_assign_seat(li, "foo");
	ck_assert_int_eq(rc, -1);
	litest_restore_log_handler(li);
}
LibinputServer::LibinputServer()
    : m_keyboardEventHandler(Input::KeyboardEventHandler::create())
    , m_keyboardEventRepeating(new Input::KeyboardEventRepeating(*this))
    , m_pointerCoords(0, 0)
    , m_pointerBounds(1, 1)
#ifdef KEY_INPUT_HANDLING_VIRTUAL
    , m_virtualkeyboard(nullptr)
#endif
{
    m_udev = udev_new();
    if (!m_udev)
        return;

    m_libinput = libinput_udev_create_context(&g_interface, nullptr, m_udev);
    if (!m_libinput)
        return;

    int ret = libinput_udev_assign_seat(m_libinput, "seat0");
    if (ret)
        return;

    GSource* baseSource = g_source_new(&EventSource::s_sourceFuncs, sizeof(EventSource));
    auto* source = reinterpret_cast<EventSource*>(baseSource);
    source->pfd.fd = libinput_get_fd(m_libinput);
    source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
    source->pfd.revents = 0;
    g_source_add_poll(baseSource, &source->pfd);
    source->server = this;

    g_source_set_name(baseSource, "[WPE] libinput");
    g_source_set_priority(baseSource, G_PRIORITY_DEFAULT);
    g_source_attach(baseSource, g_main_context_get_thread_default());

#ifdef KEY_INPUT_HANDLING_VIRTUAL
    const char listenerName[] = "WebKitBrowser";
    m_virtualkeyboard = Construct(listenerName, connectorName, VirtualKeyboardCallback);
    if (m_virtualkeyboard == nullptr) {
      fprintf(stderr, "[LibinputServer] Initialization of virtual keyboard failed!!!\n");
    }
    else {
       fprintf(stderr, "[LibinputServer] Initialization of virtual keyboard and linux input system succeeded.\n");
    }
#else
    fprintf(stderr, "[LibinputServer] Initialization of linux input system succeeded.\n");
#endif

}
Esempio n. 6
0
END_TEST

/**
 * This test only works if there's at least one device in the system that is
 * assigned the default seat. Should cover the 99% case.
 */
START_TEST(udev_added_seat_default)
{
	struct libinput *li;
	struct libinput_event *event;
	struct udev *udev;
	struct libinput_device *device;
	struct libinput_seat *seat;
	const char *seat_name;
	enum libinput_event_type type;
	int default_seat_found = 0;

	udev = udev_new();
	ck_assert(udev != NULL);

	li = libinput_udev_create_context(&simple_interface, NULL, udev);
	ck_assert(li != NULL);
	ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
	libinput_dispatch(li);

	while (!default_seat_found && (event = libinput_get_event(li))) {
		type = libinput_event_get_type(event);
		if (type != LIBINPUT_EVENT_DEVICE_ADDED) {
			libinput_event_destroy(event);
			continue;
		}

		device = libinput_event_get_device(event);
		seat = libinput_device_get_seat(device);
		ck_assert(seat != NULL);

		seat_name = libinput_seat_get_logical_name(seat);
		default_seat_found = !strcmp(seat_name, "default");
		libinput_event_destroy(event);
	}

	ck_assert(default_seat_found);

	libinput_unref(li);
	udev_unref(udev);
}
Esempio n. 7
0
bool
LibInputHandler::Open()
{
  if ((nullptr != udev_context)
      || (nullptr != li_if)
      || (nullptr != li)
      || fd.IsDefined())
    return false;

  if (nullptr == udev_context) {
    udev_context = new UdevContext(UdevContext::NewRef());
    if ((nullptr == udev_context) || (nullptr == udev_context->Get())) {
      return false;
    }
  }

  li_if = new libinput_interface;
  assert(li_if);
  li_if->open_restricted = [](const char *path, int flags, void* user_data)
      -> int {
    return reinterpret_cast<LibInputHandler*>(user_data)->OpenDevice(path,
                                                                     flags);
  };
  li_if->close_restricted = [](int fd, void* user_data) {
    reinterpret_cast<LibInputHandler*>(user_data)->CloseDevice(fd);
  };

  li = libinput_udev_create_context(li_if, this, udev_context->Get());
  if (nullptr == li)
    return false;

  int assign_seat_ret = libinput_udev_assign_seat(li, UDEV_DEFAULT_SEAT);
  if (0 != assign_seat_ret)
    return false;

  fd.Set(libinput_get_fd(li));
  if (!fd.IsDefined())
    return false;
  io_loop.Add(fd, io_loop.READ, *this);

  return true;
}
Esempio n. 8
0
static struct libinput *
open_udev(const struct libinput_interface *interface,
	  void *userdata,
	  const char *seat,
	  int verbose)
{
	struct libinput *li;
	struct udev *udev = udev_new();

	if (!udev) {
		fprintf(stderr, "Failed to initialize udev\n");
		return NULL;
	}

	li = libinput_udev_create_context(interface, userdata, udev);
	if (!li) {
		fprintf(stderr, "Failed to initialize context from udev\n");
		goto out;
	}

	if (verbose) {
		libinput_log_set_handler(li, log_handler);
		libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
	}

	if (libinput_udev_assign_seat(li, seat)) {
		fprintf(stderr, "Failed to set seat\n");
		libinput_unref(li);
		li = NULL;
		goto out;
	}

out:
	udev_unref(udev);
	return li;
}
Esempio n. 9
0
END_TEST

START_TEST(udev_seat_recycle)
{
	struct udev *udev;
	struct libinput *li;
	struct libinput_event *ev;
	struct libinput_device *device;
	struct libinput_seat *saved_seat = NULL;
	struct libinput_seat *seat;
	int data = 0;
	int found = 0;
	void *user_data;

	udev = udev_new();
	ck_assert(udev != NULL);

	li = libinput_udev_create_context(&simple_interface, NULL, udev);
	ck_assert(li != NULL);
	ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);

	libinput_dispatch(li);
	while ((ev = libinput_get_event(li))) {
		switch (libinput_event_get_type(ev)) {
		case LIBINPUT_EVENT_DEVICE_ADDED:
			if (saved_seat)
				break;

			device = libinput_event_get_device(ev);
			ck_assert(device != NULL);
			saved_seat = libinput_device_get_seat(device);
			libinput_seat_set_user_data(saved_seat, &data);
			libinput_seat_ref(saved_seat);
			break;
		default:
			break;
		}

		libinput_event_destroy(ev);
	}

	ck_assert(saved_seat != NULL);

	libinput_suspend(li);

	litest_drain_events(li);

	libinput_resume(li);

	libinput_dispatch(li);
	while ((ev = libinput_get_event(li))) {
		switch (libinput_event_get_type(ev)) {
		case LIBINPUT_EVENT_DEVICE_ADDED:
			device = libinput_event_get_device(ev);
			ck_assert(device != NULL);

			seat = libinput_device_get_seat(device);
			user_data = libinput_seat_get_user_data(seat);
			if (user_data == &data) {
				found = 1;
				ck_assert(seat == saved_seat);
			}
			break;
		default:
			break;
		}

		libinput_event_destroy(ev);
	}

	ck_assert(found == 1);

	libinput_unref(li);
	udev_unref(udev);
}