From c6ce7a1c35f14d0496946f2c5bdc5191df6683a7 Mon Sep 17 00:00:00 2001 From: itycodes Date: Sun, 27 Oct 2024 07:41:54 +0100 Subject: [PATCH] Implement a murder command The murder command destroys the client that a given surface is connected to. --- include/sway/commands.h | 1 + include/sway/tree/view.h | 2 ++ sway/commands.c | 1 + sway/commands/murder.c | 31 +++++++++++++++++++++++++++++++ sway/meson.build | 1 + sway/tree/view.c | 5 +++++ 6 files changed, 41 insertions(+) create mode 100644 sway/commands/murder.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 5210d3ba..8c8519bb 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -150,6 +150,7 @@ sway_cmd cmd_input; sway_cmd cmd_seat; sway_cmd cmd_ipc; sway_cmd cmd_kill; +sway_cmd cmd_murder; sway_cmd cmd_layout; sway_cmd cmd_log_colors; sway_cmd cmd_mark; diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index f6032221..58e0c774 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -272,6 +272,8 @@ void view_set_tiled(struct sway_view *view, bool tiled); void view_close(struct sway_view *view); +void view_murder(struct sway_view *view); + void view_close_popups(struct sway_view *view); // view implementation diff --git a/sway/commands.c b/sway/commands.c index c2c12ee6..447c7631 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -124,6 +124,7 @@ static const struct cmd_handler command_handlers[] = { { "mark", cmd_mark }, { "max_render_time", cmd_max_render_time }, { "move", cmd_move }, + { "murder", cmd_murder }, { "nop", cmd_nop }, { "opacity", cmd_opacity }, { "reload", cmd_reload }, diff --git a/sway/commands/murder.c b/sway/commands/murder.c new file mode 100644 index 00000000..8f02b052 --- /dev/null +++ b/sway/commands/murder.c @@ -0,0 +1,31 @@ +#include "log.h" +#include "sway/input/input-manager.h" +#include "sway/input/seat.h" +#include "sway/tree/container.h" +#include "sway/tree/view.h" +#include "sway/tree/workspace.h" +#include "sway/commands.h" + +static void close_container_iterator(struct sway_container *con, void *data) { + if (con->view) { + view_murder(con->view); + } +} + +struct cmd_results *cmd_murder(int argc, char **argv) { + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, + "Can't run this command while there's no outputs connected."); + } + struct sway_container *con = config->handler_context.container; + struct sway_workspace *ws = config->handler_context.workspace; + + if (con) { + close_container_iterator(con, NULL); + container_for_each_child(con, close_container_iterator, NULL); + } else { + workspace_for_each_container(ws, close_container_iterator, NULL); + } + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/meson.build b/sway/meson.build index 8042c89b..a153d5b2 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -73,6 +73,7 @@ sway_sources = files( 'commands/inhibit_idle.c', 'commands/kill.c', 'commands/mark.c', + 'commands/murder.c', 'commands/max_render_time.c', 'commands/opacity.c', 'commands/include.c', diff --git a/sway/tree/view.c b/sway/tree/view.c index 492095b9..3cb3d374 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -454,6 +454,11 @@ void view_close(struct sway_view *view) { } } +void view_murder(struct sway_view *view) { + struct wl_client *client = wl_resource_get_client(view->surface->resource); + wl_client_destroy(client); +} + void view_close_popups(struct sway_view *view) { if (view->impl->close_popups) { view->impl->close_popups(view);