aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/kill.c
blob: 4b3666be269b1dce2d937e1af9119f882b150d3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <wlr/util/log.h>
#include "log.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/view.h"
#include "sway/commands.h"

struct cmd_results *cmd_kill(int argc, char **argv) {
	if (config->reading) {
		return cmd_results_new(CMD_FAILURE, "kill",
			"Command 'kill' cannot be used in the config file");
	}
	if (config->handler_context.current_container == NULL) {
		wlr_log(L_DEBUG, "no container to kill");
		return cmd_results_new(CMD_SUCCESS, NULL, NULL);
	}
	enum swayc_types type = config->handler_context.current_container->type;
	if (type != C_VIEW && type != C_CONTAINER) {
		return cmd_results_new(CMD_INVALID, NULL,
				"Can only kill views and containers with this command");
	}

	// TODO close arbitrary containers without a view
	struct sway_view *view =
		config->handler_context.current_container->sway_view;

	if (view) {
		view_close(view);
	}

	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}