diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index e166a2377..8d4a5b005 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -62,4 +62,6 @@ struct input_config *input_device_get_config(struct sway_input_device *device); char *input_device_get_identifier(struct wlr_input_device *device); +const char *input_device_get_type(struct sway_input_device *device); + #endif diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index adb36af93..0c5254bdf 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -71,6 +71,40 @@ char *input_device_get_identifier(struct wlr_input_device *device) { return identifier; } +static bool device_is_touchpad(struct sway_input_device *device) { + if (device->wlr_device->type != WLR_INPUT_DEVICE_POINTER || + !wlr_input_device_is_libinput(device->wlr_device)) { + return false; + } + + struct libinput_device *libinput_device = + wlr_libinput_get_device_handle(device->wlr_device); + + return libinput_device_config_tap_get_finger_count(libinput_device) > 0; +} + +const char *input_device_get_type(struct sway_input_device *device) { + switch (device->wlr_device->type) { + case WLR_INPUT_DEVICE_POINTER: + if (device_is_touchpad(device)) { + return "touchpad"; + } else { + return "pointer"; + } + case WLR_INPUT_DEVICE_KEYBOARD: + return "keyboard"; + case WLR_INPUT_DEVICE_TOUCH: + return "touch"; + case WLR_INPUT_DEVICE_TABLET_TOOL: + return "tablet_tool"; + case WLR_INPUT_DEVICE_TABLET_PAD: + return "tablet_pad"; + case WLR_INPUT_DEVICE_SWITCH: + return "switch"; + } + return "unknown"; +} + static struct sway_input_device *input_sway_device_from_wlr( struct wlr_input_device *device) { struct sway_input_device *input_device = NULL; diff --git a/sway/ipc-json.c b/sway/ipc-json.c index c320d9586..4ccf6dfd3 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -85,24 +85,6 @@ static const char *ipc_json_output_transform_description(enum wl_output_transfor return NULL; } -static const char *ipc_json_device_type_description(struct sway_input_device *device) { - switch (device->wlr_device->type) { - case WLR_INPUT_DEVICE_POINTER: - return "pointer"; - case WLR_INPUT_DEVICE_KEYBOARD: - return "keyboard"; - case WLR_INPUT_DEVICE_SWITCH: - return "switch"; - case WLR_INPUT_DEVICE_TOUCH: - return "touch"; - case WLR_INPUT_DEVICE_TABLET_TOOL: - return "tablet_tool"; - case WLR_INPUT_DEVICE_TABLET_PAD: - return "tablet_pad"; - } - return "unknown"; -} - json_object *ipc_json_get_version(void) { int major = 0, minor = 0, patch = 0; json_object *version = json_object_new_object(); @@ -819,7 +801,7 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) { json_object_new_int(device->wlr_device->product)); json_object_object_add(object, "type", json_object_new_string( - ipc_json_device_type_description(device))); + input_device_get_type(device))); if (device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) { struct wlr_keyboard *keyboard = device->wlr_device->keyboard; diff --git a/swaymsg/main.c b/swaymsg/main.c index f86000a42..e2c43445c 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -98,6 +98,7 @@ static const char *pretty_type_name(const char *name) { } type_names[] = { { "keyboard", "Keyboard" }, { "pointer", "Mouse" }, + { "touchpad", "Touchpad" }, { "tablet_pad", "Tablet pad" }, { "tablet_tool", "Tablet tool" }, { "touch", "Touch" },