diff options
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/sway/config.c b/sway/config.c index 61131845..b591ae9e 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include <signal.h> | 12 | #include <signal.h> |
13 | #include <libinput.h> | 13 | #include <libinput.h> |
14 | #include <limits.h> | 14 | #include <limits.h> |
15 | #include <float.h> | ||
16 | #include <dirent.h> | 15 | #include <dirent.h> |
17 | #include <strings.h> | 16 | #include <strings.h> |
18 | #ifdef __linux__ | 17 | #ifdef __linux__ |
@@ -21,6 +20,7 @@ | |||
21 | #include <dev/evdev/input-event-codes.h> | 20 | #include <dev/evdev/input-event-codes.h> |
22 | #endif | 21 | #endif |
23 | #include <wlr/types/wlr_output.h> | 22 | #include <wlr/types/wlr_output.h> |
23 | #include "sway/input/input-manager.h" | ||
24 | #include "sway/commands.h" | 24 | #include "sway/commands.h" |
25 | #include "sway/config.h" | 25 | #include "sway/config.h" |
26 | #include "sway/layout.h" | 26 | #include "sway/layout.h" |
@@ -44,11 +44,13 @@ static void config_defaults(struct sway_config *config) { | |||
44 | if (!(config->criteria = create_list())) goto cleanup; | 44 | if (!(config->criteria = create_list())) goto cleanup; |
45 | if (!(config->no_focus = create_list())) goto cleanup; | 45 | if (!(config->no_focus = create_list())) goto cleanup; |
46 | if (!(config->input_configs = create_list())) goto cleanup; | 46 | if (!(config->input_configs = create_list())) goto cleanup; |
47 | if (!(config->seat_configs = create_list())) goto cleanup; | ||
47 | if (!(config->output_configs = create_list())) goto cleanup; | 48 | if (!(config->output_configs = create_list())) goto cleanup; |
48 | 49 | ||
49 | if (!(config->cmd_queue = create_list())) goto cleanup; | 50 | if (!(config->cmd_queue = create_list())) goto cleanup; |
50 | 51 | ||
51 | if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) goto cleanup; | 52 | if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) |
53 | goto cleanup; | ||
52 | if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup; | 54 | if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup; |
53 | strcpy(config->current_mode->name, "default"); | 55 | strcpy(config->current_mode->name, "default"); |
54 | if (!(config->current_mode->bindings = create_list())) goto cleanup; | 56 | if (!(config->current_mode->bindings = create_list())) goto cleanup; |
@@ -256,8 +258,9 @@ bool load_main_config(const char *file, bool is_active) { | |||
256 | bool success = true; | 258 | bool success = true; |
257 | DIR *dir = opendir(SYSCONFDIR "/sway/security.d"); | 259 | DIR *dir = opendir(SYSCONFDIR "/sway/security.d"); |
258 | if (!dir) { | 260 | if (!dir) { |
259 | sway_log(L_ERROR, "%s does not exist, sway will have no security configuration" | 261 | sway_log(L_ERROR, |
260 | " and will probably be broken", SYSCONFDIR "/sway/security.d"); | 262 | "%s does not exist, sway will have no security configuration" |
263 | " and will probably be broken", SYSCONFDIR "/sway/security.d"); | ||
261 | } else { | 264 | } else { |
262 | list_t *secconfigs = create_list(); | 265 | list_t *secconfigs = create_list(); |
263 | char *base = SYSCONFDIR "/sway/security.d/"; | 266 | char *base = SYSCONFDIR "/sway/security.d/"; |
@@ -281,8 +284,12 @@ bool load_main_config(const char *file, bool is_active) { | |||
281 | list_qsort(secconfigs, qstrcmp); | 284 | list_qsort(secconfigs, qstrcmp); |
282 | for (int i = 0; i < secconfigs->length; ++i) { | 285 | for (int i = 0; i < secconfigs->length; ++i) { |
283 | char *_path = secconfigs->items[i]; | 286 | char *_path = secconfigs->items[i]; |
284 | if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (((s.st_mode & 0777) != 0644) && (s.st_mode & 0777) != 0444)) { | 287 | if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || |
285 | sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644 or 444", _path); | 288 | (((s.st_mode & 0777) != 0644) && |
289 | (s.st_mode & 0777) != 0444)) { | ||
290 | sway_log(L_ERROR, | ||
291 | "Refusing to load %s - it must be owned by root " | ||
292 | "and mode 644 or 444", _path); | ||
286 | success = false; | 293 | success = false; |
287 | } else { | 294 | } else { |
288 | success = success && load_config(_path, config); | 295 | success = success && load_config(_path, config); |
@@ -311,7 +318,8 @@ bool load_main_config(const char *file, bool is_active) { | |||
311 | return success; | 318 | return success; |
312 | } | 319 | } |
313 | 320 | ||
314 | static bool load_include_config(const char *path, const char *parent_dir, struct sway_config *config) { | 321 | static bool load_include_config(const char *path, const char *parent_dir, |
322 | struct sway_config *config) { | ||
315 | // save parent config | 323 | // save parent config |
316 | const char *parent_config = config->current_config; | 324 | const char *parent_config = config->current_config; |
317 | 325 | ||
@@ -321,7 +329,8 @@ static bool load_include_config(const char *path, const char *parent_dir, struct | |||
321 | len = len + strlen(parent_dir) + 2; | 329 | len = len + strlen(parent_dir) + 2; |
322 | full_path = malloc(len * sizeof(char)); | 330 | full_path = malloc(len * sizeof(char)); |
323 | if (!full_path) { | 331 | if (!full_path) { |
324 | sway_log(L_ERROR, "Unable to allocate full path to included config"); | 332 | sway_log(L_ERROR, |
333 | "Unable to allocate full path to included config"); | ||
325 | return false; | 334 | return false; |
326 | } | 335 | } |
327 | snprintf(full_path, len, "%s/%s", parent_dir, path); | 336 | snprintf(full_path, len, "%s/%s", parent_dir, path); |
@@ -340,7 +349,9 @@ static bool load_include_config(const char *path, const char *parent_dir, struct | |||
340 | for (j = 0; j < config->config_chain->length; ++j) { | 349 | for (j = 0; j < config->config_chain->length; ++j) { |
341 | char *old_path = config->config_chain->items[j]; | 350 | char *old_path = config->config_chain->items[j]; |
342 | if (strcmp(real_path, old_path) == 0) { | 351 | if (strcmp(real_path, old_path) == 0) { |
343 | sway_log(L_DEBUG, "%s already included once, won't be included again.", real_path); | 352 | sway_log(L_DEBUG, |
353 | "%s already included once, won't be included again.", | ||
354 | real_path); | ||
344 | free(real_path); | 355 | free(real_path); |
345 | return false; | 356 | return false; |
346 | } | 357 | } |
@@ -400,6 +411,7 @@ bool load_include_configs(const char *path, struct sway_config *config) { | |||
400 | return true; | 411 | return true; |
401 | } | 412 | } |
402 | 413 | ||
414 | |||
403 | bool read_config(FILE *file, struct sway_config *config) { | 415 | bool read_config(FILE *file, struct sway_config *config) { |
404 | bool success = true; | 416 | bool success = true; |
405 | enum cmd_status block = CMD_BLOCK_END; | 417 | enum cmd_status block = CMD_BLOCK_END; |
@@ -427,8 +439,8 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
427 | switch(res->status) { | 439 | switch(res->status) { |
428 | case CMD_FAILURE: | 440 | case CMD_FAILURE: |
429 | case CMD_INVALID: | 441 | case CMD_INVALID: |
430 | sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number, line, | 442 | sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number, |
431 | res->error, config->current_config); | 443 | line, res->error, config->current_config); |
432 | success = false; | 444 | success = false; |
433 | break; | 445 | break; |
434 | 446 | ||
@@ -453,6 +465,14 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
453 | } | 465 | } |
454 | break; | 466 | break; |
455 | 467 | ||
468 | case CMD_BLOCK_SEAT: | ||
469 | if (block == CMD_BLOCK_END) { | ||
470 | block = CMD_BLOCK_SEAT; | ||
471 | } else { | ||
472 | sway_log(L_ERROR, "Invalid block '%s'", line); | ||
473 | } | ||
474 | break; | ||
475 | |||
456 | case CMD_BLOCK_BAR: | 476 | case CMD_BLOCK_BAR: |
457 | if (block == CMD_BLOCK_END) { | 477 | if (block == CMD_BLOCK_END) { |
458 | block = CMD_BLOCK_BAR; | 478 | block = CMD_BLOCK_BAR; |
@@ -503,8 +523,13 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
503 | 523 | ||
504 | case CMD_BLOCK_INPUT: | 524 | case CMD_BLOCK_INPUT: |
505 | sway_log(L_DEBUG, "End of input block"); | 525 | sway_log(L_DEBUG, "End of input block"); |
506 | // TODO: input | 526 | current_input_config = NULL; |
507 | //current_input_config = NULL; | 527 | block = CMD_BLOCK_END; |
528 | break; | ||
529 | |||
530 | case CMD_BLOCK_SEAT: | ||
531 | sway_log(L_DEBUG, "End of seat block"); | ||
532 | current_seat_config = NULL; | ||
508 | block = CMD_BLOCK_END; | 533 | block = CMD_BLOCK_END; |
509 | break; | 534 | break; |
510 | 535 | ||
@@ -569,7 +594,8 @@ char *do_var_replacement(char *str) { | |||
569 | char *newstr = malloc(strlen(str) - vnlen + vvlen + 1); | 594 | char *newstr = malloc(strlen(str) - vnlen + vvlen + 1); |
570 | if (!newstr) { | 595 | if (!newstr) { |
571 | sway_log(L_ERROR, | 596 | sway_log(L_ERROR, |
572 | "Unable to allocate replacement during variable expansion"); | 597 | "Unable to allocate replacement " |
598 | "during variable expansion"); | ||
573 | break; | 599 | break; |
574 | } | 600 | } |
575 | char *newptr = newstr; | 601 | char *newptr = newstr; |