mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05: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);
|
||||
}
|
||||
|
||||
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) {
|
||||
char *copy = strdup(value);
|
||||
for (const char *font = strtok(copy, ","); font != NULL; font = strtok(NULL, ","))
|
||||
|
|
@ -440,6 +453,8 @@ config_load(struct config *conf)
|
|||
*conf = (struct config) {
|
||||
.term = strdup("foot"),
|
||||
.shell = get_shell(),
|
||||
.width = -1,
|
||||
.height = -1,
|
||||
.fonts = tll_init(),
|
||||
.scrollback_lines = 1000,
|
||||
|
||||
|
|
|
|||
3
config.h
3
config.h
|
|
@ -9,6 +9,9 @@
|
|||
struct config {
|
||||
char *term;
|
||||
char *shell;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
|
||||
tll(char *) fonts;
|
||||
|
||||
int scrollback_lines;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ execute (instead of the shell).
|
|||
Font and style to use, in fontconfig format. See *FONT
|
||||
FORMAT*. Default: _monospace_.
|
||||
|
||||
*-g*,*--geometry*=_WIDTHxHEIGHT_
|
||||
Set initial window width and height.
|
||||
|
||||
*-t*,*--term*=_TERM_
|
||||
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
|
||||
FORMAT*. Default: _monospace_.
|
||||
|
||||
*geometry*
|
||||
Initial window width and height, on the form _WIDTHxHEIGHT_.
|
||||
|
||||
*shell*
|
||||
Executable to launch. Typically a shell. Default: the user's
|
||||
default shell (as specified in _/etc/passwd_).
|
||||
|
|
|
|||
1
footrc
1
footrc
|
|
@ -1,5 +1,6 @@
|
|||
# font=monospace
|
||||
# scrollback=1000
|
||||
# geometry=500x300
|
||||
# shell=/usr/bin/zsh
|
||||
# term=foot
|
||||
# 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("\n");
|
||||
printf("Options:\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"
|
||||
" -v,--version show the version number and quit\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"
|
||||
" -g,--geometry=WIDTHxHEIGHT set initial width and height\n"
|
||||
" -v,--version show the version number and quit\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
|
@ -371,15 +372,16 @@ main(int argc, char *const *argv)
|
|||
const char *const prog_name = argv[0];
|
||||
|
||||
static const struct option longopts[] = {
|
||||
{"term", required_argument, 0, 't'},
|
||||
{"font", required_argument, 0, 'f'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{NULL, no_argument, 0, 0},
|
||||
{"term", required_argument, 0, 't'},
|
||||
{"font", required_argument, 0, 'f'},
|
||||
{"geometry", required_argument, 0, 'g'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{NULL, no_argument, 0, 0},
|
||||
};
|
||||
|
||||
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)
|
||||
break;
|
||||
|
||||
|
|
@ -394,6 +396,18 @@ main(int argc, char *const *argv)
|
|||
tll_push_back(conf.fonts, strdup(optarg));
|
||||
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':
|
||||
printf("foot version %s\n", FOOT_VERSION);
|
||||
return EXIT_SUCCESS;
|
||||
|
|
@ -724,10 +738,14 @@ main(int argc, char *const *argv)
|
|||
wl_surface_commit(term.wl.surface);
|
||||
wl_display_roundtrip(term.wl.display);
|
||||
|
||||
/* TODO: use font metrics to calculate initial size from ROWS x COLS */
|
||||
const int default_width = 300;
|
||||
const int default_height = 300;
|
||||
render_resize(&term, default_width, default_height);
|
||||
if (conf.width == -1) {
|
||||
assert(conf.height == -1);
|
||||
conf.width = 80 * term.cell_width;
|
||||
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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue