Exemplo n.º 1
0
json_object *ipc_json_describe_input(struct libinput_device *device) {
	char* identifier = libinput_dev_unique_id(device);
	int vendor = libinput_device_get_id_vendor(device);
	int product = libinput_device_get_id_product(device);
	const char *name = libinput_device_get_name(device);
	double width = -1, height = -1;
	int has_size = libinput_device_get_size(device, &width, &height);

	json_object *device_object = json_object_new_object();
	json_object_object_add(device_object,"identifier",
			identifier ? json_object_new_string(identifier) : NULL);
	json_object_object_add(device_object,
			"vendor", json_object_new_int(vendor));
	json_object_object_add(device_object,
			"product", json_object_new_int(product));
	json_object_object_add(device_object,
			"name", json_object_new_string(name));
	if (has_size == 0) {
		json_object *size_object = json_object_new_object();
		json_object_object_add(size_object,
				"width", json_object_new_double(width));
		json_object_object_add(size_object,
				"height", json_object_new_double(height));
	} else {
		json_object_object_add(device_object, "size", NULL);
	}

	struct {
		enum libinput_device_capability cap;
		const char *name;
		// If anyone feels like implementing device-specific IPC output,
		// be my guest
		json_object *(*describe)(struct libinput_device *);
	} caps[] = {
		{ LIBINPUT_DEVICE_CAP_KEYBOARD, "keyboard", NULL },
		{ LIBINPUT_DEVICE_CAP_POINTER, "pointer", NULL },
		{ LIBINPUT_DEVICE_CAP_TOUCH, "touch", NULL },
		{ LIBINPUT_DEVICE_CAP_TABLET_TOOL, "tablet_tool", NULL },
		{ LIBINPUT_DEVICE_CAP_TABLET_PAD, "tablet_pad", NULL },
		{ LIBINPUT_DEVICE_CAP_GESTURE, "gesture", NULL },
#ifdef LIBINPUT_DEVICE_CAP_SWITCH // libinput 1.7.0+
		{ LIBINPUT_DEVICE_CAP_SWITCH, "switch", NULL },
#endif		
	};

	json_object *_caps = json_object_new_array();
	for (size_t i = 0; i < sizeof(caps) / sizeof(caps[0]); ++i) {
		if (libinput_device_has_capability(device, caps[i].cap)) {
			json_object_array_add(_caps, json_object_new_string(caps[i].name));
			if (caps[i].describe) {
				json_object *desc = caps[i].describe(device);
				json_object_object_add(device_object, caps[i].name, desc);
			}
		}
	}
	json_object_object_add(device_object, "capabilities", _caps);

	free(identifier);
	return device_object;
}
Exemplo n.º 2
0
ClutterInputDeviceType
_clutter_input_device_evdev_determine_type (struct libinput_device *ldev)
{
  /* This setting is specific to touchpads and alike, only in these
   * devices there is this additional layer of touch event interpretation.
   */
  if (libinput_device_config_tap_get_finger_count (ldev) > 0)
    return CLUTTER_TOUCHPAD_DEVICE;
  else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_POINTER))
    return CLUTTER_POINTER_DEVICE;
  else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_TOUCH))
    return CLUTTER_TOUCHSCREEN_DEVICE;
  else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_KEYBOARD))
    return CLUTTER_KEYBOARD_DEVICE;
  else
    return CLUTTER_EXTENSION_DEVICE;
}
Exemplo n.º 3
0
/*
 * _clutter_input_device_evdev_new:
 * @manager: the device manager
 * @seat: the seat the device will belong to
 * @libinput_device: the libinput device
 *
 * Create a new ClutterInputDevice given a libinput device and associate
 * it with the provided seat.
 */
ClutterInputDevice *
_clutter_input_device_evdev_new (ClutterDeviceManager *manager,
                                 ClutterSeatEvdev *seat,
                                 struct libinput_device *libinput_device)
{
  ClutterInputDeviceEvdev *device;
  ClutterInputDeviceType type;
  ClutterDeviceManagerEvdev *manager_evdev;
  gchar *vendor, *product;
  gint device_id, n_rings = 0, n_strips = 0, n_groups = 1;
  gchar *node_path;
  gdouble width, height;

  type = _clutter_input_device_evdev_determine_type (libinput_device);
  vendor = g_strdup_printf ("%.4x", libinput_device_get_id_vendor (libinput_device));
  product = g_strdup_printf ("%.4x", libinput_device_get_id_product (libinput_device));
  manager_evdev = CLUTTER_DEVICE_MANAGER_EVDEV (manager);
  device_id = _clutter_device_manager_evdev_acquire_device_id (manager_evdev);
  node_path = g_strdup_printf ("/dev/input/%s", libinput_device_get_sysname (libinput_device));

  if (libinput_device_has_capability (libinput_device,
                                      LIBINPUT_DEVICE_CAP_TABLET_PAD))
    {
      n_rings = libinput_device_tablet_pad_get_num_rings (libinput_device);
      n_strips = libinput_device_tablet_pad_get_num_strips (libinput_device);
      n_groups = libinput_device_tablet_pad_get_num_mode_groups (libinput_device);
    }

  device = g_object_new (CLUTTER_TYPE_INPUT_DEVICE_EVDEV,
                         "id", device_id,
                         "name", libinput_device_get_name (libinput_device),
                         "device-manager", manager,
                         "device-type", type,
                         "device-mode", CLUTTER_INPUT_MODE_SLAVE,
                         "enabled", TRUE,
                         "vendor-id", vendor,
                         "product-id", product,
                         "n-rings", n_rings,
                         "n-strips", n_strips,
                         "n-mode-groups", n_groups,
                         "device-node", node_path,
                         NULL);

  device->seat = seat;
  device->libinput_device = libinput_device;

  libinput_device_set_user_data (libinput_device, device);
  libinput_device_ref (libinput_device);
  g_free (vendor);
  g_free (product);
  g_free (node_path);

  if (libinput_device_get_size (libinput_device, &width, &height) == 0)
    device->device_aspect_ratio = width / height;

  return CLUTTER_INPUT_DEVICE (device);
}
Exemplo n.º 4
0
END_TEST

START_TEST(device_wheel_only)
{
	struct litest_device *dev = litest_current_device();
	struct libinput_device *device = dev->libinput_device;

	ck_assert(libinput_device_has_capability(device,
						 LIBINPUT_DEVICE_CAP_POINTER));
}
Exemplo n.º 5
0
void LibInputHandlerPrivate::_q_liEventHandler()
{
    Q_Q(LibInputHandler);

    if (libinput_dispatch(li) != 0) {
        qCWarning(lcInput) << "Failed to dispatch libinput events";
        return;
    }

    libinput_event *event;
    while ((event = libinput_get_event(li)) != Q_NULLPTR) {
        libinput_event_type type = libinput_event_get_type(event);
        libinput_device *device = libinput_event_get_device(event);

        switch (type) {
        // Devices
        case LIBINPUT_EVENT_DEVICE_ADDED:
            if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
                ++keyboardCount;
                Q_EMIT q->capabilitiesChanged();
                Q_EMIT q->keyboardCountChanged(keyboardCount);
            }

            if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) {
                ++pointerCount;
                Q_EMIT q->capabilitiesChanged();
                Q_EMIT q->pointerCountChanged(pointerCount);
            }

            if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH)) {
                QTouchDevice *td = touch->registerDevice(device);
                Q_EMIT q->touchDeviceRegistered(td);

                ++touchCount;
                Q_EMIT q->capabilitiesChanged();
                Q_EMIT q->touchCountChanged(touchCount);
            }

            if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)) {
                ++gestureCount;
                Q_EMIT q->capabilitiesChanged();
                Q_EMIT q->gestureCountChanged(gestureCount);
            }
            break;
        case LIBINPUT_EVENT_DEVICE_REMOVED:
            if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
                --keyboardCount;
                Q_EMIT q->capabilitiesChanged();
                Q_EMIT q->keyboardCountChanged(keyboardCount);
            }

            if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) {
                --pointerCount;
                Q_EMIT q->capabilitiesChanged();
                Q_EMIT q->pointerCountChanged(pointerCount);
            }

            if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH)) {
                QTouchDevice *td = Q_NULLPTR;
                touch->unregisterDevice(device, &td);
                Q_EMIT q->touchDeviceUnregistered(td);

                --touchCount;
                Q_EMIT q->capabilitiesChanged();
                Q_EMIT q->touchCountChanged(touchCount);
            }

            if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)) {
                --gestureCount;
                Q_EMIT q->capabilitiesChanged();
                Q_EMIT q->gestureCountChanged(gestureCount);
            }
            break;
            // Keyboard
        case LIBINPUT_EVENT_KEYBOARD_KEY:
            keyboard->handleKey(libinput_event_get_keyboard_event(event));
            break;
            // Pointer
        case LIBINPUT_EVENT_POINTER_BUTTON:
            pointer->handleButton(libinput_event_get_pointer_event(event));
            break;
        case LIBINPUT_EVENT_POINTER_AXIS:
            pointer->handleAxis(libinput_event_get_pointer_event(event));
            break;
        case LIBINPUT_EVENT_POINTER_MOTION:
            pointer->handleMotion(libinput_event_get_pointer_event(event));
            break;
        case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
            pointer->handleAbsoluteMotion(libinput_event_get_pointer_event(event));
            break;
            // Touch
        case LIBINPUT_EVENT_TOUCH_UP:
            touch->handleTouchUp(libinput_event_get_touch_event(event));
            break;
        case LIBINPUT_EVENT_TOUCH_DOWN:
            touch->handleTouchDown(libinput_event_get_touch_event(event));
            break;
        case LIBINPUT_EVENT_TOUCH_FRAME:
            touch->handleTouchFrame(libinput_event_get_touch_event(event));
            break;
        case LIBINPUT_EVENT_TOUCH_MOTION:
            touch->handleTouchMotion(libinput_event_get_touch_event(event));
            break;
        case LIBINPUT_EVENT_TOUCH_CANCEL:
            touch->handleTouchCancel(libinput_event_get_touch_event(event));
            break;
            // Gesture
        case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
            gesture->handlePinchBegin(libinput_event_get_gesture_event(event));
            break;
        case LIBINPUT_EVENT_GESTURE_PINCH_END:
            gesture->handlePinchEnd(libinput_event_get_gesture_event(event));
            break;
        case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
            gesture->handlePinchUpdate(libinput_event_get_gesture_event(event));
            break;
        case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
            gesture->handleSwipeBegin(libinput_event_get_gesture_event(event));
            break;
        case LIBINPUT_EVENT_GESTURE_SWIPE_END:
            gesture->handleSwipeEnd(libinput_event_get_gesture_event(event));
            break;
        case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
            gesture->handleSwipeUpdate(libinput_event_get_gesture_event(event));
            break;
        default:
            break;
        }

        libinput_event_destroy(event);
    }
}
static void
print_device_notify(struct libinput_event *ev)
{
	struct libinput_device *dev = libinput_event_get_device(ev);
	struct libinput_seat *seat = libinput_device_get_seat(dev);
	struct libinput_device_group *group;
	double w, h;
	static int next_group_id = 0;
	intptr_t group_id;
	const char *devnode;
	char *str;

	group = libinput_device_get_device_group(dev);
	group_id = (intptr_t)libinput_device_group_get_user_data(group);
	if (!group_id) {
		group_id = ++next_group_id;
		libinput_device_group_set_user_data(group, (void*)group_id);
	}

	devnode = udev_device_get_devnode(
				  libinput_device_get_udev_device(dev));

	printf("Device:         %s\n"
	       "Kernel:         %s\n"
	       "Group:          %d\n"
	       "Seat:           %s, %s\n",
	       libinput_device_get_name(dev),
	       devnode,
	       (int)group_id,
	       libinput_seat_get_physical_name(seat),
	       libinput_seat_get_logical_name(seat));

	if (libinput_device_get_size(dev, &w, &h) == 0)
		printf("Size:           %.2fx%.2fmm\n", w, h);
	printf("Capabilities:   ");
	if (libinput_device_has_capability(dev,
					   LIBINPUT_DEVICE_CAP_KEYBOARD))
		printf("keyboard ");
	if (libinput_device_has_capability(dev,
					   LIBINPUT_DEVICE_CAP_POINTER))
		printf("pointer ");
	if (libinput_device_has_capability(dev,
					   LIBINPUT_DEVICE_CAP_TOUCH))
		printf("touch");
	printf("\n");

	printf("Tap-to-click:   %s\n", tap_default(dev));
	printf("Left-handed:    %s\n", left_handed_default(dev));
	printf("Nat.scrolling:  %s\n", nat_scroll_default(dev));
	str = calibration_default(dev);
	printf("Calibration:    %s\n", str);
	free(str);

	str = scroll_defaults(dev);
	printf("Scroll methods: %s\n", str);
	free(str);

	str = click_defaults(dev);
	printf("Click methods:  %s\n", str);
	free(str);

	printf("\n");
}