diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-12-15 22:31:35 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-12-15 22:31:35 -0500 |
commit | 1825cf32bf45f32b5291ed42606d6911b10f72cc (patch) | |
tree | a4bfe189ac0b49d132a7f48500bb07a5e8241e21 /swaybar/main.c | |
parent | [swaybar] Get bar config via IPC (diff) | |
download | sway-1825cf32bf45f32b5291ed42606d6911b10f72cc.tar.gz sway-1825cf32bf45f32b5291ed42606d6911b10f72cc.tar.zst sway-1825cf32bf45f32b5291ed42606d6911b10f72cc.zip |
Apply color config from swaybar
Diffstat (limited to 'swaybar/main.c')
-rw-r--r-- | swaybar/main.c | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/swaybar/main.c b/swaybar/main.c index 5a16be93..21a8d292 100644 --- a/swaybar/main.c +++ b/swaybar/main.c | |||
@@ -143,6 +143,18 @@ void ipc_update_workspaces() { | |||
143 | free(res); | 143 | free(res); |
144 | } | 144 | } |
145 | 145 | ||
146 | uint32_t parse_color(const char *color) { | ||
147 | if (color[0] != '#') { | ||
148 | sway_abort("Invalid color %s", color); | ||
149 | } | ||
150 | char *end; | ||
151 | uint32_t res = (uint32_t)strtol(color + 1, &end, 16); | ||
152 | if (strlen(color) == 7) { | ||
153 | res = (res << 8) | 0xFF; | ||
154 | } | ||
155 | return res; | ||
156 | } | ||
157 | |||
146 | void bar_ipc_init(int outputi, const char *bar_id) { | 158 | void bar_ipc_init(int outputi, const char *bar_id) { |
147 | uint32_t len = 0; | 159 | uint32_t len = 0; |
148 | char *res = ipc_single_command(socketfd, IPC_GET_OUTPUTS, NULL, &len); | 160 | char *res = ipc_single_command(socketfd, IPC_GET_OUTPUTS, NULL, &len); |
@@ -161,7 +173,7 @@ void bar_ipc_init(int outputi, const char *bar_id) { | |||
161 | json_object *bar_config = json_tokener_parse(res); | 173 | json_object *bar_config = json_tokener_parse(res); |
162 | json_object *tray_output, *mode, *hidden_state, *position, *_status_command; | 174 | json_object *tray_output, *mode, *hidden_state, *position, *_status_command; |
163 | json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers; | 175 | json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers; |
164 | json_object *binding_mode_indicator, *verbose, *colors; | 176 | json_object *binding_mode_indicator, *verbose, *_colors; |
165 | json_object_object_get_ex(bar_config, "tray_output", &tray_output); | 177 | json_object_object_get_ex(bar_config, "tray_output", &tray_output); |
166 | json_object_object_get_ex(bar_config, "mode", &mode); | 178 | json_object_object_get_ex(bar_config, "mode", &mode); |
167 | json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); | 179 | json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); |
@@ -173,8 +185,66 @@ void bar_ipc_init(int outputi, const char *bar_id) { | |||
173 | json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); | 185 | json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); |
174 | json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); | 186 | json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); |
175 | json_object_object_get_ex(bar_config, "verbose", &verbose); | 187 | json_object_object_get_ex(bar_config, "verbose", &verbose); |
176 | json_object_object_get_ex(bar_config, "colors", &colors); | 188 | json_object_object_get_ex(bar_config, "colors", &_colors); |
189 | |||
190 | // TODO: More of these options | ||
191 | // TODO: Refactor swaybar into several files, create a bar config struct (shared with compositor?) | ||
177 | if (_status_command) status_command = strdup(json_object_get_string(_status_command)); | 192 | if (_status_command) status_command = strdup(json_object_get_string(_status_command)); |
193 | |||
194 | if (_colors) { | ||
195 | json_object *background, *statusline, *separator; | ||
196 | json_object *focused_workspace_border, *focused_workspace_bg, *focused_workspace_text; | ||
197 | json_object *inactive_workspace_border, *inactive_workspace_bg, *inactive_workspace_text; | ||
198 | json_object *active_workspace_border, *active_workspace_bg, *active_workspace_text; | ||
199 | json_object *urgent_workspace_border, *urgent_workspace_bg, *urgent_workspace_text; | ||
200 | json_object *binding_mode_border, *binding_mode_bg, *binding_mode_text; | ||
201 | json_object_object_get_ex(_colors, "background", &background); | ||
202 | json_object_object_get_ex(_colors, "statusline", &statusline); | ||
203 | json_object_object_get_ex(_colors, "separator", &separator); | ||
204 | json_object_object_get_ex(_colors, "focused_workspace_border", &focused_workspace_border); | ||
205 | json_object_object_get_ex(_colors, "focused_workspace_bg", &focused_workspace_bg); | ||
206 | json_object_object_get_ex(_colors, "focused_workspace_text", &focused_workspace_text); | ||
207 | json_object_object_get_ex(_colors, "active_workspace_border", &active_workspace_border); | ||
208 | json_object_object_get_ex(_colors, "active_workspace_bg", &active_workspace_bg); | ||
209 | json_object_object_get_ex(_colors, "active_workspace_text", &active_workspace_text); | ||
210 | json_object_object_get_ex(_colors, "inactive_workspace_border", &inactive_workspace_border); | ||
211 | json_object_object_get_ex(_colors, "inactive_workspace_bg", &inactive_workspace_bg); | ||
212 | json_object_object_get_ex(_colors, "inactive_workspace_text", &inactive_workspace_text); | ||
213 | json_object_object_get_ex(_colors, "urgent_workspace_border", &urgent_workspace_border); | ||
214 | json_object_object_get_ex(_colors, "urgent_workspace_bg", &urgent_workspace_bg); | ||
215 | json_object_object_get_ex(_colors, "urgent_workspace_text", &urgent_workspace_text); | ||
216 | json_object_object_get_ex(_colors, "binding_mode_border", &binding_mode_border); | ||
217 | json_object_object_get_ex(_colors, "binding_mode_bg", &binding_mode_bg); | ||
218 | json_object_object_get_ex(_colors, "binding_mode_text", &binding_mode_text); | ||
219 | if (background) colors.background = parse_color(json_object_get_string(background)); | ||
220 | if (statusline) colors.statusline = parse_color(json_object_get_string(statusline)); | ||
221 | if (separator) colors.seperator = parse_color(json_object_get_string(separator)); | ||
222 | if (focused_workspace_border) | ||
223 | colors.focused_workspace.border = parse_color(json_object_get_string(focused_workspace_border)); | ||
224 | if (focused_workspace_bg) | ||
225 | colors.focused_workspace.background = parse_color(json_object_get_string(focused_workspace_bg)); | ||
226 | if (focused_workspace_text) | ||
227 | colors.focused_workspace.text = parse_color(json_object_get_string(focused_workspace_text)); | ||
228 | if (active_workspace_border) | ||
229 | colors.active_workspace.border = parse_color(json_object_get_string(active_workspace_border)); | ||
230 | if (active_workspace_bg) | ||
231 | colors.active_workspace.background = parse_color(json_object_get_string(active_workspace_bg)); | ||
232 | if (active_workspace_text) | ||
233 | colors.active_workspace.text = parse_color(json_object_get_string(active_workspace_text)); | ||
234 | if (inactive_workspace_border) | ||
235 | colors.inactive_workspace.border = parse_color(json_object_get_string(inactive_workspace_border)); | ||
236 | if (inactive_workspace_bg) | ||
237 | colors.inactive_workspace.background = parse_color(json_object_get_string(inactive_workspace_bg)); | ||
238 | if (inactive_workspace_text) | ||
239 | colors.inactive_workspace.text = parse_color(json_object_get_string(inactive_workspace_text)); | ||
240 | if (binding_mode_border) | ||
241 | colors.binding_mode.border = parse_color(json_object_get_string(binding_mode_border)); | ||
242 | if (binding_mode_bg) | ||
243 | colors.binding_mode.background = parse_color(json_object_get_string(binding_mode_bg)); | ||
244 | if (binding_mode_text) | ||
245 | colors.binding_mode.text = parse_color(json_object_get_string(binding_mode_text)); | ||
246 | } | ||
247 | |||
178 | json_object_put(bar_config); | 248 | json_object_put(bar_config); |
179 | free(res); | 249 | free(res); |
180 | 250 | ||