aboutsummaryrefslogtreecommitdiffstats
path: root/swaymsg
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-18 14:27:38 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-18 14:27:38 -0500
commitf2985000f364693fbeb832df1c4fd468c608e40f (patch)
treef84600bdc02e4239fd93f203eb020a90fc7a5f48 /swaymsg
parentMerge branch 'wlroots' into feature/input (diff)
downloadsway-f2985000f364693fbeb832df1c4fd468c608e40f.tar.gz
sway-f2985000f364693fbeb832df1c4fd468c608e40f.tar.zst
sway-f2985000f364693fbeb832df1c4fd468c608e40f.zip
ipc get_inputs
Diffstat (limited to 'swaymsg')
-rw-r--r--swaymsg/main.c72
1 files changed, 33 insertions, 39 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 2f9cfb14..18f17a59 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
64static void pretty_print_input(json_object *i) { 64static 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
86static 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
115static void pretty_print_output(json_object *o) { 109static void pretty_print_output(json_object *o) {