aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c103
1 files changed, 34 insertions, 69 deletions
diff --git a/sway/config.c b/sway/config.c
index 4b51dc73..f9131e0f 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -1,3 +1,4 @@
1#undef _POSIX_C_SOURCE
1#define _XOPEN_SOURCE 700 // for realpath 2#define _XOPEN_SOURCE 700 // for realpath
2#include <stdio.h> 3#include <stdio.h>
3#include <stdbool.h> 4#include <stdbool.h>
@@ -36,19 +37,26 @@
36struct sway_config *config = NULL; 37struct sway_config *config = NULL;
37 38
38static struct xkb_state *keysym_translation_state_create( 39static struct xkb_state *keysym_translation_state_create(
39 struct xkb_rule_names rules) { 40 struct xkb_rule_names rules, uint32_t context_flags) {
40 struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_SECURE_GETENV); 41 struct xkb_context *context = xkb_context_new(context_flags | XKB_CONTEXT_NO_SECURE_GETENV);
41 struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names( 42 struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names(
42 context, 43 context,
43 &rules, 44 &rules,
44 XKB_KEYMAP_COMPILE_NO_FLAGS); 45 XKB_KEYMAP_COMPILE_NO_FLAGS);
45
46 xkb_context_unref(context); 46 xkb_context_unref(context);
47 if (xkb_keymap == NULL) {
48 sway_log(SWAY_ERROR, "Failed to compile keysym translation XKB keymap");
49 return NULL;
50 }
51
47 return xkb_state_new(xkb_keymap); 52 return xkb_state_new(xkb_keymap);
48} 53}
49 54
50static void keysym_translation_state_destroy( 55static void keysym_translation_state_destroy(
51 struct xkb_state *state) { 56 struct xkb_state *state) {
57 if (state == NULL) {
58 return;
59 }
52 xkb_keymap_unref(xkb_state_get_keymap(state)); 60 xkb_keymap_unref(xkb_state_get_keymap(state));
53 xkb_state_unref(state); 61 xkb_state_unref(state);
54} 62}
@@ -336,8 +344,14 @@ static void config_defaults(struct sway_config *config) {
336 344
337 // The keysym to keycode translation 345 // The keysym to keycode translation
338 struct xkb_rule_names rules = {0}; 346 struct xkb_rule_names rules = {0};
339 config->keysym_translation_state = 347 config->keysym_translation_state = keysym_translation_state_create(rules, 0);
340 keysym_translation_state_create(rules); 348 if (config->keysym_translation_state == NULL) {
349 config->keysym_translation_state = keysym_translation_state_create(rules,
350 XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
351 }
352 if (config->keysym_translation_state == NULL) {
353 goto cleanup;
354 }
341 355
342 return; 356 return;
343cleanup: 357cleanup:
@@ -352,13 +366,7 @@ static char *config_path(const char *prefix, const char *config_folder) {
352 if (!prefix || !prefix[0] || !config_folder || !config_folder[0]) { 366 if (!prefix || !prefix[0] || !config_folder || !config_folder[0]) {
353 return NULL; 367 return NULL;
354 } 368 }
355 369 return format_str("%s/%s/config", prefix, config_folder);
356 const char *filename = "config";
357
358 size_t size = 3 + strlen(prefix) + strlen(config_folder) + strlen(filename);
359 char *path = calloc(size, sizeof(char));
360 snprintf(path, size, "%s/%s/%s", prefix, config_folder, filename);
361 return path;
362} 370}
363 371
364static char *get_config_path(void) { 372static char *get_config_path(void) {
@@ -368,10 +376,7 @@ static char *get_config_path(void) {
368 376
369 const char *config_home = getenv("XDG_CONFIG_HOME"); 377 const char *config_home = getenv("XDG_CONFIG_HOME");
370 if ((config_home == NULL || config_home[0] == '\0') && home != NULL) { 378 if ((config_home == NULL || config_home[0] == '\0') && home != NULL) {
371 size_t size_fallback = 1 + strlen(home) + strlen("/.config"); 379 config_home_fallback = format_str("%s/.config", home);
372 config_home_fallback = calloc(size_fallback, sizeof(char));
373 if (config_home_fallback != NULL)
374 snprintf(config_home_fallback, size_fallback, "%s/.config", home);
375 config_home = config_home_fallback; 380 config_home = config_home_fallback;
376 } 381 }
377 382
@@ -475,6 +480,11 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
475 old_config->xwayland ? "enabled" : "disabled"); 480 old_config->xwayland ? "enabled" : "disabled");
476 config->xwayland = old_config->xwayland; 481 config->xwayland = old_config->xwayland;
477 482
483 // primary_selection can only be enabled/disabled at launch
484 sway_log(SWAY_DEBUG, "primary_selection will remain %s",
485 old_config->primary_selection ? "enabled" : "disabled");
486 config->primary_selection = old_config->primary_selection;
487
478 if (!config->validating) { 488 if (!config->validating) {
479 if (old_config->swaybg_client != NULL) { 489 if (old_config->swaybg_client != NULL) {
480 wl_client_destroy(old_config->swaybg_client); 490 wl_client_destroy(old_config->swaybg_client);
@@ -494,56 +504,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
494 504
495 config->reading = true; 505 config->reading = true;
496 506
497 // Read security configs 507 bool success = load_config(path, config, &config->swaynag_config_errors);
498 // TODO: Security
499 bool success = true;
500 /*
501 DIR *dir = opendir(SYSCONFDIR "/sway/security.d");
502 if (!dir) {
503 sway_log(SWAY_ERROR,
504 "%s does not exist, sway will have no security configuration"
505 " and will probably be broken", SYSCONFDIR "/sway/security.d");
506 } else {
507 list_t *secconfigs = create_list();
508 char *base = SYSCONFDIR "/sway/security.d/";
509 struct dirent *ent = readdir(dir);
510 struct stat s;
511 while (ent != NULL) {
512 char *_path = malloc(strlen(ent->d_name) + strlen(base) + 1);
513 strcpy(_path, base);
514 strcat(_path, ent->d_name);
515 lstat(_path, &s);
516 if (S_ISREG(s.st_mode) && ent->d_name[0] != '.') {
517 list_add(secconfigs, _path);
518 }
519 else {
520 free(_path);
521 }
522 ent = readdir(dir);
523 }
524 closedir(dir);
525
526 list_qsort(secconfigs, qstrcmp);
527 for (int i = 0; i < secconfigs->length; ++i) {
528 char *_path = secconfigs->items[i];
529 if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 ||
530 (((s.st_mode & 0777) != 0644) &&
531 (s.st_mode & 0777) != 0444)) {
532 sway_log(SWAY_ERROR,
533 "Refusing to load %s - it must be owned by root "
534 "and mode 644 or 444", _path);
535 success = false;
536 } else {
537 success = success && load_config(_path, config);
538 }
539 }
540
541 list_free_items_and_destroy(secconfigs);
542 }
543 */
544
545 success = success && load_config(path, config,
546 &config->swaynag_config_errors);
547 508
548 if (validating) { 509 if (validating) {
549 free_config(config); 510 free_config(config);
@@ -571,7 +532,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
571 } 532 }
572 sway_switch_retrigger_bindings_for_all(); 533 sway_switch_retrigger_bindings_for_all();
573 534
574 reset_outputs(); 535 apply_all_output_configs();
575 spawn_swaybg(); 536 spawn_swaybg();
576 537
577 config->reloading = false; 538 config->reloading = false;
@@ -1037,8 +998,12 @@ void translate_keysyms(struct input_config *input_config) {
1037 998
1038 struct xkb_rule_names rules = {0}; 999 struct xkb_rule_names rules = {0};
1039 input_config_fill_rule_names(input_config, &rules); 1000 input_config_fill_rule_names(input_config, &rules);
1040 config->keysym_translation_state = 1001 config->keysym_translation_state = keysym_translation_state_create(rules, 0);
1041 keysym_translation_state_create(rules); 1002 if (config->keysym_translation_state == NULL) {
1003 sway_log(SWAY_ERROR, "Failed to create keysym translation XKB state "
1004 "for device '%s'", input_config->identifier);
1005 return;
1006 }
1042 1007
1043 for (int i = 0; i < config->modes->length; ++i) { 1008 for (int i = 0; i < config->modes->length; ++i) {
1044 struct sway_mode *mode = config->modes->items[i]; 1009 struct sway_mode *mode = config->modes->items[i];