diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-29 17:41:02 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-03-29 22:11:08 -0400 |
commit | 569b2bfd5daae5b3be49772bdca4a3f224e20629 (patch) | |
tree | 56e1d9e37cc5ffdca34d2f86a0e297cd06ffaf83 | |
parent | Add bar configuration commands (diff) | |
download | sway-569b2bfd5daae5b3be49772bdca4a3f224e20629.tar.gz sway-569b2bfd5daae5b3be49772bdca4a3f224e20629.tar.zst sway-569b2bfd5daae5b3be49772bdca4a3f224e20629.zip |
Move bar config into its own file
-rw-r--r-- | include/sway/config.h | 26 | ||||
-rw-r--r-- | sway/config.c | 127 | ||||
-rw-r--r-- | sway/config/bar.c | 143 | ||||
-rw-r--r-- | sway/config/output.c | 2 | ||||
-rw-r--r-- | sway/meson.build | 1 |
5 files changed, 151 insertions, 148 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index f9ab6778..dbcfc91e 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -12,6 +12,8 @@ | |||
12 | #include "container.h" | 12 | #include "container.h" |
13 | #include "wlr-layer-shell-unstable-v1-protocol.h" | 13 | #include "wlr-layer-shell-unstable-v1-protocol.h" |
14 | 14 | ||
15 | // TODO: Refactor this shit | ||
16 | |||
15 | /** | 17 | /** |
16 | * Describes a variable created via the `set` command. | 18 | * Describes a variable created via the `set` command. |
17 | */ | 19 | */ |
@@ -407,11 +409,6 @@ void merge_output_config(struct output_config *dst, struct output_config *src); | |||
407 | void apply_output_config(struct output_config *oc, swayc_t *output); | 409 | void apply_output_config(struct output_config *oc, swayc_t *output); |
408 | void free_output_config(struct output_config *oc); | 410 | void free_output_config(struct output_config *oc); |
409 | 411 | ||
410 | /** | ||
411 | * Updates the list of active bar modifiers | ||
412 | */ | ||
413 | void update_active_bar_modifiers(void); | ||
414 | |||
415 | int workspace_output_cmp_workspace(const void *a, const void *b); | 412 | int workspace_output_cmp_workspace(const void *a, const void *b); |
416 | 413 | ||
417 | int sway_binding_cmp(const void *a, const void *b); | 414 | int sway_binding_cmp(const void *a, const void *b); |
@@ -420,27 +417,16 @@ int sway_binding_cmp_keys(const void *a, const void *b); | |||
420 | void free_sway_binding(struct sway_binding *sb); | 417 | void free_sway_binding(struct sway_binding *sb); |
421 | struct sway_binding *sway_binding_dup(struct sway_binding *sb); | 418 | struct sway_binding *sway_binding_dup(struct sway_binding *sb); |
422 | 419 | ||
423 | int sway_mouse_binding_cmp(const void *a, const void *b); | 420 | /* Bar stuff */ |
424 | int sway_mouse_binding_cmp_qsort(const void *a, const void *b); | ||
425 | int sway_mouse_binding_cmp_buttons(const void *a, const void *b); | ||
426 | void free_sway_mouse_binding(struct sway_mouse_binding *smb); | ||
427 | |||
428 | void load_swaybars(); | 421 | void load_swaybars(); |
429 | void terminate_swaybg(pid_t pid); | 422 | void terminate_swaybg(pid_t pid); |
430 | |||
431 | /** | ||
432 | * Allocate and initialize default bar configuration. | ||
433 | */ | ||
434 | struct bar_config *default_bar_config(void); | 423 | struct bar_config *default_bar_config(void); |
424 | void free_bar_config(struct bar_config *bar); | ||
435 | 425 | ||
436 | /** | 426 | /* Global config singleton. */ |
437 | * Global config singleton. | ||
438 | */ | ||
439 | extern struct sway_config *config; | 427 | extern struct sway_config *config; |
440 | 428 | ||
441 | /** | 429 | /* Config file currently being read */ |
442 | * Config file currently being read. | ||
443 | */ | ||
444 | extern const char *current_config_path; | 430 | extern const char *current_config_path; |
445 | 431 | ||
446 | #endif | 432 | #endif |
diff --git a/sway/config.c b/sway/config.c index a0e408de..0422fdd9 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -110,48 +110,6 @@ void free_config(struct sway_config *config) { | |||
110 | free(config); | 110 | free(config); |
111 | } | 111 | } |
112 | 112 | ||
113 | static void free_bar(struct bar_config *bar) { | ||
114 | if (!bar) { | ||
115 | return; | ||
116 | } | ||
117 | free(bar->mode); | ||
118 | free(bar->position); | ||
119 | free(bar->hidden_state); | ||
120 | free(bar->status_command); | ||
121 | free(bar->font); | ||
122 | free(bar->separator_symbol); | ||
123 | // TODO: Free mouse bindings | ||
124 | list_free(bar->bindings); | ||
125 | if (bar->outputs) { | ||
126 | free_flat_list(bar->outputs); | ||
127 | } | ||
128 | if (bar->pid != 0) { | ||
129 | // TODO terminate_swaybar(bar->pid); | ||
130 | } | ||
131 | free(bar->colors.background); | ||
132 | free(bar->colors.statusline); | ||
133 | free(bar->colors.separator); | ||
134 | free(bar->colors.focused_background); | ||
135 | free(bar->colors.focused_statusline); | ||
136 | free(bar->colors.focused_separator); | ||
137 | free(bar->colors.focused_workspace_border); | ||
138 | free(bar->colors.focused_workspace_bg); | ||
139 | free(bar->colors.focused_workspace_text); | ||
140 | free(bar->colors.active_workspace_border); | ||
141 | free(bar->colors.active_workspace_bg); | ||
142 | free(bar->colors.active_workspace_text); | ||
143 | free(bar->colors.inactive_workspace_border); | ||
144 | free(bar->colors.inactive_workspace_bg); | ||
145 | free(bar->colors.inactive_workspace_text); | ||
146 | free(bar->colors.urgent_workspace_border); | ||
147 | free(bar->colors.urgent_workspace_bg); | ||
148 | free(bar->colors.urgent_workspace_text); | ||
149 | free(bar->colors.binding_mode_border); | ||
150 | free(bar->colors.binding_mode_bg); | ||
151 | free(bar->colors.binding_mode_text); | ||
152 | free(bar); | ||
153 | } | ||
154 | |||
155 | static void destroy_removed_seats(struct sway_config *old_config, | 113 | static void destroy_removed_seats(struct sway_config *old_config, |
156 | struct sway_config *new_config) { | 114 | struct sway_config *new_config) { |
157 | struct seat_config *seat_config; | 115 | struct seat_config *seat_config; |
@@ -281,91 +239,6 @@ cleanup: | |||
281 | sway_abort("Unable to allocate config structures"); | 239 | sway_abort("Unable to allocate config structures"); |
282 | } | 240 | } |
283 | 241 | ||
284 | struct bar_config *default_bar_config(void) { | ||
285 | struct bar_config *bar = NULL; | ||
286 | bar = malloc(sizeof(struct bar_config)); | ||
287 | if (!bar) { | ||
288 | return NULL; | ||
289 | } | ||
290 | if (!(bar->mode = strdup("dock"))) goto cleanup; | ||
291 | if (!(bar->hidden_state = strdup("hide"))) goto cleanup; | ||
292 | bar->outputs = NULL; | ||
293 | bar->position = strdup("bottom"); | ||
294 | if (!(bar->bindings = create_list())) goto cleanup; | ||
295 | if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup; | ||
296 | bar->pango_markup = false; | ||
297 | bar->swaybar_command = NULL; | ||
298 | bar->font = NULL; | ||
299 | bar->height = -1; | ||
300 | bar->workspace_buttons = true; | ||
301 | bar->wrap_scroll = false; | ||
302 | bar->separator_symbol = NULL; | ||
303 | bar->strip_workspace_numbers = false; | ||
304 | bar->binding_mode_indicator = true; | ||
305 | bar->verbose = false; | ||
306 | bar->pid = 0; | ||
307 | // set default colors | ||
308 | if (!(bar->colors.background = strndup("#000000ff", 9))) { | ||
309 | goto cleanup; | ||
310 | } | ||
311 | if (!(bar->colors.statusline = strndup("#ffffffff", 9))) { | ||
312 | goto cleanup; | ||
313 | } | ||
314 | if (!(bar->colors.separator = strndup("#666666ff", 9))) { | ||
315 | goto cleanup; | ||
316 | } | ||
317 | if (!(bar->colors.focused_workspace_border = strndup("#4c7899ff", 9))) { | ||
318 | goto cleanup; | ||
319 | } | ||
320 | if (!(bar->colors.focused_workspace_bg = strndup("#285577ff", 9))) { | ||
321 | goto cleanup; | ||
322 | } | ||
323 | if (!(bar->colors.focused_workspace_text = strndup("#ffffffff", 9))) { | ||
324 | goto cleanup; | ||
325 | } | ||
326 | if (!(bar->colors.active_workspace_border = strndup("#333333ff", 9))) { | ||
327 | goto cleanup; | ||
328 | } | ||
329 | if (!(bar->colors.active_workspace_bg = strndup("#5f676aff", 9))) { | ||
330 | goto cleanup; | ||
331 | } | ||
332 | if (!(bar->colors.active_workspace_text = strndup("#ffffffff", 9))) { | ||
333 | goto cleanup; | ||
334 | } | ||
335 | if (!(bar->colors.inactive_workspace_border = strndup("#333333ff", 9))) { | ||
336 | goto cleanup; | ||
337 | } | ||
338 | if (!(bar->colors.inactive_workspace_bg = strndup("#222222ff", 9))) { | ||
339 | goto cleanup; | ||
340 | } | ||
341 | if (!(bar->colors.inactive_workspace_text = strndup("#888888ff", 9))) { | ||
342 | goto cleanup; | ||
343 | } | ||
344 | if (!(bar->colors.urgent_workspace_border = strndup("#2f343aff", 9))) { | ||
345 | goto cleanup; | ||
346 | } | ||
347 | if (!(bar->colors.urgent_workspace_bg = strndup("#900000ff", 9))) { | ||
348 | goto cleanup; | ||
349 | } | ||
350 | if (!(bar->colors.urgent_workspace_text = strndup("#ffffffff", 9))) { | ||
351 | goto cleanup; | ||
352 | } | ||
353 | // if the following colors stay undefined, they fall back to background, | ||
354 | // statusline, separator and urgent_workspace_*. | ||
355 | bar->colors.focused_background = NULL; | ||
356 | bar->colors.focused_statusline = NULL; | ||
357 | bar->colors.focused_separator = NULL; | ||
358 | bar->colors.binding_mode_border = NULL; | ||
359 | bar->colors.binding_mode_bg = NULL; | ||
360 | bar->colors.binding_mode_text = NULL; | ||
361 | |||
362 | list_add(config->bars, bar); | ||
363 | return bar; | ||
364 | cleanup: | ||
365 | free_bar(bar); | ||
366 | return NULL; | ||
367 | } | ||
368 | |||
369 | static bool file_exists(const char *path) { | 242 | static bool file_exists(const char *path) { |
370 | return path && access(path, R_OK) != -1; | 243 | return path && access(path, R_OK) != -1; |
371 | } | 244 | } |
diff --git a/sway/config/bar.c b/sway/config/bar.c new file mode 100644 index 00000000..ecc357d0 --- /dev/null +++ b/sway/config/bar.c | |||
@@ -0,0 +1,143 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #define _XOPEN_SOURCE 700 | ||
3 | #include <stdio.h> | ||
4 | #include <stdbool.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <unistd.h> | ||
7 | #include <wordexp.h> | ||
8 | #include <sys/types.h> | ||
9 | #include <sys/wait.h> | ||
10 | #include <sys/stat.h> | ||
11 | #include <signal.h> | ||
12 | #include <strings.h> | ||
13 | #include "sway/config.h" | ||
14 | #include "stringop.h" | ||
15 | #include "list.h" | ||
16 | #include "log.h" | ||
17 | |||
18 | void free_bar_config(struct bar_config *bar) { | ||
19 | if (!bar) { | ||
20 | return; | ||
21 | } | ||
22 | free(bar->mode); | ||
23 | free(bar->position); | ||
24 | free(bar->hidden_state); | ||
25 | free(bar->status_command); | ||
26 | free(bar->font); | ||
27 | free(bar->separator_symbol); | ||
28 | // TODO: Free mouse bindings | ||
29 | list_free(bar->bindings); | ||
30 | if (bar->outputs) { | ||
31 | free_flat_list(bar->outputs); | ||
32 | } | ||
33 | if (bar->pid != 0) { | ||
34 | // TODO terminate_swaybar(bar->pid); | ||
35 | } | ||
36 | free(bar->colors.background); | ||
37 | free(bar->colors.statusline); | ||
38 | free(bar->colors.separator); | ||
39 | free(bar->colors.focused_background); | ||
40 | free(bar->colors.focused_statusline); | ||
41 | free(bar->colors.focused_separator); | ||
42 | free(bar->colors.focused_workspace_border); | ||
43 | free(bar->colors.focused_workspace_bg); | ||
44 | free(bar->colors.focused_workspace_text); | ||
45 | free(bar->colors.active_workspace_border); | ||
46 | free(bar->colors.active_workspace_bg); | ||
47 | free(bar->colors.active_workspace_text); | ||
48 | free(bar->colors.inactive_workspace_border); | ||
49 | free(bar->colors.inactive_workspace_bg); | ||
50 | free(bar->colors.inactive_workspace_text); | ||
51 | free(bar->colors.urgent_workspace_border); | ||
52 | free(bar->colors.urgent_workspace_bg); | ||
53 | free(bar->colors.urgent_workspace_text); | ||
54 | free(bar->colors.binding_mode_border); | ||
55 | free(bar->colors.binding_mode_bg); | ||
56 | free(bar->colors.binding_mode_text); | ||
57 | free(bar); | ||
58 | } | ||
59 | |||
60 | struct bar_config *default_bar_config(void) { | ||
61 | struct bar_config *bar = NULL; | ||
62 | bar = malloc(sizeof(struct bar_config)); | ||
63 | if (!bar) { | ||
64 | return NULL; | ||
65 | } | ||
66 | if (!(bar->mode = strdup("dock"))) goto cleanup; | ||
67 | if (!(bar->hidden_state = strdup("hide"))) goto cleanup; | ||
68 | bar->outputs = NULL; | ||
69 | bar->position = strdup("bottom"); | ||
70 | if (!(bar->bindings = create_list())) goto cleanup; | ||
71 | if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup; | ||
72 | bar->pango_markup = false; | ||
73 | bar->swaybar_command = NULL; | ||
74 | bar->font = NULL; | ||
75 | bar->height = -1; | ||
76 | bar->workspace_buttons = true; | ||
77 | bar->wrap_scroll = false; | ||
78 | bar->separator_symbol = NULL; | ||
79 | bar->strip_workspace_numbers = false; | ||
80 | bar->binding_mode_indicator = true; | ||
81 | bar->verbose = false; | ||
82 | bar->pid = 0; | ||
83 | // set default colors | ||
84 | if (!(bar->colors.background = strndup("#000000ff", 9))) { | ||
85 | goto cleanup; | ||
86 | } | ||
87 | if (!(bar->colors.statusline = strndup("#ffffffff", 9))) { | ||
88 | goto cleanup; | ||
89 | } | ||
90 | if (!(bar->colors.separator = strndup("#666666ff", 9))) { | ||
91 | goto cleanup; | ||
92 | } | ||
93 | if (!(bar->colors.focused_workspace_border = strndup("#4c7899ff", 9))) { | ||
94 | goto cleanup; | ||
95 | } | ||
96 | if (!(bar->colors.focused_workspace_bg = strndup("#285577ff", 9))) { | ||
97 | goto cleanup; | ||
98 | } | ||
99 | if (!(bar->colors.focused_workspace_text = strndup("#ffffffff", 9))) { | ||
100 | goto cleanup; | ||
101 | } | ||
102 | if (!(bar->colors.active_workspace_border = strndup("#333333ff", 9))) { | ||
103 | goto cleanup; | ||
104 | } | ||
105 | if (!(bar->colors.active_workspace_bg = strndup("#5f676aff", 9))) { | ||
106 | goto cleanup; | ||
107 | } | ||
108 | if (!(bar->colors.active_workspace_text = strndup("#ffffffff", 9))) { | ||
109 | goto cleanup; | ||
110 | } | ||
111 | if (!(bar->colors.inactive_workspace_border = strndup("#333333ff", 9))) { | ||
112 | goto cleanup; | ||
113 | } | ||
114 | if (!(bar->colors.inactive_workspace_bg = strndup("#222222ff", 9))) { | ||
115 | goto cleanup; | ||
116 | } | ||
117 | if (!(bar->colors.inactive_workspace_text = strndup("#888888ff", 9))) { | ||
118 | goto cleanup; | ||
119 | } | ||
120 | if (!(bar->colors.urgent_workspace_border = strndup("#2f343aff", 9))) { | ||
121 | goto cleanup; | ||
122 | } | ||
123 | if (!(bar->colors.urgent_workspace_bg = strndup("#900000ff", 9))) { | ||
124 | goto cleanup; | ||
125 | } | ||
126 | if (!(bar->colors.urgent_workspace_text = strndup("#ffffffff", 9))) { | ||
127 | goto cleanup; | ||
128 | } | ||
129 | // if the following colors stay undefined, they fall back to background, | ||
130 | // statusline, separator and urgent_workspace_*. | ||
131 | bar->colors.focused_background = NULL; | ||
132 | bar->colors.focused_statusline = NULL; | ||
133 | bar->colors.focused_separator = NULL; | ||
134 | bar->colors.binding_mode_border = NULL; | ||
135 | bar->colors.binding_mode_bg = NULL; | ||
136 | bar->colors.binding_mode_text = NULL; | ||
137 | |||
138 | list_add(config->bars, bar); | ||
139 | return bar; | ||
140 | cleanup: | ||
141 | free_bar_config(bar); | ||
142 | return NULL; | ||
143 | } | ||
diff --git a/sway/config/output.c b/sway/config/output.c index 9e211861..24b4a18e 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -186,7 +186,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { | |||
186 | output_id[bufsize-1] = 0; | 186 | output_id[bufsize-1] = 0; |
187 | 187 | ||
188 | char *const cmd[] = { | 188 | char *const cmd[] = { |
189 | "./swaybg/swaybg", | 189 | "swaybg", |
190 | output_id, | 190 | output_id, |
191 | oc->background, | 191 | oc->background, |
192 | oc->background_option, | 192 | oc->background_option, |
diff --git a/sway/meson.build b/sway/meson.build index 8fcb0dbf..ac65d05e 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -64,6 +64,7 @@ sway_sources = files( | |||
64 | 'commands/reload.c', | 64 | 'commands/reload.c', |
65 | 'commands/workspace.c', | 65 | 'commands/workspace.c', |
66 | 'config.c', | 66 | 'config.c', |
67 | 'config/bar.c', | ||
67 | 'config/output.c', | 68 | 'config/output.c', |
68 | 'config/seat.c', | 69 | 'config/seat.c', |
69 | 'config/input.c', | 70 | 'config/input.c', |