diff --git a/include/sway/commands.h b/include/sway/commands.h index 3ed007635..19ddb0579 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -265,6 +265,7 @@ sway_cmd output_cmd_transform; sway_cmd seat_cmd_attach; sway_cmd seat_cmd_cursor; +sway_cmd seat_cmd_detach; sway_cmd seat_cmd_fallback; sway_cmd seat_cmd_hide_cursor; sway_cmd seat_cmd_pointer_constraint; diff --git a/include/sway/config.h b/include/sway/config.h index 43ea77788..caa4d04bf 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -571,6 +571,9 @@ struct seat_attachment_config *seat_config_get_attachment( struct seat_config *store_seat_config(struct seat_config *seat); +void seat_config_remove_attachment( + struct seat_config *seat_config, char *identifier); + int output_name_cmp(const void *item, const void *data); void output_get_identifier(char *identifier, size_t len, diff --git a/sway/commands/seat.c b/sway/commands/seat.c index 5b23dcc6a..8b25963f0 100644 --- a/sway/commands/seat.c +++ b/sway/commands/seat.c @@ -10,6 +10,7 @@ static struct cmd_handler seat_handlers[] = { { "attach", seat_cmd_attach }, { "cursor", seat_cmd_cursor }, + { "detach", seat_cmd_detach }, { "fallback", seat_cmd_fallback }, { "hide_cursor", seat_cmd_hide_cursor }, { "pointer_constraint", seat_cmd_pointer_constraint }, diff --git a/sway/commands/seat/detach.c b/sway/commands/seat/detach.c new file mode 100644 index 000000000..5c2f1cad6 --- /dev/null +++ b/sway/commands/seat/detach.c @@ -0,0 +1,27 @@ +#define _XOPEN_SOURCE 700 +#include +#include "sway/commands.h" +#include "sway/config.h" + +struct cmd_results *seat_cmd_detach(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "detach", EXPECTED_AT_LEAST, 1))) { + return error; + } + struct seat_config *current_seat_config = config->handler_context.seat_config; + if (!current_seat_config) { + return cmd_results_new(CMD_FAILURE, "detach", "No seat defined"); + } + + int i; + i = list_seq_find(config->seat_configs, seat_name_cmp, current_seat_config->name); + if (i >= 0) { + struct seat_config *sc = config->seat_configs->items[i]; + seat_config_remove_attachment(sc, strdup(argv[0])); + } + + if (!config->validating) { + input_manager_apply_seat_config(new_seat_config(current_seat_config->name)); + } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/config/seat.c b/sway/config/seat.c index 04a44e3a8..312c890b9 100644 --- a/sway/config/seat.c +++ b/sway/config/seat.c @@ -191,3 +191,14 @@ struct seat_attachment_config *seat_config_get_attachment( return NULL; } + +void seat_config_remove_attachment(struct seat_config *seat_config, char *identifier) { + for (int i = 0; i < seat_config->attachments->length; ++i) { + struct seat_attachment_config *attachment = seat_config->attachments->items[i]; + if (strcmp(attachment->identifier, identifier) == 0) { + list_del(seat_config->attachments, i); + seat_attachment_config_free(attachment); + break; + } + } +} diff --git a/sway/meson.build b/sway/meson.build index 293a4ed20..04cbdc3fc 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -82,6 +82,7 @@ sway_sources = files( 'commands/seat.c', 'commands/seat/attach.c', 'commands/seat/cursor.c', + 'commands/seat/detach.c', 'commands/seat/fallback.c', 'commands/seat/hide_cursor.c', 'commands/seat/pointer_constraint.c', diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index 376e18338..30e09cef4 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd @@ -150,6 +150,11 @@ sitting in their own "seat"). Attach an input device to this seat by its input identifier. A special value of "\*" will attach all devices to the seat. +*seat* detach + Detaches an input device from this seat by its input identifier. + + Note: the fallback seat will catch input devices with no seat. + *seat* cursor move|set Move specified seat's cursor relative to current position or wrap to absolute coordinates (with respect to the global coordinate space).