aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar/workspace_min_width.c
blob: 8d65592ca82bf246455c46c61b8298e7c8769f20 (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
#include <stdlib.h>
#include <strings.h>
#include "config.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "log.h"

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

	struct bar_config *bar = config->current_bar;

	char *end;
	int min_width = strtol(argv[0], &end, 10);
	if (min_width < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) {
		return cmd_results_new(CMD_INVALID,
				"[Bar %s] Invalid minimum workspace button width value: %s",
				bar->id, argv[0]);
	}

	if (argc == 2 && strcasecmp(argv[1], "px") != 0) {
		return cmd_results_new(CMD_INVALID,
				"Expected 'workspace_min_width <px> [px]'");
	}

	sway_log(SWAY_DEBUG, "[Bar %s] Setting minimum workspace button width to %d",
			bar->id, min_width);
	config->current_bar->workspace_min_width = min_width;
	return cmd_results_new(CMD_SUCCESS, NULL);
}