aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/client.c
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin@gmail.com>2016-09-01 21:39:08 -0500
committerLibravatar Zandr Martin <zandrmartin@gmail.com>2016-09-01 21:39:08 -0500
commitb374c35758777f98e5ddbe4b0dc43bd7c80f36d7 (patch)
tree04bb4cfc3da7d2e0de7fbc38db42f65c66d2df4c /sway/commands/client.c
parentMerge pull request #874 from yohanesu75/ipc-client-fix (diff)
downloadsway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.gz
sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.zst
sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.zip
refactor commands.c
Diffstat (limited to 'sway/commands/client.c')
-rw-r--r--sway/commands/client.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/sway/commands/client.c b/sway/commands/client.c
new file mode 100644
index 00000000..993fa2f8
--- /dev/null
+++ b/sway/commands/client.c
@@ -0,0 +1,68 @@
1#include <stdlib.h>
2#include <string.h>
3#include "commands.h"
4
5static struct cmd_results *parse_border_color(struct border_colors *border_colors, const char *cmd_name, int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if (argc != 5) {
8 return cmd_results_new(CMD_INVALID, cmd_name, "Requires exactly five color values");
9 }
10
11 uint32_t colors[5];
12 int i;
13 for (i = 0; i < 5; i++) {
14 char buffer[10];
15 error = add_color(cmd_name, buffer, argv[i]);
16 if (error) {
17 return error;
18 }
19 colors[i] = strtoul(buffer+1, NULL, 16);
20 }
21
22 border_colors->border = colors[0];
23 border_colors->background = colors[1];
24 border_colors->text = colors[2];
25 border_colors->indicator = colors[3];
26 border_colors->child_border = colors[4];
27
28 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
29}
30
31struct cmd_results *cmd_client_focused(int argc, char **argv) {
32 return parse_border_color(&config->border_colors.focused, "client.focused", argc, argv);
33}
34
35struct cmd_results *cmd_client_focused_inactive(int argc, char **argv) {
36 return parse_border_color(&config->border_colors.focused_inactive, "client.focused_inactive", argc, argv);
37}
38
39struct cmd_results *cmd_client_unfocused(int argc, char **argv) {
40 return parse_border_color(&config->border_colors.unfocused, "client.unfocused", argc, argv);
41}
42
43struct cmd_results *cmd_client_urgent(int argc, char **argv) {
44 return parse_border_color(&config->border_colors.urgent, "client.urgent", argc, argv);
45}
46
47struct cmd_results *cmd_client_placeholder(int argc, char **argv) {
48 return parse_border_color(&config->border_colors.placeholder, "client.placeholder", argc, argv);
49}
50
51struct cmd_results *cmd_client_background(int argc, char **argv) {
52 char buffer[10];
53 struct cmd_results *error = NULL;
54 uint32_t background;
55
56 if (argc != 1) {
57 return cmd_results_new(CMD_INVALID, "client.background", "Requires exactly one color value");
58 }
59
60 error = add_color("client.background", buffer, argv[0]);
61 if (error) {
62 return error;
63 }
64
65 background = strtoul(buffer+1, NULL, 16);
66 config->border_colors.background = background;
67 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
68}