diff options
Diffstat (limited to 'swaymsg/main.c')
-rw-r--r-- | swaymsg/main.c | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c index 2f9cfb14..b431872a 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c | |||
@@ -61,55 +61,49 @@ static void pretty_print_workspace(json_object *w) { | |||
61 | ); | 61 | ); |
62 | } | 62 | } |
63 | 63 | ||
64 | static void pretty_print_input(json_object *i) { | 64 | static const char *pretty_type_name(const char *name) { |
65 | json_object *id, *name, *size, *caps; | 65 | // TODO these constants probably belong in the common lib |
66 | json_object_object_get_ex(i, "identifier", &id); | ||
67 | json_object_object_get_ex(i, "name", &name); | ||
68 | json_object_object_get_ex(i, "size", &size); | ||
69 | json_object_object_get_ex(i, "capabilities", &caps); | ||
70 | |||
71 | printf( "Input device %s\n Type: ", json_object_get_string(name)); | ||
72 | |||
73 | struct { | 66 | struct { |
74 | const char *a; | 67 | const char *a; |
75 | const char *b; | 68 | const char *b; |
76 | } cap_names[] = { | 69 | } type_names[] = { |
77 | { "keyboard", "Keyboard" }, | 70 | { "keyboard", "Keyboard" }, |
78 | { "pointer", "Mouse" }, | 71 | { "pointer", "Mouse" }, |
79 | { "touch", "Touch" }, | ||
80 | { "tablet_tool", "Tablet tool" }, | ||
81 | { "tablet_pad", "Tablet pad" }, | 72 | { "tablet_pad", "Tablet pad" }, |
82 | { "gesture", "Gesture" }, | 73 | { "tablet_tool", "Tablet tool" }, |
83 | { "switch", "Switch" }, | 74 | { "touch", "Touch" }, |
84 | }; | 75 | }; |
85 | 76 | ||
86 | size_t len = json_object_array_length(caps); | 77 | for (size_t i = 0; i < sizeof(type_names) / sizeof(type_names[0]); ++i) { |
87 | if (len == 0) { | 78 | if (strcmp(type_names[i].a, name) == 0) { |
88 | printf("Unknown"); | 79 | return type_names[i].b; |
89 | } | ||
90 | |||
91 | json_object *cap; | ||
92 | for (size_t i = 0; i < len; ++i) { | ||
93 | cap = json_object_array_get_idx(caps, i); | ||
94 | const char *cap_s = json_object_get_string(cap); | ||
95 | const char *_name = NULL; | ||
96 | for (size_t j = 0; j < sizeof(cap_names) / sizeof(cap_names[0]); ++i) { | ||
97 | if (strcmp(cap_names[i].a, cap_s) == 0) { | ||
98 | _name = cap_names[i].b; | ||
99 | break; | ||
100 | } | ||
101 | } | 80 | } |
102 | printf("%s%s", _name ? _name : cap_s, len > 1 && i != len - 1 ? ", " : ""); | ||
103 | } | ||
104 | printf("\n Sway ID: %s\n", json_object_get_string(id)); | ||
105 | if (size) { | ||
106 | json_object *width, *height; | ||
107 | json_object_object_get_ex(size, "width", &width); | ||
108 | json_object_object_get_ex(size, "height", &height); | ||
109 | printf(" Size: %lfmm x %lfmm\n", | ||
110 | json_object_get_double(width), json_object_get_double(height)); | ||
111 | } | 81 | } |
112 | printf("\n"); | 82 | |
83 | return name; | ||
84 | } | ||
85 | |||
86 | static void pretty_print_input(json_object *i) { | ||
87 | json_object *id, *name, *type, *product, *vendor; | ||
88 | json_object_object_get_ex(i, "identifier", &id); | ||
89 | json_object_object_get_ex(i, "name", &name); | ||
90 | json_object_object_get_ex(i, "type", &type); | ||
91 | json_object_object_get_ex(i, "product", &product); | ||
92 | json_object_object_get_ex(i, "vendor", &vendor); | ||
93 | |||
94 | const char *fmt = | ||
95 | "Input device: %s\n" | ||
96 | " Type: %s\n" | ||
97 | " Identifier: %s\n" | ||
98 | " Product ID: %d\n" | ||
99 | " Vendor ID: %d\n\n"; | ||
100 | |||
101 | |||
102 | printf(fmt, json_object_get_string(name), | ||
103 | pretty_type_name(json_object_get_string(type)), | ||
104 | json_object_get_string(id), | ||
105 | json_object_get_int(product), | ||
106 | json_object_get_int(vendor)); | ||
113 | } | 107 | } |
114 | 108 | ||
115 | static void pretty_print_output(json_object *o) { | 109 | static void pretty_print_output(json_object *o) { |
@@ -314,9 +308,11 @@ int main(int argc, char **argv) { | |||
314 | } | 308 | } |
315 | free(cmdtype); | 309 | free(cmdtype); |
316 | 310 | ||
317 | char *command = strdup(""); | 311 | char *command = NULL; |
318 | if (optind < argc) { | 312 | if (optind < argc) { |
319 | command = join_args(argv + optind, argc - optind); | 313 | command = join_args(argv + optind, argc - optind); |
314 | } else { | ||
315 | command = strdup(""); | ||
320 | } | 316 | } |
321 | 317 | ||
322 | int ret = 0; | 318 | int ret = 0; |
@@ -341,7 +337,7 @@ int main(int argc, char **argv) { | |||
341 | } else { | 337 | } else { |
342 | pretty_print(type, obj); | 338 | pretty_print(type, obj); |
343 | } | 339 | } |
344 | free(obj); | 340 | json_object_put(obj); |
345 | } | 341 | } |
346 | } | 342 | } |
347 | close(socketfd); | 343 | close(socketfd); |