diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-04-03 07:27:25 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-04-03 07:27:25 -0400 |
commit | 60ce81e06adc9ea133e8cfd030465e94295a95ff (patch) | |
tree | eb34022e36dd9277b40bed5bb4def27d5a1de5e0 /sway/ipc-json.c | |
parent | 8d9a9280588a0a2243c5aa87c769ae42e46f926d (diff) |
Add pretty printing to swaymsg
If stdout is a tty, it will pretty print unless -r (--raw) is given.
Sample outputs:
```
~/s/s/build > ./bin/swaymsg fullscreen toggle
Error: Permission denied for fullscreen toggle via IPC
~/s/s/build > ./bin/swaymsg -t get_workspaces
Workspace 3:三
Output: DVI-I-1
Layout: splith
Workspace 1:一 (off-screen)
Output: HDMI-A-1
Layout: splith
Workspace 5:五 (focused)
Output: HDMI-A-1
Layout: splith
~/s/s/build > ./bin/swaymsg -t get_inputs
Input device Metadot - Das Keyboard Das Keyboard
Type: Keyboard
Sway ID: 9456:320:Metadot_-_Das_Keyboard_Das_Keyb
Input device Wacom Intuos S 2 Pen
Type: Tablet tool
Sway ID: 1386:827:Wacom_Intuos_S_2
Input device Wacom Intuos S 2 Pad
Type: Tablet pad
Sway ID: 1386:827:Wacom_Intuos_S_2
Input device Logitech Gaming Mouse G502
Type: Keyboard, Mouse
Sway ID: 1133:49277:Logitech_Gaming_Mous
~/s/s/build > ./bin/swaymsg -t get_outputs
Output DVI-I-1
Geometry: 1920x1080 @ 3840,0
Scale factor: 1x
Workspace: 3:三
Output DVI-D-1
Geometry: 1920x1080 @ 0,0
Scale factor: 1x
Workspace: 4:四
Output HDMI-A-1
Geometry: 1920x1080 @ 1920,0
Scale factor: 1x
Workspace: 5:五
```
Diffstat (limited to 'sway/ipc-json.c')
-rw-r--r-- | sway/ipc-json.c | 61 |
1 files changed, 61 insertions, 0 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(); |