summaryrefslogtreecommitdiffstats
path: root/sway/commands/show_marks.c
blob: c7fdc5383d99949ac407d50f18287be3fbc33a7a (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
33
34
35
36
37
38
39
40
41
42
43
#define _POSIX_C_SOURCE 200809L
#include <string.h>
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/tree/view.h"
#include "sway/output.h"
#include "list.h"
#include "log.h"
#include "stringop.h"

static void rebuild_marks_iterator(struct sway_container *con, void *data) {
	if (con->type == C_VIEW) {
		view_update_marks_textures(con->sway_view);
	}
}

struct cmd_results *cmd_show_marks(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "show_marks", EXPECTED_AT_LEAST, 1))) {
		return error;
	}

	if (strcmp(*argv, "yes") == 0) {
		config->show_marks = true;
	} else if (strcmp(*argv, "no") == 0) {
		config->show_marks = false;
	} else {
		return cmd_results_new(CMD_INVALID, "show_marks",
				"Expected 'show_marks <yes|no>'");
	}

	if (config->show_marks) {
		container_for_each_descendant_dfs(&root_container,
				rebuild_marks_iterator, NULL);
	}

	for (int i = 0; i < root_container.children->length; ++i) {
		struct sway_container *con = root_container.children->items[i];
		output_damage_whole(con->sway_output);
	}

	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}