diff options
author | 2017-04-10 08:19:02 -0400 | |
---|---|---|
committer | 2017-04-10 08:19:02 -0400 | |
commit | cd3c48fb9d70fd49c53922b0b294828130fcaaa5 (patch) | |
tree | 35860f43beb1ce46de5a3d780ca33830d4bc9ba4 /sway | |
parent | Merge pull request #1150 from JerziKaminsky/cmake_find_libcap (diff) | |
parent | Merge branch 'master' into pretty-print-swaymsg (diff) | |
download | sway-cd3c48fb9d70fd49c53922b0b294828130fcaaa5.tar.gz sway-cd3c48fb9d70fd49c53922b0b294828130fcaaa5.tar.zst sway-cd3c48fb9d70fd49c53922b0b294828130fcaaa5.zip |
Merge pull request #1146 from SirCmpwn/pretty-print-swaymsg
Add pretty printing to swaymsg
Diffstat (limited to 'sway')
-rw-r--r-- | sway/ipc-json.c | 61 | ||||
-rw-r--r-- | sway/ipc-server.c | 12 |
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 @@ | |||
2 | #include <ctype.h> | 2 | #include <ctype.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include <stdint.h> | 4 | #include <stdint.h> |
5 | #include <libinput.h> | ||
5 | #include "sway/container.h" | 6 | #include "sway/container.h" |
7 | #include "sway/input.h" | ||
6 | #include "sway/ipc-json.h" | 8 | #include "sway/ipc-json.h" |
7 | #include "util.h" | 9 | #include "util.h" |
8 | 10 | ||
@@ -242,6 +244,65 @@ json_object *ipc_json_describe_container(swayc_t *c) { | |||
242 | return object; | 244 | return object; |
243 | } | 245 | } |
244 | 246 | ||
247 | json_object *ipc_json_describe_input(struct libinput_device *device) { | ||
248 | char* identifier = libinput_dev_unique_id(device); | ||
249 | int vendor = libinput_device_get_id_vendor(device); | ||
250 | int product = libinput_device_get_id_product(device); | ||
251 | const char *name = libinput_device_get_name(device); | ||
252 | double width = -1, height = -1; | ||
253 | int has_size = libinput_device_get_size(device, &width, &height); | ||
254 | |||
255 | json_object *device_object = json_object_new_object(); | ||
256 | json_object_object_add(device_object,"identifier", | ||
257 | identifier ? json_object_new_string(identifier) : NULL); | ||
258 | json_object_object_add(device_object, | ||
259 | "vendor", json_object_new_int(vendor)); | ||
260 | json_object_object_add(device_object, | ||
261 | "product", json_object_new_int(product)); | ||
262 | json_object_object_add(device_object, | ||
263 | "name", json_object_new_string(name)); | ||
264 | if (has_size == 0) { | ||
265 | json_object *size_object = json_object_new_object(); | ||
266 | json_object_object_add(size_object, | ||
267 | "width", json_object_new_double(width)); | ||
268 | json_object_object_add(size_object, | ||
269 | "height", json_object_new_double(height)); | ||
270 | } else { | ||
271 | json_object_object_add(device_object, "size", NULL); | ||
272 | } | ||
273 | |||
274 | struct { | ||
275 | enum libinput_device_capability cap; | ||
276 | const char *name; | ||
277 | // If anyone feels like implementing device-specific IPC output, | ||
278 | // be my guest | ||
279 | json_object *(*describe)(struct libinput_device *); | ||
280 | } caps[] = { | ||
281 | { LIBINPUT_DEVICE_CAP_KEYBOARD, "keyboard", NULL }, | ||
282 | { LIBINPUT_DEVICE_CAP_POINTER, "pointer", NULL }, | ||
283 | { LIBINPUT_DEVICE_CAP_TOUCH, "touch", NULL }, | ||
284 | { LIBINPUT_DEVICE_CAP_TABLET_TOOL, "tablet_tool", NULL }, | ||
285 | { LIBINPUT_DEVICE_CAP_TABLET_PAD, "tablet_pad", NULL }, | ||
286 | { LIBINPUT_DEVICE_CAP_GESTURE, "gesture", NULL }, | ||
287 | { LIBINPUT_DEVICE_CAP_SWITCH, "switch", NULL } | ||
288 | }; | ||
289 | |||
290 | json_object *_caps = json_object_new_array(); | ||
291 | for (size_t i = 0; i < sizeof(caps) / sizeof(caps[0]); ++i) { | ||
292 | if (libinput_device_has_capability(device, caps[i].cap)) { | ||
293 | json_object_array_add(_caps, json_object_new_string(caps[i].name)); | ||
294 | if (caps[i].describe) { | ||
295 | json_object *desc = caps[i].describe(device); | ||
296 | json_object_object_add(device_object, caps[i].name, desc); | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | json_object_object_add(device_object, "capabilities", _caps); | ||
301 | |||
302 | free(identifier); | ||
303 | return device_object; | ||
304 | } | ||
305 | |||
245 | json_object *ipc_json_get_version() { | 306 | json_object *ipc_json_get_version() { |
246 | json_object *version = json_object_new_object(); | 307 | json_object *version = json_object_new_object(); |
247 | 308 | ||
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 6554098b..67a3cdc8 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -421,17 +421,9 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
421 | } | 421 | } |
422 | json_object *inputs = json_object_new_array(); | 422 | json_object *inputs = json_object_new_array(); |
423 | if (input_devices) { | 423 | if (input_devices) { |
424 | for(int i=0; i<input_devices->length; i++) { | 424 | for(int i = 0; i<input_devices->length; i++) { |
425 | struct libinput_device *device = input_devices->items[i]; | 425 | struct libinput_device *device = input_devices->items[i]; |
426 | char* identifier = libinput_dev_unique_id(device); | 426 | json_object_array_add(inputs, ipc_json_describe_input(device)); |
427 | json_object *device_object = json_object_new_object(); | ||
428 | if (!identifier) { | ||
429 | json_object_object_add(device_object, "identifier", NULL); | ||
430 | } else { | ||
431 | json_object_object_add(device_object, "identifier", json_object_new_string(identifier)); | ||
432 | } | ||
433 | json_object_array_add(inputs, device_object); | ||
434 | free(identifier); | ||
435 | } | 427 | } |
436 | } | 428 | } |
437 | const char *json_string = json_object_to_json_string(inputs); | 429 | const char *json_string = json_object_to_json_string(inputs); |