diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-09-08 17:17:29 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-09-08 17:41:00 +0000 |
| commit | eb6737ca2593f457368ae16e920911cdd70a2e33 (patch) | |
| tree | f8dbf85542613c15d50439255d99db4e3d90ef25 /config.c | |
| parent | changelog: move deprecation section up first, change most ‘footrc’ -> ‘foot.ini’ (diff) | |
Add -W,--window-size-chars, and foot.ini:initial-window-size-chars
* Add -W,--window-size-chars command line option
* Add initial-window-size-chars foot.ini option
* Add -w,--window-size-pixels command line option
* Add initial-window-size-pixels foot.ini option
* Deprecate -g,--geometry command line option in favor of
-w,--window-size-pixels
* Deprecate geometry option in foot.ini in favor of
initial-window-size-pixels
Diffstat (limited to 'config.c')
| -rw-r--r-- | config.c | 63 |
1 files changed, 51 insertions, 12 deletions
@@ -452,18 +452,49 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->app_id = xstrdup(value); } - else if (strcmp(key, "geometry") == 0) { + else if (strcmp(key, "initial-window-size-pixels") == 0 || + strcmp(key, "geometry") == 0 /* deprecated */) + { + if (strcmp(key, "geometry") == 0) { + LOG_WARN("deprecated: [default]: geometry: use 'initial-window-size-pixels' instead'"); + + const char *fmt = "%s:%d: \033[1mgeometry\033[21m, use \033[1minitial-window-size-pixels\033[21m instead"; + char *text = xasprintf(fmt, path, lineno); + + struct user_notification deprecation = { + .kind = USER_NOTIFICATION_DEPRECATED, + .text = text, + }; + tll_push_back(conf->notifications, deprecation); + } + unsigned width, height; if (sscanf(value, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) { LOG_AND_NOTIFY_ERR( - "%s: %d: [default]: geometry: expected WIDTHxHEIGHT, " - "where both are positive integers, got '%s'", - path, lineno, value); + "%s: %d: [default]: initial-window-size-pixels: " + "expected WIDTHxHEIGHT, where both are positive integers, " + "got '%s'", path, lineno, value); + return false; + } + + conf->size.type = CONF_SIZE_PX; + conf->size.px.width = width; + conf->size.px.height = height; + } + + else if (strcmp(key, "initial-window-size-chars") == 0) { + unsigned width, height; + if (sscanf(value, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) { + LOG_AND_NOTIFY_ERR( + "%s: %d: [default]: initial-window-size-chars: " + "expected WIDTHxHEIGHT, where both are positive integers, " + "got '%s'", path, lineno, value); return false; } - conf->width = width; - conf->height = height; + conf->size.type = CONF_SIZE_CELLS; + conf->size.cells.width = width; + conf->size.cells.height = height; } else if (strcmp(key, "pad") == 0) { @@ -1721,7 +1752,8 @@ add_default_mouse_bindings(struct config *conf) } bool -config_load(struct config *conf, const char *conf_path, bool errors_are_fatal) +config_load(struct config *conf, const char *conf_path, + user_notifications_t *initial_user_notifications, bool errors_are_fatal) { bool ret = false; @@ -1730,8 +1762,13 @@ config_load(struct config *conf, const char *conf_path, bool errors_are_fatal) .shell = get_shell(), .title = xstrdup("foot"), .app_id = xstrdup("foot"), - .width = 700, - .height = 500, + .size = { + .type = CONF_SIZE_PX, + .px = { + .width = 700, + .height = 500, + }, + }, .pad_x = 2, .pad_y = 2, .startup_mode = STARTUP_WINDOWED, @@ -1810,6 +1847,10 @@ config_load(struct config *conf, const char *conf_path, bool errors_are_fatal) .notifications = tll_init(), }; + tll_foreach(*initial_user_notifications, it) + tll_push_back(conf->notifications, it->item); + tll_free(*initial_user_notifications); + add_default_key_bindings(conf); add_default_search_bindings(conf); add_default_mouse_bindings(conf); @@ -1887,9 +1928,7 @@ config_free(struct config conf) tll_free(conf.bindings.mouse); tll_free(conf.bindings.search); - tll_foreach(conf.notifications, it) - free(it->item.text); - tll_free(conf.notifications); + user_notifications_free(&conf.notifications); } struct config_font |
