diff options
Diffstat (limited to 'sway/config')
-rw-r--r-- | sway/config/bar.c | 22 | ||||
-rw-r--r-- | sway/config/input.c | 2 | ||||
-rw-r--r-- | sway/config/output.c | 114 | ||||
-rw-r--r-- | sway/config/seat.c | 64 |
4 files changed, 147 insertions, 55 deletions
diff --git a/sway/config/bar.c b/sway/config/bar.c index 7bca5f49..701bf051 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c | |||
@@ -1,5 +1,4 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #define _XOPEN_SOURCE 700 | ||
3 | #include <stdio.h> | 2 | #include <stdio.h> |
4 | #include <stdbool.h> | 3 | #include <stdbool.h> |
5 | #include <stdlib.h> | 4 | #include <stdlib.h> |
@@ -13,6 +12,7 @@ | |||
13 | #include <signal.h> | 12 | #include <signal.h> |
14 | #include "sway/config.h" | 13 | #include "sway/config.h" |
15 | #include "sway/output.h" | 14 | #include "sway/output.h" |
15 | #include "config.h" | ||
16 | #include "stringop.h" | 16 | #include "stringop.h" |
17 | #include "list.h" | 17 | #include "list.h" |
18 | #include "log.h" | 18 | #include "log.h" |
@@ -50,13 +50,10 @@ void free_bar_config(struct bar_config *bar) { | |||
50 | free(bar->font); | 50 | free(bar->font); |
51 | free(bar->separator_symbol); | 51 | free(bar->separator_symbol); |
52 | for (int i = 0; i < bar->bindings->length; i++) { | 52 | for (int i = 0; i < bar->bindings->length; i++) { |
53 | struct bar_binding *binding = bar->bindings->items[i]; | 53 | free_bar_binding(bar->bindings->items[i]); |
54 | free_bar_binding(binding); | ||
55 | } | 54 | } |
56 | list_free(bar->bindings); | 55 | list_free(bar->bindings); |
57 | if (bar->outputs) { | 56 | list_free_items_and_destroy(bar->outputs); |
58 | free_flat_list(bar->outputs); | ||
59 | } | ||
60 | if (bar->pid != 0) { | 57 | if (bar->pid != 0) { |
61 | terminate_swaybar(bar->pid); | 58 | terminate_swaybar(bar->pid); |
62 | } | 59 | } |
@@ -81,6 +78,10 @@ void free_bar_config(struct bar_config *bar) { | |||
81 | free(bar->colors.binding_mode_border); | 78 | free(bar->colors.binding_mode_border); |
82 | free(bar->colors.binding_mode_bg); | 79 | free(bar->colors.binding_mode_bg); |
83 | free(bar->colors.binding_mode_text); | 80 | free(bar->colors.binding_mode_text); |
81 | #if HAVE_TRAY | ||
82 | list_free_items_and_destroy(bar->tray_outputs); | ||
83 | free(bar->icon_theme); | ||
84 | #endif | ||
84 | free(bar); | 85 | free(bar); |
85 | } | 86 | } |
86 | 87 | ||
@@ -95,15 +96,18 @@ struct bar_config *default_bar_config(void) { | |||
95 | bar->pango_markup = false; | 96 | bar->pango_markup = false; |
96 | bar->swaybar_command = NULL; | 97 | bar->swaybar_command = NULL; |
97 | bar->font = NULL; | 98 | bar->font = NULL; |
98 | bar->height = -1; | 99 | bar->height = 0; |
99 | bar->workspace_buttons = true; | 100 | bar->workspace_buttons = true; |
100 | bar->wrap_scroll = false; | 101 | bar->wrap_scroll = false; |
101 | bar->separator_symbol = NULL; | 102 | bar->separator_symbol = NULL; |
102 | bar->strip_workspace_numbers = false; | 103 | bar->strip_workspace_numbers = false; |
104 | bar->strip_workspace_name = false; | ||
103 | bar->binding_mode_indicator = true; | 105 | bar->binding_mode_indicator = true; |
104 | bar->verbose = false; | 106 | bar->verbose = false; |
105 | bar->pid = 0; | 107 | bar->pid = 0; |
106 | bar->modifier = get_modifier_mask_by_name("Mod4"); | 108 | bar->modifier = get_modifier_mask_by_name("Mod4"); |
109 | bar->status_padding = 1; | ||
110 | bar->status_edge_padding = 3; | ||
107 | if (!(bar->mode = strdup("dock"))) { | 111 | if (!(bar->mode = strdup("dock"))) { |
108 | goto cleanup; | 112 | goto cleanup; |
109 | } | 113 | } |
@@ -168,6 +172,10 @@ struct bar_config *default_bar_config(void) { | |||
168 | bar->colors.binding_mode_bg = NULL; | 172 | bar->colors.binding_mode_bg = NULL; |
169 | bar->colors.binding_mode_text = NULL; | 173 | bar->colors.binding_mode_text = NULL; |
170 | 174 | ||
175 | #if HAVE_TRAY | ||
176 | bar->tray_padding = 2; | ||
177 | #endif | ||
178 | |||
171 | list_add(config->bars, bar); | 179 | list_add(config->bars, bar); |
172 | return bar; | 180 | return bar; |
173 | cleanup: | 181 | cleanup: |
diff --git a/sway/config/input.c b/sway/config/input.c index d5d2d90b..d649d34d 100644 --- a/sway/config/input.c +++ b/sway/config/input.c | |||
@@ -1,4 +1,4 @@ | |||
1 | #define _XOPEN_SOURCE 700 | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <limits.h> | 3 | #include <limits.h> |
4 | #include <float.h> | 4 | #include <float.h> |
diff --git a/sway/config/output.c b/sway/config/output.c index 07543e3c..f24e7d66 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -1,4 +1,4 @@ | |||
1 | #define _XOPEN_SOURCE 700 | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <assert.h> | 2 | #include <assert.h> |
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | #include <string.h> | 4 | #include <string.h> |
@@ -179,10 +179,6 @@ void apply_output_config(struct output_config *oc, struct sway_output *output) { | |||
179 | 179 | ||
180 | if (oc && oc->enabled == 0) { | 180 | if (oc && oc->enabled == 0) { |
181 | if (output->enabled) { | 181 | if (output->enabled) { |
182 | if (output->bg_pid != 0) { | ||
183 | terminate_swaybg(output->bg_pid); | ||
184 | output->bg_pid = 0; | ||
185 | } | ||
186 | output_disable(output); | 182 | output_disable(output); |
187 | wlr_output_layout_remove(root->output_layout, wlr_output); | 183 | wlr_output_layout_remove(root->output_layout, wlr_output); |
188 | } | 184 | } |
@@ -276,18 +272,86 @@ void apply_output_config(struct output_config *oc, struct sway_output *output) { | |||
276 | } | 272 | } |
277 | } | 273 | } |
278 | 274 | ||
279 | static struct output_config *get_output_config(char *name, char *identifier) { | 275 | static void default_output_config(struct output_config *oc, |
276 | struct wlr_output *wlr_output) { | ||
277 | oc->enabled = 1; | ||
278 | if (!wl_list_empty(&wlr_output->modes)) { | ||
279 | struct wlr_output_mode *mode = | ||
280 | wl_container_of(wlr_output->modes.prev, mode, link); | ||
281 | oc->width = mode->width; | ||
282 | oc->height = mode->height; | ||
283 | oc->refresh_rate = mode->refresh; | ||
284 | } | ||
285 | oc->x = oc->y = -1; | ||
286 | oc->scale = 1; | ||
287 | oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; | ||
288 | } | ||
289 | |||
290 | static struct output_config *get_output_config(char *identifier, | ||
291 | struct sway_output *sway_output) { | ||
292 | const char *name = sway_output->wlr_output->name; | ||
293 | struct output_config *oc_name = NULL; | ||
280 | int i = list_seq_find(config->output_configs, output_name_cmp, name); | 294 | int i = list_seq_find(config->output_configs, output_name_cmp, name); |
281 | if (i >= 0) { | 295 | if (i >= 0) { |
282 | return config->output_configs->items[i]; | 296 | oc_name = config->output_configs->items[i]; |
283 | } | 297 | } |
284 | 298 | ||
299 | struct output_config *oc_id = NULL; | ||
285 | i = list_seq_find(config->output_configs, output_name_cmp, identifier); | 300 | i = list_seq_find(config->output_configs, output_name_cmp, identifier); |
286 | if (i >= 0) { | 301 | if (i >= 0) { |
287 | return config->output_configs->items[i]; | 302 | oc_id = config->output_configs->items[i]; |
303 | } | ||
304 | |||
305 | struct output_config *result = result = new_output_config("temp"); | ||
306 | if (config->reloading) { | ||
307 | default_output_config(result, sway_output->wlr_output); | ||
308 | } | ||
309 | if (oc_name && oc_id) { | ||
310 | // Generate a config named `<identifier> on <name>` which contains a | ||
311 | // merged copy of the identifier on name. This will make sure that both | ||
312 | // identifier and name configs are respected, with identifier getting | ||
313 | // priority | ||
314 | size_t length = snprintf(NULL, 0, "%s on %s", identifier, name) + 1; | ||
315 | char *temp = malloc(length); | ||
316 | snprintf(temp, length, "%s on %s", identifier, name); | ||
317 | |||
318 | free(result->name); | ||
319 | result->name = temp; | ||
320 | merge_output_config(result, oc_name); | ||
321 | merge_output_config(result, oc_id); | ||
322 | |||
323 | wlr_log(WLR_DEBUG, "Generated output config \"%s\" (enabled: %d)" | ||
324 | " (%dx%d@%fHz position %d,%d scale %f transform %d) (bg %s %s)" | ||
325 | " (dpms %d)", result->name, result->enabled, result->width, | ||
326 | result->height, result->refresh_rate, result->x, result->y, | ||
327 | result->scale, result->transform, result->background, | ||
328 | result->background_option, result->dpms_state); | ||
329 | } else if (oc_name) { | ||
330 | // No identifier config, just return a copy of the name config | ||
331 | free(result->name); | ||
332 | result->name = strdup(name); | ||
333 | merge_output_config(result, oc_name); | ||
334 | } else if (oc_id) { | ||
335 | // No name config, just return a copy of the identifier config | ||
336 | free(result->name); | ||
337 | result->name = strdup(identifier); | ||
338 | merge_output_config(result, oc_id); | ||
339 | } else if (config->reloading) { | ||
340 | // Neither config exists, but we need to reset the output so create a | ||
341 | // default config for the output and if a wildcard config exists, merge | ||
342 | // that on top | ||
343 | free(result->name); | ||
344 | result->name = strdup("*"); | ||
345 | i = list_seq_find(config->output_configs, output_name_cmp, "*"); | ||
346 | if (i >= 0) { | ||
347 | merge_output_config(result, config->output_configs->items[i]); | ||
348 | } | ||
349 | } else { | ||
350 | free_output_config(result); | ||
351 | result = NULL; | ||
288 | } | 352 | } |
289 | 353 | ||
290 | return NULL; | 354 | return result; |
291 | } | 355 | } |
292 | 356 | ||
293 | void apply_output_config_to_outputs(struct output_config *oc) { | 357 | void apply_output_config_to_outputs(struct output_config *oc) { |
@@ -301,14 +365,17 @@ void apply_output_config_to_outputs(struct output_config *oc) { | |||
301 | char *name = sway_output->wlr_output->name; | 365 | char *name = sway_output->wlr_output->name; |
302 | output_get_identifier(id, sizeof(id), sway_output); | 366 | output_get_identifier(id, sizeof(id), sway_output); |
303 | if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) { | 367 | if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) { |
304 | struct output_config *current = oc; | 368 | struct output_config *current = new_output_config(oc->name); |
369 | merge_output_config(current, oc); | ||
305 | if (wildcard) { | 370 | if (wildcard) { |
306 | struct output_config *tmp = get_output_config(name, id); | 371 | struct output_config *tmp = get_output_config(id, sway_output); |
307 | if (tmp) { | 372 | if (tmp) { |
373 | free_output_config(current); | ||
308 | current = tmp; | 374 | current = tmp; |
309 | } | 375 | } |
310 | } | 376 | } |
311 | apply_output_config(current, sway_output); | 377 | apply_output_config(current, sway_output); |
378 | free_output_config(current); | ||
312 | 379 | ||
313 | if (!wildcard) { | 380 | if (!wildcard) { |
314 | // Stop looking if the output config isn't applicable to all | 381 | // Stop looking if the output config isn't applicable to all |
@@ -329,28 +396,3 @@ void free_output_config(struct output_config *oc) { | |||
329 | free(oc->background_fallback); | 396 | free(oc->background_fallback); |
330 | free(oc); | 397 | free(oc); |
331 | } | 398 | } |
332 | |||
333 | static void default_output_config(struct output_config *oc, | ||
334 | struct wlr_output *wlr_output) { | ||
335 | oc->enabled = 1; | ||
336 | if (!wl_list_empty(&wlr_output->modes)) { | ||
337 | struct wlr_output_mode *mode = | ||
338 | wl_container_of(wlr_output->modes.prev, mode, link); | ||
339 | oc->width = mode->width; | ||
340 | oc->height = mode->height; | ||
341 | oc->refresh_rate = mode->refresh; | ||
342 | } | ||
343 | oc->x = oc->y = -1; | ||
344 | oc->scale = 1; | ||
345 | oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; | ||
346 | } | ||
347 | |||
348 | void create_default_output_configs(void) { | ||
349 | struct sway_output *sway_output; | ||
350 | wl_list_for_each(sway_output, &root->all_outputs, link) { | ||
351 | char *name = sway_output->wlr_output->name; | ||
352 | struct output_config *oc = new_output_config(name); | ||
353 | default_output_config(oc, sway_output->wlr_output); | ||
354 | list_add(config->output_configs, oc); | ||
355 | } | ||
356 | } | ||
diff --git a/sway/config/seat.c b/sway/config/seat.c index 46456caf..d7316c68 100644 --- a/sway/config/seat.c +++ b/sway/config/seat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | #define _XOPEN_SOURCE 700 | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include "sway/config.h" | 4 | #include "sway/config.h" |
@@ -11,7 +11,6 @@ struct seat_config *new_seat_config(const char* name) { | |||
11 | return NULL; | 11 | return NULL; |
12 | } | 12 | } |
13 | 13 | ||
14 | wlr_log(WLR_DEBUG, "new_seat_config(%s)", name); | ||
15 | seat->name = strdup(name); | 14 | seat->name = strdup(name); |
16 | if (!sway_assert(seat->name, "could not allocate name for seat")) { | 15 | if (!sway_assert(seat->name, "could not allocate name for seat")) { |
17 | free(seat); | 16 | free(seat); |
@@ -26,10 +25,57 @@ struct seat_config *new_seat_config(const char* name) { | |||
26 | free(seat); | 25 | free(seat); |
27 | return NULL; | 26 | return NULL; |
28 | } | 27 | } |
28 | seat->hide_cursor_timeout = -1; | ||
29 | 29 | ||
30 | return seat; | 30 | return seat; |
31 | } | 31 | } |
32 | 32 | ||
33 | static void merge_wildcard_on_all(struct seat_config *wildcard) { | ||
34 | for (int i = 0; i < config->seat_configs->length; i++) { | ||
35 | struct seat_config *sc = config->seat_configs->items[i]; | ||
36 | if (strcmp(wildcard->name, sc->name) != 0) { | ||
37 | wlr_log(WLR_DEBUG, "Merging seat * config on %s", sc->name); | ||
38 | merge_seat_config(sc, wildcard); | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | |||
43 | struct seat_config *store_seat_config(struct seat_config *sc) { | ||
44 | bool wildcard = strcmp(sc->name, "*") == 0; | ||
45 | if (wildcard) { | ||
46 | merge_wildcard_on_all(sc); | ||
47 | } | ||
48 | |||
49 | int i = list_seq_find(config->seat_configs, seat_name_cmp, sc->name); | ||
50 | if (i >= 0) { | ||
51 | wlr_log(WLR_DEBUG, "Merging on top of existing seat config"); | ||
52 | struct seat_config *current = config->seat_configs->items[i]; | ||
53 | merge_seat_config(current, sc); | ||
54 | free_seat_config(sc); | ||
55 | sc = current; | ||
56 | } else if (!wildcard) { | ||
57 | wlr_log(WLR_DEBUG, "Adding non-wildcard seat config"); | ||
58 | i = list_seq_find(config->seat_configs, seat_name_cmp, "*"); | ||
59 | if (i >= 0) { | ||
60 | wlr_log(WLR_DEBUG, "Merging on top of seat * config"); | ||
61 | struct seat_config *current = new_seat_config(sc->name); | ||
62 | merge_seat_config(current, config->seat_configs->items[i]); | ||
63 | merge_seat_config(current, sc); | ||
64 | free_seat_config(sc); | ||
65 | sc = current; | ||
66 | } | ||
67 | list_add(config->seat_configs, sc); | ||
68 | } else { | ||
69 | // New wildcard config. Just add it | ||
70 | wlr_log(WLR_DEBUG, "Adding seat * config"); | ||
71 | list_add(config->seat_configs, sc); | ||
72 | } | ||
73 | |||
74 | wlr_log(WLR_DEBUG, "Config stored for seat %s", sc->name); | ||
75 | |||
76 | return sc; | ||
77 | } | ||
78 | |||
33 | struct seat_attachment_config *seat_attachment_config_new(void) { | 79 | struct seat_attachment_config *seat_attachment_config_new(void) { |
34 | struct seat_attachment_config *attachment = | 80 | struct seat_attachment_config *attachment = |
35 | calloc(1, sizeof(struct seat_attachment_config)); | 81 | calloc(1, sizeof(struct seat_attachment_config)); |
@@ -65,11 +111,6 @@ static void merge_seat_attachment_config(struct seat_attachment_config *dest, | |||
65 | } | 111 | } |
66 | 112 | ||
67 | void merge_seat_config(struct seat_config *dest, struct seat_config *source) { | 113 | void merge_seat_config(struct seat_config *dest, struct seat_config *source) { |
68 | if (source->name) { | ||
69 | free(dest->name); | ||
70 | dest->name = strdup(source->name); | ||
71 | } | ||
72 | |||
73 | if (source->fallback != -1) { | 114 | if (source->fallback != -1) { |
74 | dest->fallback = source->fallback; | 115 | dest->fallback = source->fallback; |
75 | } | 116 | } |
@@ -97,6 +138,10 @@ void merge_seat_config(struct seat_config *dest, struct seat_config *source) { | |||
97 | } | 138 | } |
98 | } | 139 | } |
99 | } | 140 | } |
141 | |||
142 | if (source->hide_cursor_timeout != -1) { | ||
143 | dest->hide_cursor_timeout = source->hide_cursor_timeout; | ||
144 | } | ||
100 | } | 145 | } |
101 | 146 | ||
102 | struct seat_config *copy_seat_config(struct seat_config *seat) { | 147 | struct seat_config *copy_seat_config(struct seat_config *seat) { |
@@ -117,11 +162,8 @@ void free_seat_config(struct seat_config *seat) { | |||
117 | 162 | ||
118 | free(seat->name); | 163 | free(seat->name); |
119 | for (int i = 0; i < seat->attachments->length; ++i) { | 164 | for (int i = 0; i < seat->attachments->length; ++i) { |
120 | struct seat_attachment_config *attachment = | 165 | seat_attachment_config_free(seat->attachments->items[i]); |
121 | seat->attachments->items[i]; | ||
122 | seat_attachment_config_free(attachment); | ||
123 | } | 166 | } |
124 | |||
125 | list_free(seat->attachments); | 167 | list_free(seat->attachments); |
126 | free(seat); | 168 | free(seat); |
127 | } | 169 | } |