From e197368c0ffc2235da9b6b41a0d16cdb5b0b61bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 26 Mar 2020 19:39:12 +0100 Subject: [PATCH] config: add 'startup-mode' option This option controls the initial window mode: windowed, maximized or fullscreen. The default is windowed. --- CHANGELOG.md | 2 ++ config.c | 18 +++++++++++++++++- config.h | 1 + doc/foot.5.scd | 4 ++++ footrc | 1 + terminal.c | 14 ++++++++++++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a310289..3e5b9a85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ * User configurable key- and mouse bindings. See `man 5 foot` and the example `footrc` (https://codeberg.org/dnkl/foot/issues/1) +* **startup-mode** option to `footrc`, that lets you control the + initial window mode: _windowed_, _maximized_ or _fullscreen_. ### Changed diff --git a/config.c b/config.c index 80163e2e..93b536cb 100644 --- a/config.c +++ b/config.c @@ -225,7 +225,7 @@ parse_section_main(const char *key, const char *value, struct config *conf, unsigned x, y; if (sscanf(value, "%ux%u", &x, &y) != 2) { LOG_ERR( - "%s: %d: expected PAD_XxPAD_Y, where both are positive integers: %s", + "%s:%d: expected PAD_XxPAD_Y, where both are positive integers: %s", path, lineno, value); return false; } @@ -234,6 +234,21 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->pad_y = y; } + else if (strcmp(key, "startup-mode") == 0) { + if (strcmp(value, "windowed") == 0) + conf->startup_mode = STARTUP_WINDOWED; + else if (strcmp(value, "maximized") == 0) + conf->startup_mode = STARTUP_MAXIMIZED; + else if (strcmp(value, "fullscreen") == 0) + conf->startup_mode = STARTUP_FULLSCREEN; + else { + LOG_ERR( + "%s:%d: expected either 'windowed', 'maximized' or 'fullscreen'", + path, lineno); + return false; + } + } + else if (strcmp(key, "font") == 0) { char *copy = strdup(value); for (const char *font = strtok(copy, ","); font != NULL; font = strtok(NULL, ",")) { @@ -803,6 +818,7 @@ config_load(struct config *conf, const char *conf_path) .height = 500, .pad_x = 2, .pad_y = 2, + .startup_mode = STARTUP_WINDOWED, .fonts = tll_init(), .scrollback_lines = 1000, diff --git a/config.h b/config.h index 596aa368..635abb20 100644 --- a/config.h +++ b/config.h @@ -15,6 +15,7 @@ struct config { unsigned height; unsigned pad_x; unsigned pad_y; + enum { STARTUP_WINDOWED, STARTUP_MAXIMIZED, STARTUP_FULLSCREEN } startup_mode; tll(char *) fonts; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 96036ce3..de32f712 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -40,6 +40,10 @@ in this order: Padding between border and glyphs, in pixels, on the form _XxY_ (-padding). Default: _2x2_. +*startup-mode* + Initial window mode: *windowed*, *maximized* or + *fullscreen*. Default: _windowed_. + *shell* Executable to launch. Typically a shell. Default: _$SHELL_ if set, otherwise the user's default shell (as specified in diff --git a/footrc b/footrc index 2575b58a..0254c31a 100644 --- a/footrc +++ b/footrc @@ -4,6 +4,7 @@ # scrollback=1000 # geometry=700x500 # pad=2x2 +# startup-mode=windowed # shell=$SHELL (if set, otherwise user's default shell from /etc/passwd) # term=foot # login-shell=no diff --git a/terminal.c b/terminal.c index 36f0e42b..41b0ccd9 100644 --- a/terminal.c +++ b/terminal.c @@ -13,6 +13,7 @@ #include #include #include +#include #define LOG_MODULE "terminal" #define LOG_ENABLE_DBG 0 @@ -800,6 +801,19 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, /* Let the Wayland backend know we exist */ tll_push_back(wayl->terms, term); + switch (conf->startup_mode) { + case STARTUP_WINDOWED: + break; + + case STARTUP_MAXIMIZED: + xdg_toplevel_set_maximized(term->window->xdg_toplevel); + break; + + case STARTUP_FULLSCREEN: + xdg_toplevel_set_fullscreen(term->window->xdg_toplevel, NULL); + break; + } + /* Start the slave/client */ if ((term->slave = slave_spawn(term->ptmx, argc, term->cwd, argv, term_env, conf->shell, login_shell)) == -1) goto err;