aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c107
1 files changed, 59 insertions, 48 deletions
diff --git a/sway/config.c b/sway/config.c
index 6e665434..e4745a5c 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -26,7 +26,7 @@
26#include "sway/tree/arrange.h" 26#include "sway/tree/arrange.h"
27#include "sway/tree/root.h" 27#include "sway/tree/root.h"
28#include "sway/tree/workspace.h" 28#include "sway/tree/workspace.h"
29#include "cairo.h" 29#include "cairo_util.h"
30#include "pango.h" 30#include "pango.h"
31#include "stringop.h" 31#include "stringop.h"
32#include "list.h" 32#include "list.h"
@@ -236,7 +236,6 @@ static void config_defaults(struct sway_config *config) {
236 config->default_layout = L_NONE; 236 config->default_layout = L_NONE;
237 config->default_orientation = L_NONE; 237 config->default_orientation = L_NONE;
238 if (!(config->font = strdup("monospace 10"))) goto cleanup; 238 if (!(config->font = strdup("monospace 10"))) goto cleanup;
239 config->font_height = 17; // height of monospace 10
240 config->urgent_timeout = 500; 239 config->urgent_timeout = 500;
241 config->focus_on_window_activation = FOWA_URGENT; 240 config->focus_on_window_activation = FOWA_URGENT;
242 config->popup_during_fullscreen = POPUP_SMART; 241 config->popup_during_fullscreen = POPUP_SMART;
@@ -267,7 +266,7 @@ static void config_defaults(struct sway_config *config) {
267 config->tiling_drag = true; 266 config->tiling_drag = true;
268 config->tiling_drag_threshold = 9; 267 config->tiling_drag_threshold = 9;
269 268
270 config->smart_gaps = false; 269 config->smart_gaps = SMART_GAPS_OFF;
271 config->gaps_inner = 0; 270 config->gaps_inner = 0;
272 config->gaps_outer.top = 0; 271 config->gaps_outer.top = 0;
273 config->gaps_outer.right = 0; 272 config->gaps_outer.right = 0;
@@ -291,6 +290,8 @@ static void config_defaults(struct sway_config *config) {
291 config->hide_edge_borders_smart = ESMART_OFF; 290 config->hide_edge_borders_smart = ESMART_OFF;
292 config->hide_lone_tab = false; 291 config->hide_lone_tab = false;
293 292
293 config->has_focused_tab_title = false;
294
294 // border colors 295 // border colors
295 color_to_rgba(config->border_colors.focused.border, 0x4C7899FF); 296 color_to_rgba(config->border_colors.focused.border, 0x4C7899FF);
296 color_to_rgba(config->border_colors.focused.background, 0x285577FF); 297 color_to_rgba(config->border_colors.focused.background, 0x285577FF);
@@ -338,35 +339,62 @@ static bool file_exists(const char *path) {
338 return path && access(path, R_OK) != -1; 339 return path && access(path, R_OK) != -1;
339} 340}
340 341
342static char *config_path(const char *prefix, const char *config_folder) {
343 if (!prefix || !prefix[0] || !config_folder || !config_folder[0]) {
344 return NULL;
345 }
346
347 const char *filename = "config";
348
349 size_t size = 3 + strlen(prefix) + strlen(config_folder) + strlen(filename);
350 char *path = calloc(size, sizeof(char));
351 snprintf(path, size, "%s/%s/%s", prefix, config_folder, filename);
352 return path;
353}
354
341static char *get_config_path(void) { 355static char *get_config_path(void) {
342 static const char *config_paths[] = { 356 char *path = NULL;
343 "$HOME/.sway/config", 357 const char *home = getenv("HOME");
344 "$XDG_CONFIG_HOME/sway/config", 358 char *config_home_fallback = NULL;
345 "$HOME/.i3/config", 359
346 "$XDG_CONFIG_HOME/i3/config", 360 const char *config_home = getenv("XDG_CONFIG_HOME");
347 SYSCONFDIR "/sway/config", 361 if ((config_home == NULL || config_home[0] == '\0') && home != NULL) {
348 SYSCONFDIR "/i3/config", 362 size_t size_fallback = 1 + strlen(home) + strlen("/.config");
363 config_home_fallback = calloc(size_fallback, sizeof(char));
364 if (config_home_fallback != NULL)
365 snprintf(config_home_fallback, size_fallback, "%s/.config", home);
366 config_home = config_home_fallback;
367 }
368
369 struct config_path {
370 const char *prefix;
371 const char *config_folder;
349 }; 372 };
350 373
351 char *config_home = getenv("XDG_CONFIG_HOME"); 374 struct config_path config_paths[] = {
352 if (!config_home || !*config_home) { 375 { .prefix = home, .config_folder = ".sway"},
353 config_paths[1] = "$HOME/.config/sway/config"; 376 { .prefix = config_home, .config_folder = "sway"},
354 config_paths[3] = "$HOME/.config/i3/config"; 377 { .prefix = home, .config_folder = ".i3"},
355 } 378 { .prefix = config_home, .config_folder = "i3"},
379 { .prefix = SYSCONFDIR, .config_folder = "sway"},
380 { .prefix = SYSCONFDIR, .config_folder = "i3"}
381 };
356 382
357 for (size_t i = 0; i < sizeof(config_paths) / sizeof(char *); ++i) { 383 size_t num_config_paths = sizeof(config_paths)/sizeof(config_paths[0]);
358 wordexp_t p; 384 for (size_t i = 0; i < num_config_paths; i++) {
359 if (wordexp(config_paths[i], &p, WRDE_UNDEF) == 0) { 385 path = config_path(config_paths[i].prefix, config_paths[i].config_folder);
360 char *path = strdup(p.we_wordv[0]); 386 if (!path) {
361 wordfree(&p); 387 continue;
362 if (file_exists(path)) { 388 }
363 return path; 389 if (file_exists(path)) {
364 } 390 break;
365 free(path);
366 } 391 }
392 free(path);
393 path = NULL;
367 } 394 }
368 395
369 return NULL; 396 free(config_home_fallback);
397 return path;
370} 398}
371 399
372static bool load_config(const char *path, struct sway_config *config, 400static bool load_config(const char *path, struct sway_config *config,
@@ -514,6 +542,9 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
514 return success; 542 return success;
515 } 543 }
516 544
545 // Only really necessary if not explicitly `font` is set in the config.
546 config_update_font_height();
547
517 if (is_active && !validating) { 548 if (is_active && !validating) {
518 input_manager_verify_fallback_seat(); 549 input_manager_verify_fallback_seat();
519 550
@@ -964,31 +995,11 @@ int workspace_output_cmp_workspace(const void *a, const void *b) {
964 return lenient_strcmp(wsa->workspace, wsb->workspace); 995 return lenient_strcmp(wsa->workspace, wsb->workspace);
965} 996}
966 997
967static void find_font_height_iterator(struct sway_container *con, void *data) {
968 size_t amount_below_baseline = con->title_height - con->title_baseline;
969 size_t extended_height = config->font_baseline + amount_below_baseline;
970 if (extended_height > config->font_height) {
971 config->font_height = extended_height;
972 }
973}
974
975static void find_baseline_iterator(struct sway_container *con, void *data) {
976 bool *recalculate = data;
977 if (*recalculate) {
978 container_calculate_title_height(con);
979 }
980 if (con->title_baseline > config->font_baseline) {
981 config->font_baseline = con->title_baseline;
982 }
983}
984 998
985void config_update_font_height(bool recalculate) { 999void config_update_font_height(void) {
986 size_t prev_max_height = config->font_height; 1000 int prev_max_height = config->font_height;
987 config->font_height = 0;
988 config->font_baseline = 0;
989 1001
990 root_for_each_container(find_baseline_iterator, &recalculate); 1002 get_text_metrics(config->font, &config->font_height, &config->font_baseline);
991 root_for_each_container(find_font_height_iterator, NULL);
992 1003
993 if (config->font_height != prev_max_height) { 1004 if (config->font_height != prev_max_height) {
994 arrange_root(); 1005 arrange_root();