diff options
author | 2017-11-18 11:22:02 -0500 | |
---|---|---|
committer | 2017-11-18 11:22:02 -0500 | |
commit | 733993a651c71f7e2198d505960d6bbd31e0e107 (patch) | |
tree | e51732c5872b624e73355f9e5b3f762101f3cd0d /sway/old/commands/bar/colors.c | |
parent | Initial (awful) pass on xdg shell support (diff) | |
download | sway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.gz sway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.zst sway-733993a651c71f7e2198d505960d6bbd31e0e107.zip |
Move everything to sway/old/
Diffstat (limited to 'sway/old/commands/bar/colors.c')
-rw-r--r-- | sway/old/commands/bar/colors.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/sway/old/commands/bar/colors.c b/sway/old/commands/bar/colors.c new file mode 100644 index 00000000..8b3b0aac --- /dev/null +++ b/sway/old/commands/bar/colors.c | |||
@@ -0,0 +1,129 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | |||
4 | static struct cmd_results *parse_single_color(char **color, const char *cmd_name, int argc, char **argv) { | ||
5 | struct cmd_results *error = NULL; | ||
6 | if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) { | ||
7 | return error; | ||
8 | } | ||
9 | |||
10 | if (!*color) { | ||
11 | *color = malloc(10); | ||
12 | if (!*color) { | ||
13 | return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color"); | ||
14 | } | ||
15 | } | ||
16 | |||
17 | error = add_color(cmd_name, *color, argv[0]); | ||
18 | if (error) { | ||
19 | return error; | ||
20 | } | ||
21 | |||
22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
23 | } | ||
24 | |||
25 | static struct cmd_results *parse_three_colors(char ***colors, const char *cmd_name, int argc, char **argv) { | ||
26 | struct cmd_results *error = NULL; | ||
27 | if (argc != 3) { | ||
28 | return cmd_results_new(CMD_INVALID, cmd_name, "Requires exactly three color values"); | ||
29 | } | ||
30 | |||
31 | int i; | ||
32 | for (i = 0; i < 3; i++) { | ||
33 | if (!*colors[i]) { | ||
34 | *(colors[i]) = malloc(10); | ||
35 | if (!*(colors[i])) { | ||
36 | return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color"); | ||
37 | } | ||
38 | } | ||
39 | error = add_color(cmd_name, *(colors[i]), argv[i]); | ||
40 | if (error) { | ||
41 | return error; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
46 | } | ||
47 | |||
48 | struct cmd_results *bar_cmd_colors(int argc, char **argv) { | ||
49 | struct cmd_results *error = NULL; | ||
50 | if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) { | ||
51 | return error; | ||
52 | } | ||
53 | |||
54 | if (strcmp("{", argv[0]) != 0) { | ||
55 | return cmd_results_new(CMD_INVALID, "colors", | ||
56 | "Expected '{' at the start of colors config definition."); | ||
57 | } | ||
58 | |||
59 | return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL); | ||
60 | } | ||
61 | |||
62 | struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) { | ||
63 | char **colors[3] = { | ||
64 | &(config->current_bar->colors.active_workspace_border), | ||
65 | &(config->current_bar->colors.active_workspace_bg), | ||
66 | &(config->current_bar->colors.active_workspace_text) | ||
67 | }; | ||
68 | return parse_three_colors(colors, "active_workspace", argc, argv); | ||
69 | } | ||
70 | |||
71 | struct cmd_results *bar_colors_cmd_background(int argc, char **argv) { | ||
72 | return parse_single_color(&(config->current_bar->colors.background), "background", argc, argv); | ||
73 | } | ||
74 | |||
75 | struct cmd_results *bar_colors_cmd_focused_background(int argc, char **argv) { | ||
76 | return parse_single_color(&(config->current_bar->colors.focused_background), "focused_background", argc, argv); | ||
77 | } | ||
78 | |||
79 | struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) { | ||
80 | char **colors[3] = { | ||
81 | &(config->current_bar->colors.binding_mode_border), | ||
82 | &(config->current_bar->colors.binding_mode_bg), | ||
83 | &(config->current_bar->colors.binding_mode_text) | ||
84 | }; | ||
85 | return parse_three_colors(colors, "binding_mode", argc, argv); | ||
86 | } | ||
87 | |||
88 | struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) { | ||
89 | char **colors[3] = { | ||
90 | &(config->current_bar->colors.focused_workspace_border), | ||
91 | &(config->current_bar->colors.focused_workspace_bg), | ||
92 | &(config->current_bar->colors.focused_workspace_text) | ||
93 | }; | ||
94 | return parse_three_colors(colors, "focused_workspace", argc, argv); | ||
95 | } | ||
96 | |||
97 | struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) { | ||
98 | char **colors[3] = { | ||
99 | &(config->current_bar->colors.inactive_workspace_border), | ||
100 | &(config->current_bar->colors.inactive_workspace_bg), | ||
101 | &(config->current_bar->colors.inactive_workspace_text) | ||
102 | }; | ||
103 | return parse_three_colors(colors, "inactive_workspace", argc, argv); | ||
104 | } | ||
105 | |||
106 | struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) { | ||
107 | return parse_single_color(&(config->current_bar->colors.separator), "separator", argc, argv); | ||
108 | } | ||
109 | |||
110 | struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) { | ||
111 | return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv); | ||
112 | } | ||
113 | |||
114 | struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) { | ||
115 | return parse_single_color(&(config->current_bar->colors.statusline), "statusline", argc, argv); | ||
116 | } | ||
117 | |||
118 | struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) { | ||
119 | return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv); | ||
120 | } | ||
121 | |||
122 | struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) { | ||
123 | char **colors[3] = { | ||
124 | &(config->current_bar->colors.urgent_workspace_border), | ||
125 | &(config->current_bar->colors.urgent_workspace_bg), | ||
126 | &(config->current_bar->colors.urgent_workspace_text) | ||
127 | }; | ||
128 | return parse_three_colors(colors, "urgent_workspace", argc, argv); | ||
129 | } | ||