aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--completions/zsh/_swaymsg1
-rw-r--r--include/ipc.h1
-rw-r--r--include/sway/config.h4
-rw-r--r--include/sway/ipc-json.h1
-rw-r--r--sway/ipc-json.c25
-rw-r--r--sway/ipc-server.c13
-rw-r--r--sway/sway-security.7.txt3
-rw-r--r--swaymsg/main.c37
-rw-r--r--swaymsg/swaymsg.1.txt3
9 files changed, 86 insertions, 2 deletions
diff --git a/completions/zsh/_swaymsg b/completions/zsh/_swaymsg
index 1c3ccd65..6bb03279 100644
--- a/completions/zsh/_swaymsg
+++ b/completions/zsh/_swaymsg
@@ -15,6 +15,7 @@
15 15
16types=( 16types=(
17'get_workspaces' 17'get_workspaces'
18'get_seats'
18'get_inputs' 19'get_inputs'
19'get_outputs' 20'get_outputs'
20'get_tree' 21'get_tree'
diff --git a/include/ipc.h b/include/ipc.h
index 9665a88d..83b3b386 100644
--- a/include/ipc.h
+++ b/include/ipc.h
@@ -14,6 +14,7 @@ enum ipc_command_type {
14 IPC_GET_VERSION = 7, 14 IPC_GET_VERSION = 7,
15 IPC_GET_INPUTS = 8, 15 IPC_GET_INPUTS = 8,
16 IPC_GET_CLIPBOARD = 9, 16 IPC_GET_CLIPBOARD = 9,
17 IPC_GET_SEATS = 10,
17 // Events send from sway to clients. Events have the highest bits set. 18 // Events send from sway to clients. Events have the highest bits set.
18 IPC_EVENT_WORKSPACE = ((1<<31) | 0), 19 IPC_EVENT_WORKSPACE = ((1<<31) | 0),
19 IPC_EVENT_OUTPUT = ((1<<31) | 1), 20 IPC_EVENT_OUTPUT = ((1<<31) | 1),
diff --git a/include/sway/config.h b/include/sway/config.h
index a0e7e81f..b20458cb 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -263,8 +263,10 @@ enum ipc_feature {
263 IPC_FEATURE_EVENT_BINDING = 4096, 263 IPC_FEATURE_EVENT_BINDING = 4096,
264 IPC_FEATURE_EVENT_INPUT = 8192, 264 IPC_FEATURE_EVENT_INPUT = 8192,
265 IPC_FEATURE_GET_CLIPBOARD = 16384, 265 IPC_FEATURE_GET_CLIPBOARD = 16384,
266 IPC_FEATURE_GET_SEATS = 32768,
266 267
267 IPC_FEATURE_ALL_COMMANDS = 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 16384, 268 IPC_FEATURE_ALL_COMMANDS =
269 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 16384 | 32768,
268 IPC_FEATURE_ALL_EVENTS = 256 | 512 | 1024 | 2048 | 4096 | 8192, 270 IPC_FEATURE_ALL_EVENTS = 256 | 512 | 1024 | 2048 | 4096 | 8192,
269 271
270 IPC_FEATURE_ALL = IPC_FEATURE_ALL_COMMANDS | IPC_FEATURE_ALL_EVENTS, 272 IPC_FEATURE_ALL = IPC_FEATURE_ALL_COMMANDS | IPC_FEATURE_ALL_EVENTS,
diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h
index 7d87d377..440e3a24 100644
--- a/include/sway/ipc-json.h
+++ b/include/sway/ipc-json.h
@@ -9,6 +9,7 @@ json_object *ipc_json_get_version();
9json_object *ipc_json_describe_container(struct sway_container *c); 9json_object *ipc_json_describe_container(struct sway_container *c);
10json_object *ipc_json_describe_container_recursive(struct sway_container *c); 10json_object *ipc_json_describe_container_recursive(struct sway_container *c);
11json_object *ipc_json_describe_input(struct sway_input_device *device); 11json_object *ipc_json_describe_input(struct sway_input_device *device);
12json_object *ipc_json_describe_seat(struct sway_seat *seat);
12json_object *ipc_json_describe_bar_config(struct bar_config *bar); 13json_object *ipc_json_describe_bar_config(struct bar_config *bar);
13 14
14#endif 15#endif
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index ea7fd9ad..ad37216f 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -267,6 +267,31 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
267 return object; 267 return object;
268} 268}
269 269
270json_object *ipc_json_describe_seat(struct sway_seat *seat) {
271 if (!(sway_assert(seat, "Seat must not be null"))) {
272 return NULL;
273 }
274
275 json_object *object = json_object_new_object();
276 struct sway_container *focus = seat_get_focus(seat);
277
278 json_object_object_add(object, "name",
279 json_object_new_string(seat->wlr_seat->name));
280 json_object_object_add(object, "capabilities",
281 json_object_new_int(seat->wlr_seat->capabilities));
282 json_object_object_add(object, "focus",
283 json_object_new_int(focus ? focus->id : 0));
284
285 json_object *devices = json_object_new_array();
286 struct sway_seat_device *device = NULL;
287 wl_list_for_each(device, &seat->devices, link) {
288 json_object_array_add(devices, ipc_json_describe_input(device->input_device));
289 }
290 json_object_object_add(object, "devices", devices);
291
292 return object;
293}
294
270json_object *ipc_json_describe_bar_config(struct bar_config *bar) { 295json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
271 if (!sway_assert(bar, "Bar must not be NULL")) { 296 if (!sway_assert(bar, "Bar must not be NULL")) {
272 return NULL; 297 return NULL;
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 39d1d0a7..8734e8f8 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -546,6 +546,19 @@ void ipc_client_handle_command(struct ipc_client *client) {
546 goto exit_cleanup; 546 goto exit_cleanup;
547 } 547 }
548 548
549 case IPC_GET_SEATS:
550 {
551 json_object *seats = json_object_new_array();
552 struct sway_seat *seat = NULL;
553 wl_list_for_each(seat, &input_manager->seats, link) {
554 json_object_array_add(seats, ipc_json_describe_seat(seat));
555 }
556 const char *json_string = json_object_to_json_string(seats);
557 ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
558 json_object_put(seats); // free
559 goto exit_cleanup;
560 }
561
549 case IPC_GET_TREE: 562 case IPC_GET_TREE:
550 { 563 {
551 json_object *tree = 564 json_object *tree =
diff --git a/sway/sway-security.7.txt b/sway/sway-security.7.txt
index c8d6758c..2cb4e76d 100644
--- a/sway/sway-security.7.txt
+++ b/sway/sway-security.7.txt
@@ -195,6 +195,9 @@ The following commands are available within this block:
195**outputs** <enabled|disabled>:: 195**outputs** <enabled|disabled>::
196 Controls GET_OUTPUTS. 196 Controls GET_OUTPUTS.
197 197
198**seats** <enabled|disabled>::
199 Controls GET_SEATS.
200
198**tree** <enabled|disabled>:: 201**tree** <enabled|disabled>::
199 Controls GET_TREE. 202 Controls GET_TREE.
200 203
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