From fd78fa98b4765771b65140bc6edfbd472b4f666b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 27 Aug 2021 20:25:26 +0200 Subject: doc: how to pass TERMINFO through ‘doas’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See #692 --- doc/foot.1.scd | 17 ++++++++++++----- doc/footclient.1.scd | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'doc') diff --git a/doc/foot.1.scd b/doc/foot.1.scd index cbebd087..26fee4a1 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -409,15 +409,22 @@ The following environment variables are set in the child process: definitions in ncurses. Note that applications will search the default location(s) if *TERM* does not exist in *TERMINFO*. - Note that applications like sudo and ssh will remove this - environment variable. + Note that applications like *sudo*, *doas* and *ssh* may remove + this environment variable. - For sudo, you can create a file under _/etc/sudoers.d_ (name does - not matter) with the following content: + For *sudo*, you can create a file under _/etc/sudoers.d_ (name + does not matter) with the following content: *Defaults env_keep += "TERMINFO"* - For ssh, you can edit _/etc/ssh/sshd_config_ (on the *server*), + For *doas*, edit _/etc/doas.conf_ and add: + + *permit setenv { TERMINFO } :wheel* + + Or, if you are not in the *wheel* group, replace *:wheel* with + your username. + + For *ssh*, you can edit _/etc/ssh/sshd_config_ (on the *server*), and add: *SetEnv TERMINFO=*__ diff --git a/doc/footclient.1.scd b/doc/footclient.1.scd index 155683da..6d5839f0 100644 --- a/doc/footclient.1.scd +++ b/doc/footclient.1.scd @@ -153,15 +153,22 @@ The following environment variables are set in the child process: definitions in ncurses. Note that applications will search the default location(s) if *TERM* does not exist in *TERMINFO*. - Note that applications like sudo and ssh will remove this - environment variable. + Note that applications like *sudo*, *doas* and *ssh* may remove + this environment variable. - For sudo, you can create a file under _/etc/sudoers.d_ (name does - not matter) with the following content: + For *sudo*, you can create a file under _/etc/sudoers.d_ (name + does not matter) with the following content: *Defaults env_keep += "TERMINFO"* - For ssh, you can edit _/etc/ssh/sshd_config_ (on the *server*), + For *doas*, edit _/etc/doas.conf_ and add: + + *permit setenv { TERMINFO } :wheel* + + Or, if you are not in the *wheel* group, replace *:wheel* with + your username. + + For *ssh*, you can edit _/etc/ssh/sshd_config_ (on the *server*), and add: *SetEnv TERMINFO=*__ -- cgit v1.3 From 9434066546a8409117083bd64ad43f97a3a236e2 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 29 Aug 2021 11:06:45 +0200 Subject: meson: terminfo install location now defaults to $datadir/terminfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The meson command line option -Dcustom-terminfo-install-location has been changed in the following ways: * If unset, $datadir/terminfo is used, and TERMINFO is *not* exported * If set, that value (relative to $prefix) is used, and TERMINFO *is* exported. * The special value ‘no’ is removed. -Ddefault-terminfo now also changes the terminfo names generated when -Dterminfo=enabled. Furthermore, the documentation for the TERMINFO environment variable has been removed from the foot.1 and footclient.1 man pages (but as mentioned above, foot *will* still set it if -Dcustom-terminfo-install-location has been used). INSTALL.md has been updated to now recommend using ncurses’ terminfo definitions, if available. But also to document the other alternatives; installing the terminfo definitions in a custom location, or installing them with a diferent name. It also describes the general problem, and the disadvantages of each alternative (but without going into too much depth). --- INSTALL.md | 93 +++++++++++++++++++++++++++++----------------------- doc/foot.1.scd | 30 ----------------- doc/footclient.1.scd | 30 ----------------- foot.info | 10 +++--- meson.build | 32 +++++++++++------- meson_options.txt | 4 +-- 6 files changed, 79 insertions(+), 120 deletions(-) (limited to 'doc') diff --git a/INSTALL.md b/INSTALL.md index 81e9ec3e..6a380803 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -128,23 +128,35 @@ reasons for this: used by e.g. tmux. * New capabilities added to the `xterm-256color` terminfo could potentially break foot. +* There may be future additions or changes to foot’s terminfo. -As of ncurses 2021-07-31, ncurses ships a version of foot’s -terminfo. I still recommend building and installing the version -shipped with foot, since: +As of ncurses 2021-07-31, ncurses includes a version of foot’s +terminfo. **The recommendation is to use those**, and only install the +terminfo definitions from this git repo if the system’s ncurses +predates 2021-07-31. -* It will be more up to date (and more importantly, guaranteed to - match the installed version of foot). -* The ncurses version is missing several of the non-standard capabilities. +But, note that the foot terminfo definitions in ncurses’ lack the +non-standard capabilities. This mostly affects tmux; without them, +`terminal-overrides` must be configured to enable truecolor +support. For this reason, it _is_ possible to install “our” terminfo +definitions as well, either in a non-default location, or under a +different name. -Foot’s terminfo will by default be built, and installed along with -foot itself. This can be disabled (for example, to simplify packaging -when the terminfo definitions are packaged in a separate -package). Instructions on how to do so is in [terminfo](#terminfo). +Both have their set of issues. When installing to a non-default +location, foot will set the environment variable `TERMINFO` in the +child process. However, there are many situations where this simply +does not work. See https://codeberg.org/dnkl/foot/issues/695 for +details. -I recommend packaging foot’s terminfo files in a separate package, to -allow them to be installed on remote systems without having to install -foot itself. +Installing them under a different name generally works well, but will +break applications that check if `$TERM == foot`. + +Hence the recommendation to simply use ncurses’ terminfo definitions +if available. + +If packaging “our” terminfo definitions, I recommend doing that as a +separate package, to allow them to be installed on remote systems +without having to install foot itself. ### Setup @@ -158,44 +170,43 @@ mkdir -p bld/release && cd bld/release Available compile-time options: -| Option | Type | Default | Description | Extra dependencies | -|--------------------------------------|---------|----------------------------|----------------------------------|--------------------| -| `-Ddocs` | feature | `auto` | Builds and install documentation | scdoc | -| `-Dime` | bool | `true` | Enables IME support | None | -| `-Dgrapheme-clustering` | feature | `auto` | Enables grapheme clustering | libutf8proc | -| `-Dterminfo` | feature | `enabled` | Build and install terminfo files | tic (ncurses) | -| `-Ddefault-terminfo` | string | `foot` | Default value of `TERM` | none | -| `-Dcustom-terminfo-install-location` | string | `${datadir}/foot/terminfo` | Value to set `TERMINFO` to | None | +| Option | Type | Default | Description | Extra dependencies | +|--------------------------------------|---------|-----------------------|----------------------------------|--------------------| +| `-Ddocs` | feature | `auto` | Builds and install documentation | scdoc | +| `-Dime` | bool | `true` | Enables IME support | None | +| `-Dgrapheme-clustering` | feature | `auto` | Enables grapheme clustering | libutf8proc | +| `-Dterminfo` | feature | `enabled` | Build and install terminfo files | tic (ncurses) | +| `-Ddefault-terminfo` | string | `foot` | Default value of `TERM` | none | +| `-Dcustom-terminfo-install-location` | string | `${datadir}/terminfo` | Value to set `TERMINFO` to | None | Documentation includes the man pages, the example `foot.ini`, readme, changelog and license files. `-Ddefault-terminfo`: I strongly recommend leaving the default -value. This option is meant to be used as a last resort on platforms -where individual terminfo files cannot easily be installed. +value. Use this option if you plan on installing the terminfo files +under a different name. Setting this changes the default value of +`$TERM`, and the names of the terminfo files (if +`-Dterminfo=enabled`). `-Dcustom-terminfo-install-location` enables foot’s terminfo to -co-exist with ncurses’ version. The idea is that you install foot’s -terminfo to a non-standard location, for example -`/usr/share/foot/terminfo`. Use `-Dcustom-terminfo-install-location` -to tell foot where the terminfo is. Foot will set the environment -variable `TERMINFO` to this value (with `${prefix}` added). The value -is **relative to ${prefix}**. - -Conforming applications _should_ look in `TERMINFO` first, and -fallback to the builtin default (e.g. `/usr/share/terminfo`) if not -found. Thus, it will prefer foot’s version, if it exists (which it -typically will on localhost), and fallback to ncurses’ version if not -(e.g. on remote systems, where foot’s terminfo package has not been -installed). - -If set to `no`, foot will **not** set or modify `TERMINFO` at all. Use -this if you do not intend to use/support foot’s terminfo definitions -at all. +co-exist with ncurses’ version, without changing the terminfo +names. The idea is that you install foot’s terminfo to a non-standard +location, for example `/usr/share/foot/terminfo`. Use +`-Dcustom-terminfo-install-location` to tell foot where the terminfo +is. Foot will set the environment variable `TERMINFO` to this value +(with `${prefix}` added). The value is **relative to ${prefix}**. + +Note that there are several issues with this approach: +https://codeberg.org/dnkl/foot/issues/695. + +If left unset, foot will **not** set or modify `TERMINFO`. `-Dterminfo` can be used to disable building the terminfo definitions in the meson build. It does **not** change the default value of -`TERM`, and it does **not** disable `TERMINFO`. +`TERM`, and it does **not** disable `TERMINFO`, if +`-Dcustom-terminfo-install-location` has been set. Use this if +packaging the terminfo definitions in a separate package (and the +build script isn’t shared with the ‘foot’ package). Example: diff --git a/doc/foot.1.scd b/doc/foot.1.scd index 26fee4a1..bbe784bc 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -402,36 +402,6 @@ The following environment variables are set in the child process: set according to either the *--term* command-line option or the *term* config option in *foot.ini*(5). -*TERMINFO* - Path to foot's terminfo definitions. These are typically installed - in a non-standard location (though distributions may override - this), to allow them to co-exist with the foot terminfo - definitions in ncurses. Note that applications will search the - default location(s) if *TERM* does not exist in *TERMINFO*. - - Note that applications like *sudo*, *doas* and *ssh* may remove - this environment variable. - - For *sudo*, you can create a file under _/etc/sudoers.d_ (name - does not matter) with the following content: - - *Defaults env_keep += "TERMINFO"* - - For *doas*, edit _/etc/doas.conf_ and add: - - *permit setenv { TERMINFO } :wheel* - - Or, if you are not in the *wheel* group, replace *:wheel* with - your username. - - For *ssh*, you can edit _/etc/ssh/sshd_config_ (on the *server*), - and add: - - *SetEnv TERMINFO=*__ - - Where path is the location of the terminfo definitions on the - *server*, typically /usr/share/foot/terminfo. - *COLORTERM* This variable is set to *truecolor*, to indicate to client applications that 24-bit RGB colors are supported. diff --git a/doc/footclient.1.scd b/doc/footclient.1.scd index 6d5839f0..b252d5e1 100644 --- a/doc/footclient.1.scd +++ b/doc/footclient.1.scd @@ -146,36 +146,6 @@ The following environment variables are set in the child process: set according to either the *--term* command-line option or the *term* config option in *foot.ini*(5). -*TERMINFO* - Path to foot's terminfo definitions. These are typically installed - in a non-standard location (though distributions may override - this), to allow them to co-exist with the foot terminfo - definitions in ncurses. Note that applications will search the - default location(s) if *TERM* does not exist in *TERMINFO*. - - Note that applications like *sudo*, *doas* and *ssh* may remove - this environment variable. - - For *sudo*, you can create a file under _/etc/sudoers.d_ (name - does not matter) with the following content: - - *Defaults env_keep += "TERMINFO"* - - For *doas*, edit _/etc/doas.conf_ and add: - - *permit setenv { TERMINFO } :wheel* - - Or, if you are not in the *wheel* group, replace *:wheel* with - your username. - - For *ssh*, you can edit _/etc/ssh/sshd_config_ (on the *server*), - and add: - - *SetEnv TERMINFO=*__ - - Where path is the location of the terminfo definitions on the - *server*, typically /usr/share/foot/terminfo. - *COLORTERM* This variable is set to *truecolor*, to indicate to client applications that 24-bit RGB colors are supported. diff --git a/foot.info b/foot.info index 30e9e3de..f99e2aab 100644 --- a/foot.info +++ b/foot.info @@ -1,17 +1,17 @@ -foot|foot terminal emulator, - use=foot+base, +@default_terminfo@|foot terminal emulator, + use=@default_terminfo@+base, colors#256, setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48\:5\:%p1%d%;m, setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38\:5\:%p1%d%;m, -foot-direct|foot with direct color indexing, - use=foot+base, +@default_terminfo@-direct|foot with direct color indexing, + use=@default_terminfo@+base, colors#16777216, RGB, setab=\E[%?%p1%{8}%<%t4%p1%d%e48\:2\:\:%p1%{65536}%/%d\:%p1%{256}%/%{255}%&%d\:%p1%{255}%&%d%;m, setaf=\E[%?%p1%{8}%<%t3%p1%d%e38\:2\:\:%p1%{65536}%/%d\:%p1%{256}%/%{255}%&%d\:%p1%{255}%&%d%;m, -foot+base|foot base fragment, +@default_terminfo@+base|foot base fragment, am, bce, bw, diff --git a/meson.build b/meson.build index d9762f91..81dc9006 100644 --- a/meson.build +++ b/meson.build @@ -35,17 +35,15 @@ add_project_arguments( language: 'c', ) -default_terminfo_install_location = join_paths(get_option('datadir'), 'foot', 'terminfo') terminfo_install_location = get_option('custom-terminfo-install-location') -if terminfo_install_location == '' - terminfo_install_location = default_terminfo_install_location -endif -if terminfo_install_location != 'no' +if terminfo_install_location != '' add_project_arguments( ['-DFOOT_TERMINFO_PATH="@0@"'.format( join_paths(get_option('prefix'), terminfo_install_location))], language: 'c') +else + terminfo_install_location = join_paths(get_option('datadir'), 'terminfo') endif # Compute the relative path used by compiler invocations. @@ -246,15 +244,24 @@ endif tic = find_program('tic', native: true, required: get_option('terminfo')) if tic.found() + conf_data = configuration_data( + { + 'default_terminfo': get_option('default-terminfo'), + } + ) + + preprocessed = configure_file( + input: 'foot.info', + output: 'foot.info.preprocessed', + configuration: conf_data, + ) custom_target( 'terminfo', - output: 'f', - input: 'foot.info', - command: [tic, '-x', '-o', '@OUTDIR@', '-e', 'foot,foot-direct', '@INPUT@'], + output: get_option('default-terminfo')[0], + input: preprocessed, + command: [tic, '-x', '-o', '@OUTDIR@', '-e', '@0@,@0@-direct'.format(get_option('default-terminfo')), '@INPUT@'], install: true, - install_dir: (terminfo_install_location != 'no' - ? terminfo_install_location - : default_terminfo_install_location) + install_dir: terminfo_install_location ) endif @@ -267,8 +274,9 @@ summary( 'IME': get_option('ime'), 'Grapheme clustering': utf8proc.found(), 'Build terminfo': tic.found(), + 'Terminfo install location': terminfo_install_location, 'Default TERM': get_option('default-terminfo'), - 'Terminfo custom install location': terminfo_install_location, + 'Set TERMINFO': get_option('custom-terminfo-install-location') != '', }, bool_yn: true ) diff --git a/meson_options.txt b/meson_options.txt index d133f106..b47cfc7b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -11,5 +11,5 @@ option('terminfo', type: 'feature', value: 'enabled', description: 'Build and in option('default-terminfo', type: 'string', value: 'foot', description: 'Default value of the "term" option in foot.ini.') -option('custom-terminfo-install-location', type: 'string', - description: 'Path to foot\'s terminfo, relative to ${prefix}. If set to anything but “no“, foot will set TERMINFO to this value in the client process.') +option('custom-terminfo-install-location', type: 'string', value: '', + description: 'Path to foot\'s terminfo, relative to ${prefix}. If set, foot will set $TERMINFO to this value in the client process.') -- cgit v1.3 From 8ffc556d441013e06236f144020b91ea4e3a3f86 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 31 Aug 2021 19:42:22 +0200 Subject: main: verify primary font is monospaced at startup Load a couple of ASCII glyphs and check if their advance widths matches. If not, warn the user that the font is probably not monospaced. This can be disabled by setting tweak.font-monospace-warn=no. Closes #704. --- config.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ config.h | 4 ++++ doc/foot.ini.5.scd | 11 +++++++++++ main.c | 5 +++++ 4 files changed, 72 insertions(+) (limited to 'doc') diff --git a/config.c b/config.c index ac6dd24d..ca1278df 100644 --- a/config.c +++ b/config.c @@ -2452,6 +2452,9 @@ parse_section_tweak( conf->tweak.box_drawing_solid_shades ? "yes" : "no"); } + else if (strcmp(key, "font-monospace-warn") == 0) + conf->tweak.font_monospace_warn = str_to_bool(value); + else { LOG_AND_NOTIFY_ERR("%s:%u: [tweak]: %s: invalid key", path, lineno, key); return false; @@ -2957,6 +2960,7 @@ config_load(struct config *conf, const char *conf_path, .damage_whole_window = false, .box_drawing_base_thickness = 0.04, .box_drawing_solid_shades = true, + .font_monospace_warn = true, }, .notifications = tll_init(), @@ -3356,3 +3360,51 @@ config_font_list_destroy(struct config_font_list *font_list) font_list->count = 0; font_list->arr = NULL; } + + +bool +check_if_font_is_monospaced(const char *pattern, + user_notifications_t *notifications) +{ + struct fcft_font *f = fcft_from_name( + 1, (const char *[]){pattern}, ":size=8"); + + if (f == NULL) + return true; + + static const wchar_t chars[] = {L'a', L'i', L'l', L'M', L'W'}; + + bool is_monospaced = true; + int last_width = -1; + + for (size_t i = 0; i < sizeof(chars) / sizeof(chars[0]); i++) { + const struct fcft_glyph *g = fcft_glyph_rasterize( + f, chars[i], FCFT_SUBPIXEL_NONE); + + if (g == NULL) + continue; + + if (last_width >= 0 && g->advance.x != last_width) { + LOG_WARN("%s: font does not appear to be monospace; " + "check your config, or disable this warning by " + "setting [tweak].font-monospace-warn=no", + pattern); + + user_notification_add( + notifications, + USER_NOTIFICATION_WARNING, + "%s: font does not appear to be monospace; " + "check your config, or disable this warning by " + "settting \033[1m[tweak].font-monospace-warn=no\033[22m", + pattern); + + is_monospaced = false; + break; + } + + last_width = g->advance.x; + } + + fcft_destroy(f); + return is_monospaced; +} diff --git a/config.h b/config.h index 40daaf3b..6646cca3 100644 --- a/config.h +++ b/config.h @@ -253,6 +253,7 @@ struct config { off_t max_shm_pool_size; float box_drawing_base_thickness; bool box_drawing_solid_shades; + bool font_monospace_warn; } tweak; user_notifications_t notifications; @@ -269,3 +270,6 @@ struct config *config_clone(const struct config *old); bool config_font_parse(const char *pattern, struct config_font *font); void config_font_list_destroy(struct config_font_list *font_list); + +bool check_if_font_is_monospaced( + const char *pattern, user_notifications_t *notifications); diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 65a3a4dc..a124316e 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -1022,6 +1022,17 @@ any of these options. Default: _double-width_ +*font-monospace-warn* + Boolean. When enabled, foot will use heuristics to try to verify + the primary font is a monospace font, and warn if it is not. + + Disable this if you still want to use the font, even if foot + thinks it is not monospaced. + + You may also want to disable it to get slightly faster startup times. + + Default: _yes_ + *max-shm-pool-size-mb* This option controls the amount of virtual address space used by the pixmap memory to which the terminal screen content is diff --git a/main.c b/main.c index b036b9f6..4f7b027d 100644 --- a/main.c +++ b/main.c @@ -480,6 +480,11 @@ main(int argc, char *const *argv) conf.presentation_timings = presentation_timings; conf.hold_at_exit = hold; + if (conf.tweak.font_monospace_warn && conf.fonts[0].count > 0) { + check_if_font_is_monospaced( + conf.fonts[0].arr[0].pattern, &conf.notifications); + } + struct fdm *fdm = NULL; struct reaper *reaper = NULL; struct wayland *wayl = NULL; -- cgit v1.3 From b26fda7ef0e606d7a5f9e774548bdc282a3d7965 Mon Sep 17 00:00:00 2001 From: Arnavion Date: Wed, 8 Sep 2021 22:42:58 -0700 Subject: doc: Document that the default section can be reopened as [main] --- doc/foot.ini.5.scd | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index a124316e..6a9b5de5 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -6,8 +6,9 @@ foot.ini - configuration file for *foot*(1) # DESCRIPTION *foot* uses the standard _unix configuration format_, with section based -key/value pairs. The default section is unnamed (i.e. not prefixed -with a _[section]_). +key/value pairs. The default section is usually unnamed, i.e. not prefixed +with a _[section]_. However it can also be explicitly named _[main]_, +say if it needs to be reopened after any of the other sections. foot will search for a configuration file in the following locations, in this order: @@ -16,7 +17,7 @@ in this order: - *~/.config/foot/foot.ini* - *XDG_CONFIG_DIRS/foot/foot.ini* -# SECTION: default +# SECTION: main *shell* Executable to launch. Typically a shell. Default: _$SHELL_ if set, -- cgit v1.3 From ef7919e64d09d4b29a1557641883e78f5896841d Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Sat, 18 Sep 2021 23:40:40 +0100 Subject: main/client: add no-op "-e" command-line option --- CHANGELOG.md | 5 +++++ client.c | 8 ++++++-- doc/foot.1.scd | 10 ++++++++++ doc/footclient.1.scd | 4 ++++ main.c | 8 ++++++-- 5 files changed, 31 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b0c2011..d229c4ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,9 @@ (https://codeberg.org/dnkl/foot/issues/701). * Braille characters (U+2800 - U+28FF) are now rendered by foot itself (https://codeberg.org/dnkl/foot/issues/702). +* `-e` command-line option. This option is simply ignored, to appease + program launchers that blindly pass `-e` to any terminal emulator + (https://codeberg.org/dnkl/foot/issues/184). ### Changed @@ -67,6 +70,8 @@ ### Security ### Contributors +* [craigbarnes](https://codeberg.org/craigbarnes) + ## 1.9.0 diff --git a/client.c b/client.c index 7cfcb0ef..5c767e11 100644 --- a/client.c +++ b/client.c @@ -71,7 +71,8 @@ print_usage(const char *prog_name) " -o,--override=[section.]key=value override configuration option\n" " -d,--log-level={info|warning|error|none} log level (info)\n" " -l,--log-colorize=[{never|always|auto}] enable/disable colorization of log output on stderr\n" - " -v,--version show the version number and quit\n"; + " -v,--version show the version number and quit\n" + " -e ignored (for compatibility with xterm -e)\n"; printf("Usage: %s [OPTIONS...]\n", prog_name); printf("Usage: %s [OPTIONS...] command [ARGS...]\n", prog_name); @@ -145,7 +146,7 @@ main(int argc, char *const *argv) struct client_string *cargv = NULL; while (true) { - int c = getopt_long(argc, argv, "+t:T:a:w:W:mFLD:s:HNo:d:l::vh", longopts, NULL); + int c = getopt_long(argc, argv, "+t:T:a:w:W:mFLD:s:HNo:d:l::veh", longopts, NULL); if (c == -1) break; @@ -273,6 +274,9 @@ main(int argc, char *const *argv) ret = EXIT_SUCCESS; goto err; + case 'e': + break; + case '?': goto err; } diff --git a/doc/foot.1.scd b/doc/foot.1.scd index bbe784bc..91a7808a 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -141,6 +141,16 @@ the foot command line *-v*,*--version* Show the version number and quit. +*-e* + Ignored; for compatibility with *xterm -e*. + + This option was added in response to several program launchers + passing *-e* to arbitrary terminals, under the assumption that + they all implement the same semantics for it as *xterm*(1). + Ignoring it allows foot to be invoked as e.g. *foot -e man foot* + with the same results as with xterm, instead of producing an + "invalid option" error. + # EXIT STATUS Foot will exit with code 230 if there is a failure in foot itself. diff --git a/doc/footclient.1.scd b/doc/footclient.1.scd index b252d5e1..9cb4ef69 100644 --- a/doc/footclient.1.scd +++ b/doc/footclient.1.scd @@ -79,6 +79,10 @@ terminal has terminated. *-v*,*--version* Show the version number and quit +*-e* + Ignored; for compatibility with *xterm -e*. See *foot*(1) for more + details. + # EXIT STATUS Footlient will exit with code 220 if there is a failure in footclient diff --git a/main.c b/main.c index 7d4cbbcf..fd27aebd 100644 --- a/main.c +++ b/main.c @@ -78,7 +78,8 @@ print_usage(const char *prog_name) " -d,--log-level={info|warning|error|none} log level (info)\n" " -l,--log-colorize=[{never|always|auto}] enable/disable colorization of log output on stderr\n" " -s,--log-no-syslog disable syslog logging (only applicable in server mode)\n" - " -v,--version show the version number and quit\n"; + " -v,--version show the version number and quit\n" + " -e ignored (for compatibility with xterm -e)\n"; printf("Usage: %s [OPTIONS...]\n", prog_name); printf("Usage: %s [OPTIONS...] command [ARGS...]\n", prog_name); @@ -216,7 +217,7 @@ main(int argc, char *const *argv) config_override_t overrides = tll_init(); while (true) { - int c = getopt_long(argc, argv, "+c:Co:t:T:a:LD:f:w:W:s::HmFPp:d:l::Svh", longopts, NULL); + int c = getopt_long(argc, argv, "+c:Co:t:T:a:LD:f:w:W:s::HmFPp:d:l::Sveh", longopts, NULL); if (c == -1) break; @@ -375,6 +376,9 @@ main(int argc, char *const *argv) print_usage(prog_name); return EXIT_SUCCESS; + case 'e': + break; + case '?': return ret; } -- cgit v1.3 From 14e77fec32f0da5425cc0e688ed8cab85fcfa385 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 22 Sep 2021 22:00:28 +0200 Subject: doc: foot.ini: mention how dpi-aware interacts with bitmap fonts --- doc/foot.ini.5.scd | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 6a9b5de5..3e187042 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -145,11 +145,12 @@ in this order: Default: _no_. *dpi-aware* - *auto*, *yes*, or *no*. When set to *yes*, fonts are sized using - the monitor's DPI, making a font of a given size have the same - physical size, regardless of monitor. In other words, if you drag - a foot window between different monitors, the font size remains - the same. + *auto*, *yes*, or *no*. + + When set to *yes*, fonts are sized using the monitor's DPI, making + a font of a given size have the same physical size, regardless of + monitor. In other words, if you drag a foot window between + different monitors, the font size remains the same. In this mode, the monitor's scaling factor is ignored; doubling the scaling factor will *not* double the font size. @@ -162,6 +163,11 @@ in this order: DPI on monitors with a scaling factor of 1, but otherwise using the scaling factor. + Note that this option typically does not work with bitmap fonts, + which only contains a pre-defined set of sizes, and cannot be + dynamically scaled. Whichever size (of the available ones) that + best matches the DPI or scaling factor, will be used. + Default: _auto_ *pad* -- cgit v1.3 From ab34288e18132177ba991755f784305a19c5804d Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 22 Sep 2021 22:01:17 +0200 Subject: doc: foot.ini: mention how dpi-aware interacts with :pixelsize=N --- doc/foot.ini.5.scd | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 3e187042..32d838a7 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -168,6 +168,13 @@ in this order: dynamically scaled. Whichever size (of the available ones) that best matches the DPI or scaling factor, will be used. + Also note that if the font size has been specified in pixels + (*:pixelsize=*_N_, instead of *:size=*_N_), DPI scaling + (*dpi-aware=yes*) will have no effect (the specified pixel size + will be used as is). But, if the monitor's scaling factor is used + to size the font (*dpi-aware=no*), the font's pixel size will be + multiplied with the scaling factor. + Default: _auto_ *pad* -- cgit v1.3 From af1a01b2526be0b9ae36fb498c6faaba24d4a1c9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 22 Sep 2021 22:01:35 +0200 Subject: doc: foot.ini: font: add reference to dpi-aware option --- doc/foot.ini.5.scd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 32d838a7..aed491aa 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -37,7 +37,8 @@ in this order: Comma separated list of fonts to use, in fontconfig format. That is, a font name followed by a list of colon-separated options. Most noteworthy is *:size=n*, which is used to set the - font size. + font size. Note that the font size is also affected by the + *dpi-aware* option. Examples: - Dina:weight=bold:slant=italic -- cgit v1.3 From 2934a4e96c34cf81131005fd28fd0860da8c90fa Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 22 Sep 2021 22:04:30 +0200 Subject: doc: foot.ini: remove stray double quote character --- doc/foot.ini.5.scd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index aed491aa..ea4779c5 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -194,7 +194,7 @@ in this order: Default: _2x2_. *resize-delay-ms* - Time, in milliseconds, of "idle time" "before foot sends the new + Time, in milliseconds, of "idle time" before foot sends the new window dimensions to the client application while doing an interactive resize of a foot window. Idle time in this context is a period of time where the window size is not changing. -- cgit v1.3 From fb77637eb96a71de48b49e40fbe7dd71ec85bcbf Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 19 Sep 2021 11:58:34 +0200 Subject: term: only scale using DPI if *all* monitors have a scaling factor or one With dpi-aware=auto (the default), scale fonts using DPI *only* if *all* available monitors have a scaling factor of one. The idea is this: if a user, with multiple monitors, have enabled scaling on *at least* one monitor, he/she has most likely done so to match the size of his/hers other monitors. For example, if the user has one monitor with a scaling factor of one, and another one with a scaling factor of two, he/she expects things to be twice as large on the second monitor. If we (foot) scale using DPI on the first monitor, and using the scaling factor on the second monitor, foot will *not* look twice as big on the second monitor (this was the old behavior of dpi-aware=auto). Part of #714 --- CHANGELOG.md | 3 +++ README.md | 6 +++--- box-drawing.c | 4 ++-- doc/foot.ini.5.scd | 6 ++++-- terminal.c | 59 +++++++++++++++++++++++++++++++++++++----------------- terminal.h | 3 +-- wayland.c | 5 +++++ 7 files changed, 59 insertions(+), 27 deletions(-) (limited to 'doc') diff --git a/CHANGELOG.md b/CHANGELOG.md index d229c4ec..c08b29c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,9 @@ still exported, like before. * The default install location for the terminfo definitions have been changed back to `${datadir}/terminfo`. +* `dpi-aware=auto`: fonts are now scaled using the monitor’s DPI only + when **all** monitors have a scaling factor of one + (https://codeberg.org/dnkl/foot/issues/714). ### Deprecated diff --git a/README.md b/README.md index 93d783c4..d90302f8 100644 --- a/README.md +++ b/README.md @@ -347,9 +347,9 @@ This is not how it is meant to be. Fonts are measured in _point sizes_ all mediums, be it printers or monitors, regardless of their DPI. Foot’s default behavior is to use the monitor’s DPI to size fonts when -output scaling has been disabled. On monitors where output scaling has -been enabled, fonts will instead be sized using the scaling -factor. +output scaling has been disabled on **all** monitors. If at least one +monitor has output scaling enabled, fonts will instead by sized using +the scaling factor. This can be changed to either **always** use the monitor’s DPI (regardless of scaling factor), or to **never** use it, with the diff --git a/box-drawing.c b/box-drawing.c index 887aa0c9..3f8a38ef 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -2837,8 +2837,8 @@ box_drawing(const struct terminal *term, wchar_t wc) abort(); } - double dpi = term_font_sized_by_dpi(term, term->scale) ? term->font_dpi : 96.; - double scale = term_font_sized_by_scale(term, term->scale) ? term->scale : 1.; + double dpi = term->font_is_sized_by_dpi ? term->font_dpi : 96.; + double scale = term->font_is_sized_by_dpi ? 1. : term->scale; double cell_size = sqrt(pow(term->cell_width, 2) + pow(term->cell_height, 2)); int base_thickness = diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index ea4779c5..6bc93cc4 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -161,8 +161,10 @@ in this order: scaling factor *does* double the font size. Finally, if set to *auto*, fonts will be sized using the monitor's - DPI on monitors with a scaling factor of 1, but otherwise using - the scaling factor. + DPI if _all_ monitors have a scaling factor of 1. If at least one + monitor as a scaling factor larger than 1 (regardless of whether + the foot window is mapped on that monitor or not), fonts will be + scaled using the scaling factor. Note that this option typically does not work with bitmap fonts, which only contains a pre-defined set of sizes, and cannot be diff --git a/terminal.c b/terminal.c index e6837977..2738291d 100644 --- a/terminal.c +++ b/terminal.c @@ -813,25 +813,48 @@ get_font_subpixel(const struct terminal *term) return FCFT_SUBPIXEL_DEFAULT; } -bool -term_font_sized_by_dpi(const struct terminal *term, int scale) +static bool +term_font_size_by_dpi(const struct terminal *term) { - return term->conf->dpi_aware == DPI_AWARE_YES || - (term->conf->dpi_aware == DPI_AWARE_AUTO && scale <= 1); -} + switch (term->conf->dpi_aware) { + case DPI_AWARE_YES: return true; + case DPI_AWARE_NO: return false; -bool -term_font_sized_by_scale(const struct terminal *term, int scale) -{ - return !term_font_sized_by_dpi(term, scale); + case DPI_AWARE_AUTO: + /* + * Scale using DPI if all monitors have a scaling factor or 1. + * + * The idea is this: if a user, with multiple monitors, have + * enabled scaling on at least one monitor, then he/she has + * most likely done so to match the size of his/hers other + * monitors. + * + * I.e. if the user has one monitor with a scaling factor of + * one, and another with a scaling factor of two, he/she + * expects things to be twice as large on the second + * monitor. + * + * If we (foot) scale using DPI on the first monitor, and + * using the scaling factor on the second monitor, foot will + * *not* look twice as big on the second monitor. + */ + tll_foreach(term->wl->monitors, it) { + const struct monitor *mon = &it->item; + if (mon->scale > 1) + return false; + } + return true; + } + + BUG("unhandled DPI awareness value"); } int term_pt_or_px_as_pixels(const struct terminal *term, const struct pt_or_px *pt_or_px) { - double scale = term_font_sized_by_scale(term, term->scale) ? term->scale : 1.; - double dpi = term_font_sized_by_dpi(term, term->scale) ? term->font_dpi : 96.; + double scale = !term->font_is_sized_by_dpi ? term->scale : 1.; + double dpi = term->font_is_sized_by_dpi ? term->font_dpi : 96.; return pt_or_px->px == 0 ? round(pt_or_px->pt * scale * dpi / 72) @@ -878,8 +901,7 @@ reload_fonts(struct terminal *term) bool use_px_size = term->font_sizes[i][j].px_size > 0; char size[64]; - const int scale = - term_font_sized_by_scale(term, term->scale) ? term->scale : 1; + const int scale = term->font_is_sized_by_dpi ? 1 : term->scale; if (use_px_size) snprintf(size, sizeof(size), ":pixelsize=%d", @@ -914,7 +936,7 @@ reload_fonts(struct terminal *term) const size_t count_bold_italic = custom_bold_italic ? counts[3] : counts[0]; const char **names_bold_italic = (const char **)(custom_bold_italic ? names[3] : names[0]); - const bool use_dpi = term_font_sized_by_dpi(term, term->scale); + const bool use_dpi = term->font_is_sized_by_dpi; char *attrs[4] = {NULL}; int attr_len[4] = {-1, -1, -1, -1}; /* -1, so that +1 (below) results in 0 */ @@ -2008,8 +2030,8 @@ term_font_dpi_changed(struct terminal *term, int old_scale) float dpi = get_font_dpi(term); xassert(term->scale > 0); - bool was_scaled_using_dpi = term_font_sized_by_dpi(term, old_scale); - bool will_scale_using_dpi = term_font_sized_by_dpi(term, term->scale); + bool was_scaled_using_dpi = term->font_is_sized_by_dpi; + bool will_scale_using_dpi = term_font_size_by_dpi(term); bool need_font_reload = was_scaled_using_dpi != will_scale_using_dpi || @@ -2019,15 +2041,16 @@ term_font_dpi_changed(struct terminal *term, int old_scale) if (need_font_reload) { LOG_DBG("DPI/scale change: DPI-awareness=%s, " - "DPI: %.2f -> %.2f, scale: %d, " + "DPI: %.2f -> %.2f, scale: %d -> %d, " "sizing font based on monitor's %s", term->conf->dpi_aware == DPI_AWARE_AUTO ? "auto" : term->conf->dpi_aware == DPI_AWARE_YES ? "yes" : "no", - term->font_dpi, dpi, term->scale, + term->font_dpi, dpi, old_scale, term->scale, will_scale_using_dpi ? "DPI" : "scaling factor"); } term->font_dpi = dpi; + term->font_is_sized_by_dpi = will_scale_using_dpi; if (!need_font_reload) return true; diff --git a/terminal.h b/terminal.h index 028b4844..b3b4a90e 100644 --- a/terminal.h +++ b/terminal.h @@ -329,6 +329,7 @@ struct terminal { struct config_font *font_sizes[4]; struct pt_or_px font_line_height; float font_dpi; + bool font_is_sized_by_dpi; int16_t font_x_ofs; int16_t font_y_ofs; enum fcft_subpixel font_subpixel; @@ -660,8 +661,6 @@ bool term_font_size_reset(struct terminal *term); bool term_font_dpi_changed(struct terminal *term, int old_scale); void term_font_subpixel_changed(struct terminal *term); -bool term_font_sized_by_dpi(const struct terminal *term, int scale); -bool term_font_sized_by_scale(const struct terminal *term, int scale); int term_pt_or_px_as_pixels( const struct terminal *term, const struct pt_or_px *pt_or_px); diff --git a/wayland.c b/wayland.c index 911694ff..49c8ed92 100644 --- a/wayland.c +++ b/wayland.c @@ -340,6 +340,11 @@ update_terms_on_monitor(struct monitor *mon) tll_foreach(wayl->terms, it) { struct terminal *term = it->item; + if (term->conf->dpi_aware == DPI_AWARE_AUTO) { + update_term_for_output_change(term); + continue; + } + tll_foreach(term->window->on_outputs, it2) { if (it2->item == mon) { update_term_for_output_change(term); -- cgit v1.3