aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/ipc-json.c61
-rw-r--r--sway/ipc-server.c12
2 files changed, 63 insertions, 10 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 6bd5204c..fba489d7 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -2,7 +2,9 @@
#include <ctype.h>
#include <string.h>
#include <stdint.h>
+#include <libinput.h>
#include "sway/container.h"
+#include "sway/input.h"
#include "sway/ipc-json.h"
#include "util.h"
@@ -242,6 +244,65 @@ json_object *ipc_json_describe_container(swayc_t *c) {
return object;
}
+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 },
+ { LIBINPUT_DEVICE_CAP_SWITCH, "switch", NULL }
+ };
+
+ 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;
+}
+
json_object *ipc_json_get_version() {
json_object *version = json_object_new_object();
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 0cacc515..b5f4bb16 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -420,17 +420,9 @@ void ipc_client_handle_command(struct ipc_client *client) {
}
json_object *inputs = json_object_new_array();
if (input_devices) {
- for(int i=0; i<input_devices->length; i++) {
+ for(int i = 0; i<input_devices->length; i++) {
struct libinput_device *device = input_devices->items[i];
- char* identifier = libinput_dev_unique_id(device);
- json_object *device_object = json_object_new_object();
- if (!identifier) {
- json_object_object_add(device_object, "identifier", NULL);
- } else {
- json_object_object_add(device_object, "identifier", json_object_new_string(identifier));
- }
- json_object_array_add(inputs, device_object);
- free(identifier);
+ json_object_array_add(inputs, ipc_json_describe_input(device));
}
}
const char *json_string = json_object_to_json_string(inputs);