mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-29 07:58:01 -04:00
add config + command line option for setting initial window width/height
This commit is contained in:
parent
4e2067446a
commit
7026f60717
6 changed files with 56 additions and 13 deletions
15
config.c
15
config.c
|
|
@ -159,6 +159,19 @@ parse_section_main(const char *key, const char *value, struct config *conf,
|
||||||
conf->shell = strdup(value);
|
conf->shell = strdup(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (strcmp(key, "geometry") == 0) {
|
||||||
|
unsigned width, height;
|
||||||
|
if (sscanf(value, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
||||||
|
LOG_ERR(
|
||||||
|
"%s: %d: expected WIDTHxHEIGHT, where both are positive integers: %s",
|
||||||
|
path, lineno, value);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->width = width;
|
||||||
|
conf->height = height;
|
||||||
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "font") == 0) {
|
else if (strcmp(key, "font") == 0) {
|
||||||
char *copy = strdup(value);
|
char *copy = strdup(value);
|
||||||
for (const char *font = strtok(copy, ","); font != NULL; font = strtok(NULL, ","))
|
for (const char *font = strtok(copy, ","); font != NULL; font = strtok(NULL, ","))
|
||||||
|
|
@ -440,6 +453,8 @@ config_load(struct config *conf)
|
||||||
*conf = (struct config) {
|
*conf = (struct config) {
|
||||||
.term = strdup("foot"),
|
.term = strdup("foot"),
|
||||||
.shell = get_shell(),
|
.shell = get_shell(),
|
||||||
|
.width = -1,
|
||||||
|
.height = -1,
|
||||||
.fonts = tll_init(),
|
.fonts = tll_init(),
|
||||||
.scrollback_lines = 1000,
|
.scrollback_lines = 1000,
|
||||||
|
|
||||||
|
|
|
||||||
3
config.h
3
config.h
|
|
@ -9,6 +9,9 @@
|
||||||
struct config {
|
struct config {
|
||||||
char *term;
|
char *term;
|
||||||
char *shell;
|
char *shell;
|
||||||
|
unsigned width;
|
||||||
|
unsigned height;
|
||||||
|
|
||||||
tll(char *) fonts;
|
tll(char *) fonts;
|
||||||
|
|
||||||
int scrollback_lines;
|
int scrollback_lines;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ execute (instead of the shell).
|
||||||
Font and style to use, in fontconfig format. See *FONT
|
Font and style to use, in fontconfig format. See *FONT
|
||||||
FORMAT*. Default: _monospace_.
|
FORMAT*. Default: _monospace_.
|
||||||
|
|
||||||
|
*-g*,*--geometry*=_WIDTHxHEIGHT_
|
||||||
|
Set initial window width and height.
|
||||||
|
|
||||||
*-t*,*--term*=_TERM_
|
*-t*,*--term*=_TERM_
|
||||||
Value to set the environment variable _TERM_ to. Default: _foot_.
|
Value to set the environment variable _TERM_ to. Default: _foot_.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ in this order:
|
||||||
Font and style to use, in fontconfig format. See *FONT
|
Font and style to use, in fontconfig format. See *FONT
|
||||||
FORMAT*. Default: _monospace_.
|
FORMAT*. Default: _monospace_.
|
||||||
|
|
||||||
|
*geometry*
|
||||||
|
Initial window width and height, on the form _WIDTHxHEIGHT_.
|
||||||
|
|
||||||
*shell*
|
*shell*
|
||||||
Executable to launch. Typically a shell. Default: the user's
|
Executable to launch. Typically a shell. Default: the user's
|
||||||
default shell (as specified in _/etc/passwd_).
|
default shell (as specified in _/etc/passwd_).
|
||||||
|
|
|
||||||
1
footrc
1
footrc
|
|
@ -1,5 +1,6 @@
|
||||||
# font=monospace
|
# font=monospace
|
||||||
# scrollback=1000
|
# scrollback=1000
|
||||||
|
# geometry=500x300
|
||||||
# shell=/usr/bin/zsh
|
# shell=/usr/bin/zsh
|
||||||
# term=foot
|
# term=foot
|
||||||
# workers=<number of logical CPUs>
|
# workers=<number of logical CPUs>
|
||||||
|
|
|
||||||
44
main.c
44
main.c
|
|
@ -353,9 +353,10 @@ print_usage(const char *prog_name)
|
||||||
printf("Usage: %s [OPTION]...\n", prog_name);
|
printf("Usage: %s [OPTION]...\n", prog_name);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -f,--font=FONT font name and style in fontconfig format (monospace)\n"
|
printf(" -f,--font=FONT font name and style in fontconfig format (monospace)\n"
|
||||||
" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
|
" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
|
||||||
" -v,--version show the version number and quit\n");
|
" -g,--geometry=WIDTHxHEIGHT set initial width and height\n"
|
||||||
|
" -v,--version show the version number and quit\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -371,15 +372,16 @@ main(int argc, char *const *argv)
|
||||||
const char *const prog_name = argv[0];
|
const char *const prog_name = argv[0];
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
{"term", required_argument, 0, 't'},
|
{"term", required_argument, 0, 't'},
|
||||||
{"font", required_argument, 0, 'f'},
|
{"font", required_argument, 0, 'f'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"geometry", required_argument, 0, 'g'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"version", no_argument, 0, 'v'},
|
||||||
{NULL, no_argument, 0, 0},
|
{"help", no_argument, 0, 'h'},
|
||||||
|
{NULL, no_argument, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int c = getopt_long(argc, argv, ":t:f:vh", longopts, NULL);
|
int c = getopt_long(argc, argv, ":t:f:g:vh", longopts, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -394,6 +396,18 @@ main(int argc, char *const *argv)
|
||||||
tll_push_back(conf.fonts, strdup(optarg));
|
tll_push_back(conf.fonts, strdup(optarg));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'g': {
|
||||||
|
unsigned width, height;
|
||||||
|
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
||||||
|
fprintf(stderr, "error: invalid geometry: %s\n", optarg);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf.width = width;
|
||||||
|
conf.height = height;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("foot version %s\n", FOOT_VERSION);
|
printf("foot version %s\n", FOOT_VERSION);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
@ -724,10 +738,14 @@ main(int argc, char *const *argv)
|
||||||
wl_surface_commit(term.wl.surface);
|
wl_surface_commit(term.wl.surface);
|
||||||
wl_display_roundtrip(term.wl.display);
|
wl_display_roundtrip(term.wl.display);
|
||||||
|
|
||||||
/* TODO: use font metrics to calculate initial size from ROWS x COLS */
|
if (conf.width == -1) {
|
||||||
const int default_width = 300;
|
assert(conf.height == -1);
|
||||||
const int default_height = 300;
|
conf.width = 80 * term.cell_width;
|
||||||
render_resize(&term, default_width, default_height);
|
conf.height = 24 * term.cell_height;
|
||||||
|
}
|
||||||
|
conf.width = max(conf.width, term.cell_width);
|
||||||
|
conf.height = max(conf.height, term.cell_height);
|
||||||
|
render_resize(&term, conf.width, conf.height);
|
||||||
|
|
||||||
wl_display_dispatch_pending(term.wl.display);
|
wl_display_dispatch_pending(term.wl.display);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue