From 6e85e7ec89e06dd1270a6ab08391cd7320d4c2d2 Mon Sep 17 00:00:00 2001 From: madblobfish Date: Thu, 1 Nov 2018 09:28:02 +0100 Subject: [PATCH] remove empty seats --- include/sway/input/input-manager.h | 2 ++ include/sway/input/seat.h | 2 ++ sway/commands/seat/detach.c | 4 ++++ sway/input/input-manager.c | 5 +++++ sway/input/seat.c | 6 ++++++ 5 files changed, 19 insertions(+) diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index e166a2377..b1ad51adb 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -53,6 +53,8 @@ struct sway_seat *input_manager_get_seat(const char *seat_name, bool create); */ void input_manager_verify_fallback_seat(void); +void input_manager_seat_consider_destroy(const char *seat_name); + /** * Gets the last seat the user interacted with */ diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index 1c9354df4..f6bca14d5 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -94,6 +94,8 @@ struct sway_seat *seat_create(const char *seat_name); void seat_destroy(struct sway_seat *seat); +void seat_consider_destroy(struct sway_seat *seat); + void seat_add_device(struct sway_seat *seat, struct sway_input_device *device); diff --git a/sway/commands/seat/detach.c b/sway/commands/seat/detach.c index 5c2f1cad6..400fb31d8 100644 --- a/sway/commands/seat/detach.c +++ b/sway/commands/seat/detach.c @@ -2,6 +2,7 @@ #include #include "sway/commands.h" #include "sway/config.h" +#include "sway/input/input-manager.h" struct cmd_results *seat_cmd_detach(int argc, char **argv) { struct cmd_results *error = NULL; @@ -23,5 +24,8 @@ struct cmd_results *seat_cmd_detach(int argc, char **argv) { if (!config->validating) { input_manager_apply_seat_config(new_seat_config(current_seat_config->name)); } + + input_manager_seat_consider_destroy(current_seat_config->name); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index f99fc395b..4ed7d1abb 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -729,6 +729,11 @@ void input_manager_apply_seat_config(struct seat_config *seat_config) { } } +void input_manager_seat_consider_destroy(const char *seat_name) { + struct sway_seat *seat = input_manager_get_seat(seat_name, false); + seat_consider_destroy(seat); +} + void input_manager_configure_xcursor(void) { struct sway_seat *seat = NULL; wl_list_for_each(seat, &server.input->seats, link) { diff --git a/sway/input/seat.c b/sway/input/seat.c index 18664d7cb..d05d8b4c3 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -59,6 +59,12 @@ static void seat_node_destroy(struct sway_seat_node *seat_node) { free(seat_node); } +void seat_consider_destroy(struct sway_seat *seat) { + if (wl_list_empty(&seat->devices)) { + seat_destroy(seat); + } +} + /** * Activate all views within this container recursively. */