config: add 'startup-mode' option

This option controls the initial window mode: windowed, maximized or
fullscreen. The default is windowed.
This commit is contained in:
Daniel Eklöf 2020-03-26 19:39:12 +01:00
parent be8b6e8c75
commit e197368c0f
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
6 changed files with 39 additions and 1 deletions

View file

@ -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

View file

@ -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,

View file

@ -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;

View file

@ -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

1
footrc
View file

@ -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

View file

@ -13,6 +13,7 @@
#include <sys/timerfd.h>
#include <fcntl.h>
#include <linux/input-event-codes.h>
#include <xdg-shell.h>
#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;