aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-08-23 15:26:41 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-08-23 15:26:41 +0000
commit7026f6071752423ed55d3e7dfa0b4112d39efb9a (patch)
tree88a8284ef33767adb358447beca5262634604104
parentmain: use slave's exit value as our exit value (diff)
add config + command line option for setting initial window width/height
-rw-r--r--config.c15
-rw-r--r--config.h3
-rw-r--r--doc/foot.1.scd3
-rw-r--r--doc/foot.5.scd3
-rw-r--r--footrc1
-rw-r--r--main.c44
6 files changed, 56 insertions, 13 deletions
diff --git a/config.c b/config.c
index eb9031ed..d410b721 100644
--- a/config.c
+++ b/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,
diff --git a/config.h b/config.h
index e7158688..34373969 100644
--- a/config.h
+++ b/config.h
@@ -9,6 +9,9 @@
struct config {
char *term;
char *shell;
+ unsigned width;
+ unsigned height;
+
tll(char *) fonts;
int scrollback_lines;
diff --git a/doc/foot.1.scd b/doc/foot.1.scd
index 09661bbb..8c559d7b 100644
--- a/doc/foot.1.scd
+++ b/doc/foot.1.scd
@@ -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_.
diff --git a/doc/foot.5.scd b/doc/foot.5.scd
index 51d8888f..fe37639b 100644
--- a/doc/foot.5.scd
+++ b/doc/foot.5.scd
@@ -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_).
diff --git a/footrc b/footrc
index 7cacbf1b..d0c868c3 100644
--- a/footrc
+++ b/footrc
@@ -1,5 +1,6 @@
# font=monospace
# scrollback=1000
+# geometry=500x300
# shell=/usr/bin/zsh
# term=foot
# workers=<number of logical CPUs>
diff --git a/main.c b/main.c
index ca88dae7..2a3b3daa 100644
--- a/main.c
+++ b/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);