aboutsummaryrefslogtreecommitdiffstats
path: root/swaymsg
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-11 23:51:47 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-12 18:17:36 +1000
commitc72940837c24b5df99c95667befe2e4e5c64575a (patch)
treeeae77f45803c33f0825ee134956b9dac292a52b1 /swaymsg
parentMerge pull request #1952 from Dudemanguy911/fix-crash-on-fullscreen (diff)
downloadsway-c72940837c24b5df99c95667befe2e4e5c64575a.tar.gz
sway-c72940837c24b5df99c95667befe2e4e5c64575a.tar.zst
sway-c72940837c24b5df99c95667befe2e4e5c64575a.zip
Implement IPC get_seats command
Diffstat (limited to 'swaymsg')
-rw-r--r--swaymsg/main.c37
-rw-r--r--swaymsg/swaymsg.1.txt3
2 files changed, 39 insertions, 1 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 7e3622d9..89af7345 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -106,6 +106,35 @@ static void pretty_print_input(json_object *i) {
106 json_object_get_int(vendor)); 106 json_object_get_int(vendor));
107} 107}
108 108
109static void pretty_print_seat(json_object *i) {
110 json_object *name, *capabilities, *devices;
111 json_object_object_get_ex(i, "name", &name);
112 json_object_object_get_ex(i, "capabilities", &capabilities);
113 json_object_object_get_ex(i, "devices", &devices);
114
115 const char *fmt =
116 "Seat: %s\n"
117 " Capabilities: %d\n";
118
119 printf(fmt, json_object_get_string(name),
120 json_object_get_int(capabilities));
121
122 size_t devices_len = json_object_array_length(devices);
123 if (devices_len > 0) {
124 printf(" Devices:\n");
125 for (size_t i = 0; i < devices_len; ++i) {
126 json_object *device = json_object_array_get_idx(devices, i);
127
128 json_object *device_name;
129 json_object_object_get_ex(device, "name", &device_name);
130
131 printf(" %s\n", json_object_get_string(device_name));
132 }
133 }
134
135 printf("\n");
136}
137
109static void pretty_print_output(json_object *o) { 138static void pretty_print_output(json_object *o) {
110 json_object *name, *rect, *focused, *active, *ws; 139 json_object *name, *rect, *focused, *active, *ws;
111 json_object_object_get_ex(o, "name", &name); 140 json_object_object_get_ex(o, "name", &name);
@@ -211,7 +240,8 @@ static void pretty_print_clipboard(json_object *v) {
211static void pretty_print(int type, json_object *resp) { 240static void pretty_print(int type, json_object *resp) {
212 if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES && 241 if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES &&
213 type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS && 242 type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS &&
214 type != IPC_GET_VERSION && type != IPC_GET_CLIPBOARD) { 243 type != IPC_GET_VERSION && type != IPC_GET_CLIPBOARD &&
244 type != IPC_GET_SEATS) {
215 printf("%s\n", json_object_to_json_string_ext(resp, 245 printf("%s\n", json_object_to_json_string_ext(resp,
216 JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); 246 JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
217 return; 247 return;
@@ -244,6 +274,9 @@ static void pretty_print(int type, json_object *resp) {
244 case IPC_GET_OUTPUTS: 274 case IPC_GET_OUTPUTS:
245 pretty_print_output(obj); 275 pretty_print_output(obj);
246 break; 276 break;
277 case IPC_GET_SEATS:
278 pretty_print_seat(obj);
279 break;
247 } 280 }
248 } 281 }
249} 282}
@@ -324,6 +357,8 @@ int main(int argc, char **argv) {
324 type = IPC_COMMAND; 357 type = IPC_COMMAND;
325 } else if (strcasecmp(cmdtype, "get_workspaces") == 0) { 358 } else if (strcasecmp(cmdtype, "get_workspaces") == 0) {
326 type = IPC_GET_WORKSPACES; 359 type = IPC_GET_WORKSPACES;
360 } else if (strcasecmp(cmdtype, "get_seats") == 0) {
361 type = IPC_GET_SEATS;
327 } else if (strcasecmp(cmdtype, "get_inputs") == 0) { 362 } else if (strcasecmp(cmdtype, "get_inputs") == 0) {
328 type = IPC_GET_INPUTS; 363 type = IPC_GET_INPUTS;
329 } else if (strcasecmp(cmdtype, "get_outputs") == 0) { 364 } else if (strcasecmp(cmdtype, "get_outputs") == 0) {
diff --git a/swaymsg/swaymsg.1.txt b/swaymsg/swaymsg.1.txt
index abc517c8..52209b12 100644
--- a/swaymsg/swaymsg.1.txt
+++ b/swaymsg/swaymsg.1.txt
@@ -48,6 +48,9 @@ IPC Message Types
48*get_workspaces*:: 48*get_workspaces*::
49 Gets a JSON-encoded list of workspaces and their status. 49 Gets a JSON-encoded list of workspaces and their status.
50 50
51*get_seats*::
52 Gets a JSON-encoded list of current seats.
53
51*get_inputs*:: 54*get_inputs*::
52 Gets a JSON-encoded list of current inputs. 55 Gets a JSON-encoded list of current inputs.
53 56