aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--include/sway/input/input-manager.h2
-rw-r--r--sway/input/input-manager.c34
-rw-r--r--sway/ipc-json.c20
-rw-r--r--swaymsg/main.c1
4 files changed, 38 insertions, 19 deletions
diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h
index e166a237..8d4a5b00 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);
62 62
63char *input_device_get_identifier(struct wlr_input_device *device); 63char *input_device_get_identifier(struct wlr_input_device *device);
64 64
65const char *input_device_get_type(struct sway_input_device *device);
66
65#endif 67#endif
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;
diff --git a/swaymsg/main.c b/swaymsg/main.c
index f86000a4..e2c43445 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -98,6 +98,7 @@ static const char *pretty_type_name(const char *name) {
98 } type_names[] = { 98 } type_names[] = {
99 { "keyboard", "Keyboard" }, 99 { "keyboard", "Keyboard" },
100 { "pointer", "Mouse" }, 100 { "pointer", "Mouse" },
101 { "touchpad", "Touchpad" },
101 { "tablet_pad", "Tablet pad" }, 102 { "tablet_pad", "Tablet pad" },
102 { "tablet_tool", "Tablet tool" }, 103 { "tablet_tool", "Tablet tool" },
103 { "touch", "Touch" }, 104 { "touch", "Touch" },