summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Benjamin Cheng <ben@bcheng.cf>2019-03-12 13:17:47 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-04-14 19:31:36 -0400
commit6737b90cb93d0231bbbc6045adf8a2443bc4e21c (patch)
tree1b9c4f75ec160e85a2ffe9018c3564f105bd6678 /sway
parentSpawn swaynag as a wayland client (diff)
downloadsway-6737b90cb93d0231bbbc6045adf8a2443bc4e21c.tar.gz
sway-6737b90cb93d0231bbbc6045adf8a2443bc4e21c.tar.zst
sway-6737b90cb93d0231bbbc6045adf8a2443bc4e21c.zip
Add heuristics to differentiate touchpads
Use libinput_device_config_tap_get_finger_count to determine whether a pointer is a touchpad. swaymsg is also updated to reflect the new touchpad type.
Diffstat (limited to 'sway')
-rw-r--r--sway/input/input-manager.c34
-rw-r--r--sway/ipc-json.c20
2 files changed, 35 insertions, 19 deletions
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index adb36af9..0c5254bd 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) {
71 return identifier; 71 return identifier;
72} 72}
73 73
74static bool device_is_touchpad(struct sway_input_device *device) {
75 if (device->wlr_device->type != WLR_INPUT_DEVICE_POINTER ||
76 !wlr_input_device_is_libinput(device->wlr_device)) {
77 return false;
78 }
79
80 struct libinput_device *libinput_device =
81 wlr_libinput_get_device_handle(device->wlr_device);
82
83 return libinput_device_config_tap_get_finger_count(libinput_device) > 0;
84}
85
86const char *input_device_get_type(struct sway_input_device *device) {
87 switch (device->wlr_device->type) {
88 case WLR_INPUT_DEVICE_POINTER:
89 if (device_is_touchpad(device)) {
90 return "touchpad";
91 } else {
92 return "pointer";
93 }
94 case WLR_INPUT_DEVICE_KEYBOARD:
95 return "keyboard";
96 case WLR_INPUT_DEVICE_TOUCH:
97 return "touch";
98 case WLR_INPUT_DEVICE_TABLET_TOOL:
99 return "tablet_tool";
100 case WLR_INPUT_DEVICE_TABLET_PAD:
101 return "tablet_pad";
102 case WLR_INPUT_DEVICE_SWITCH:
103 return "switch";
104 }
105 return "unknown";
106}
107
74static struct sway_input_device *input_sway_device_from_wlr( 108static struct sway_input_device *input_sway_device_from_wlr(
75 struct wlr_input_device *device) { 109 struct wlr_input_device *device) {
76 struct sway_input_device *input_device = NULL; 110 struct sway_input_device *input_device = NULL;
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index c320d958..4ccf6dfd 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
85 return NULL; 85 return NULL;
86} 86}
87 87
88static const char *ipc_json_device_type_description(struct sway_input_device *device) {
89 switch (device->wlr_device->type) {
90 case WLR_INPUT_DEVICE_POINTER:
91 return "pointer";
92 case WLR_INPUT_DEVICE_KEYBOARD:
93 return "keyboard";
94 case WLR_INPUT_DEVICE_SWITCH:
95 return "switch";
96 case WLR_INPUT_DEVICE_TOUCH:
97 return "touch";
98 case WLR_INPUT_DEVICE_TABLET_TOOL:
99 return "tablet_tool";
100 case WLR_INPUT_DEVICE_TABLET_PAD:
101 return "tablet_pad";
102 }
103 return "unknown";
104}
105
106json_object *ipc_json_get_version(void) { 88json_object *ipc_json_get_version(void) {
107 int major = 0, minor = 0, patch = 0; 89 int major = 0, minor = 0, patch = 0;
108 json_object *version = json_object_new_object(); 90 json_object *version = json_object_new_object();
@@ -819,7 +801,7 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
819 json_object_new_int(device->wlr_device->product)); 801 json_object_new_int(device->wlr_device->product));
820 json_object_object_add(object, "type", 802 json_object_object_add(object, "type",
821 json_object_new_string( 803 json_object_new_string(
822 ipc_json_device_type_description(device))); 804 input_device_get_type(device)));
823 805
824 if (device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) { 806 if (device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) {
825 struct wlr_keyboard *keyboard = device->wlr_device->keyboard; 807 struct wlr_keyboard *keyboard = device->wlr_device->keyboard;