diff options
Diffstat (limited to 'swaymsg')
-rw-r--r-- | swaymsg/CMakeLists.txt | 23 | ||||
-rw-r--r-- | swaymsg/main.c | 125 | ||||
-rw-r--r-- | swaymsg/meson.build | 8 |
3 files changed, 86 insertions, 70 deletions
diff --git a/swaymsg/CMakeLists.txt b/swaymsg/CMakeLists.txt deleted file mode 100644 index b428a409..00000000 --- a/swaymsg/CMakeLists.txt +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | add_executable(swaymsg | ||
2 | main.c | ||
3 | ) | ||
4 | |||
5 | include_directories( | ||
6 | ${JSONC_INCLUDE_DIRS} | ||
7 | ) | ||
8 | |||
9 | target_link_libraries(swaymsg | ||
10 | sway-common | ||
11 | ${JSONC_LIBRARIES} | ||
12 | ) | ||
13 | |||
14 | install( | ||
15 | TARGETS swaymsg | ||
16 | RUNTIME | ||
17 | DESTINATION bin | ||
18 | COMPONENT runtime | ||
19 | ) | ||
20 | |||
21 | if (A2X_FOUND) | ||
22 | add_manpage(swaymsg 1) | ||
23 | endif() | ||
diff --git a/swaymsg/main.c b/swaymsg/main.c index 2f9cfb14..c9be3a86 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c | |||
@@ -61,83 +61,112 @@ 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 | } | 81 | } |
104 | printf("\n Sway ID: %s\n", json_object_get_string(id)); | 82 | |
105 | if (size) { | 83 | return name; |
106 | json_object *width, *height; | 84 | } |
107 | json_object_object_get_ex(size, "width", &width); | 85 | |
108 | json_object_object_get_ex(size, "height", &height); | 86 | static void pretty_print_input(json_object *i) { |
109 | printf(" Size: %lfmm x %lfmm\n", | 87 | json_object *id, *name, *type, *product, *vendor; |
110 | json_object_get_double(width), json_object_get_double(height)); | 88 | json_object_object_get_ex(i, "identifier", &id); |
111 | } | 89 | json_object_object_get_ex(i, "name", &name); |
112 | printf("\n"); | 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) { |
116 | json_object *name, *rect, *focused, *active, *ws, *scale; | 110 | json_object *name, *rect, *focused, *active, *ws; |
117 | json_object_object_get_ex(o, "name", &name); | 111 | json_object_object_get_ex(o, "name", &name); |
118 | json_object_object_get_ex(o, "rect", &rect); | 112 | json_object_object_get_ex(o, "rect", &rect); |
119 | json_object_object_get_ex(o, "focused", &focused); | 113 | json_object_object_get_ex(o, "focused", &focused); |
120 | json_object_object_get_ex(o, "active", &active); | 114 | json_object_object_get_ex(o, "active", &active); |
121 | json_object_object_get_ex(o, "current_workspace", &ws); | 115 | json_object_object_get_ex(o, "current_workspace", &ws); |
116 | json_object *make, *model, *serial, *scale, *refresh, *transform; | ||
117 | json_object_object_get_ex(o, "make", &make); | ||
118 | json_object_object_get_ex(o, "model", &model); | ||
119 | json_object_object_get_ex(o, "serial", &serial); | ||
122 | json_object_object_get_ex(o, "scale", &scale); | 120 | json_object_object_get_ex(o, "scale", &scale); |
121 | json_object_object_get_ex(o, "refresh", &refresh); | ||
122 | json_object_object_get_ex(o, "transform", &transform); | ||
123 | json_object *x, *y, *width, *height; | 123 | json_object *x, *y, *width, *height; |
124 | json_object_object_get_ex(rect, "x", &x); | 124 | json_object_object_get_ex(rect, "x", &x); |
125 | json_object_object_get_ex(rect, "y", &y); | 125 | json_object_object_get_ex(rect, "y", &y); |
126 | json_object_object_get_ex(rect, "width", &width); | 126 | json_object_object_get_ex(rect, "width", &width); |
127 | json_object_object_get_ex(rect, "height", &height); | 127 | json_object_object_get_ex(rect, "height", &height); |
128 | json_object *modes; | ||
129 | json_object_object_get_ex(o, "modes", &modes); | ||
130 | |||
128 | printf( | 131 | printf( |
129 | "Output %s%s%s\n" | 132 | "Output %s '%s %s %s'%s%s\n" |
130 | " Geometry: %dx%d @ %d,%d\n" | 133 | " Current mode: %dx%d @ %f Hz\n" |
134 | " Position: %d,%d\n" | ||
131 | " Scale factor: %dx\n" | 135 | " Scale factor: %dx\n" |
132 | " Workspace: %s\n\n", | 136 | " Transform: %s\n" |
137 | " Workspace: %s\n", | ||
133 | json_object_get_string(name), | 138 | json_object_get_string(name), |
139 | json_object_get_string(make), | ||
140 | json_object_get_string(model), | ||
141 | json_object_get_string(serial), | ||
134 | json_object_get_boolean(focused) ? " (focused)" : "", | 142 | json_object_get_boolean(focused) ? " (focused)" : "", |
135 | !json_object_get_boolean(active) ? " (inactive)" : "", | 143 | !json_object_get_boolean(active) ? " (inactive)" : "", |
136 | json_object_get_int(width), json_object_get_int(height), | 144 | json_object_get_int(width), json_object_get_int(height), |
145 | (float)json_object_get_int(refresh) / 1000, | ||
137 | json_object_get_int(x), json_object_get_int(y), | 146 | json_object_get_int(x), json_object_get_int(y), |
138 | json_object_get_int(scale), | 147 | json_object_get_int(scale), |
148 | json_object_get_string(transform), | ||
139 | json_object_get_string(ws) | 149 | json_object_get_string(ws) |
140 | ); | 150 | ); |
151 | |||
152 | size_t modes_len = json_object_array_length(modes); | ||
153 | if (modes_len > 0) { | ||
154 | printf(" Available modes:\n"); | ||
155 | for (size_t i = 0; i < modes_len; ++i) { | ||
156 | json_object *mode = json_object_array_get_idx(modes, i); | ||
157 | |||
158 | json_object *mode_width, *mode_height, *mode_refresh; | ||
159 | json_object_object_get_ex(mode, "width", &mode_width); | ||
160 | json_object_object_get_ex(mode, "height", &mode_height); | ||
161 | json_object_object_get_ex(mode, "refresh", &mode_refresh); | ||
162 | |||
163 | printf(" %dx%d @ %f Hz\n", json_object_get_int(mode_width), | ||
164 | json_object_get_int(mode_height), | ||
165 | (float)json_object_get_int(mode_refresh) / 1000); | ||
166 | } | ||
167 | } | ||
168 | |||
169 | printf("\n"); | ||
141 | } | 170 | } |
142 | 171 | ||
143 | static void pretty_print_version(json_object *v) { | 172 | static void pretty_print_version(json_object *v) { |
@@ -149,7 +178,7 @@ static void pretty_print_version(json_object *v) { | |||
149 | static void pretty_print_clipboard(json_object *v) { | 178 | static void pretty_print_clipboard(json_object *v) { |
150 | if (success(v, true)) { | 179 | if (success(v, true)) { |
151 | if (json_object_is_type(v, json_type_array)) { | 180 | if (json_object_is_type(v, json_type_array)) { |
152 | for (int i = 0; i < json_object_array_length(v); ++i) { | 181 | for (size_t i = 0; i < json_object_array_length(v); ++i) { |
153 | json_object *o = json_object_array_get_idx(v, i); | 182 | json_object *o = json_object_array_get_idx(v, i); |
154 | printf("%s\n", json_object_get_string(o)); | 183 | printf("%s\n", json_object_get_string(o)); |
155 | } | 184 | } |
@@ -225,7 +254,7 @@ int main(int argc, char **argv) { | |||
225 | char *socket_path = NULL; | 254 | char *socket_path = NULL; |
226 | char *cmdtype = NULL; | 255 | char *cmdtype = NULL; |
227 | 256 | ||
228 | init_log(L_INFO); | 257 | wlr_log_init(L_INFO, NULL); |
229 | 258 | ||
230 | static struct option long_options[] = { | 259 | static struct option long_options[] = { |
231 | {"help", no_argument, NULL, 'h'}, | 260 | {"help", no_argument, NULL, 'h'}, |
@@ -314,9 +343,11 @@ int main(int argc, char **argv) { | |||
314 | } | 343 | } |
315 | free(cmdtype); | 344 | free(cmdtype); |
316 | 345 | ||
317 | char *command = strdup(""); | 346 | char *command = NULL; |
318 | if (optind < argc) { | 347 | if (optind < argc) { |
319 | command = join_args(argv + optind, argc - optind); | 348 | command = join_args(argv + optind, argc - optind); |
349 | } else { | ||
350 | command = strdup(""); | ||
320 | } | 351 | } |
321 | 352 | ||
322 | int ret = 0; | 353 | int ret = 0; |
@@ -341,7 +372,7 @@ int main(int argc, char **argv) { | |||
341 | } else { | 372 | } else { |
342 | pretty_print(type, obj); | 373 | pretty_print(type, obj); |
343 | } | 374 | } |
344 | free(obj); | 375 | json_object_put(obj); |
345 | } | 376 | } |
346 | } | 377 | } |
347 | close(socketfd); | 378 | close(socketfd); |
diff --git a/swaymsg/meson.build b/swaymsg/meson.build new file mode 100644 index 00000000..8638b838 --- /dev/null +++ b/swaymsg/meson.build | |||
@@ -0,0 +1,8 @@ | |||
1 | executable( | ||
2 | 'swaymsg', | ||
3 | 'main.c', | ||
4 | include_directories: [sway_inc], | ||
5 | dependencies: [jsonc, wlroots], | ||
6 | link_with: [lib_sway_common], | ||
7 | install: true | ||
8 | ) | ||