mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-29 07:58:01 -04:00
fonts: size fonts using the scaling factor when output scaling is enabled
This extends the new ‘dpi-aware’ option with a new default value, ‘auto’. When set to ‘auto’, fonts are sized using monitors’ DPI when output scaling is disabled. When output scaling is enabled, fonts are instead sized using the scaling factor. The reasoning here is that a user that has enabled output scaling is obviously *not* relying on DPI scaling. Output scaling can also be a way to compensate for different viewing distances, in which case we do *not* want to break that by using DPI scaling. Users can still force DPI-only font sizing by setting ‘dpi-aware=yes’, or disable it completely by setting ‘dpi-aware=no’.
This commit is contained in:
parent
69cd5fd3ab
commit
0a821f2ed4
5 changed files with 78 additions and 35 deletions
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -78,10 +78,13 @@ means foot can be PGO:d in e.g. sandboxed build scripts. See
|
||||||
* **bold-text-in-bright** option to `foot.ini`. When enabled, bold
|
* **bold-text-in-bright** option to `foot.ini`. When enabled, bold
|
||||||
text is rendered in a brighter color
|
text is rendered in a brighter color
|
||||||
(https://codeberg.org/dnkl/foot/issues/199).
|
(https://codeberg.org/dnkl/foot/issues/199).
|
||||||
* **dpi-aware** option to `foot.ini`. The default, **enabled**,
|
* **dpi-aware** option to `foot.ini`. The default, `auto`, sizes fonts
|
||||||
implements foot's old font sizing behavior. But, when **disabled**,
|
using the monitor’s DPI when output scaling has been
|
||||||
foot will ignore the monitors' DPI and instead size fonts using the
|
**disabled**. If output scaling has been **enabled**, fonts are
|
||||||
scale factor alone (https://codeberg.org/dnkl/foot/issues/206).
|
sized using the scaling factor. DPI-only font sizing can be forced
|
||||||
|
by setting `dpi-aware=yes`. Setting `dpi-aware=no` forces font
|
||||||
|
sizing to be based on the scaling factor.
|
||||||
|
(https://codeberg.org/dnkl/foot/issues/206).
|
||||||
* `-w,--window-size-pixels` and `-W,--window-size-chars` command line
|
* `-w,--window-size-pixels` and `-W,--window-size-chars` command line
|
||||||
options to `footclient` (https://codeberg.org/dnkl/foot/issues/189).
|
options to `footclient` (https://codeberg.org/dnkl/foot/issues/189).
|
||||||
* Short command line options for `--title`, `--maximized`,
|
* Short command line options for `--title`, `--maximized`,
|
||||||
|
|
|
||||||
10
config.c
10
config.c
|
|
@ -548,8 +548,12 @@ parse_section_main(const char *key, const char *value, struct config *conf,
|
||||||
free(copy);
|
free(copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "dpi-aware") == 0)
|
else if (strcmp(key, "dpi-aware") == 0) {
|
||||||
conf->dpi_aware = str_to_bool(value);
|
if (strcmp(value, "auto") == 0)
|
||||||
|
conf->dpi_aware = DPI_AWARE_AUTO;
|
||||||
|
else
|
||||||
|
conf->dpi_aware = str_to_bool(value) ? DPI_AWARE_YES : DPI_AWARE_NO;
|
||||||
|
}
|
||||||
|
|
||||||
else if (strcmp(key, "workers") == 0) {
|
else if (strcmp(key, "workers") == 0) {
|
||||||
unsigned long count;
|
unsigned long count;
|
||||||
|
|
@ -1959,7 +1963,7 @@ config_load(struct config *conf, const char *conf_path,
|
||||||
.bell_action = BELL_ACTION_NONE,
|
.bell_action = BELL_ACTION_NONE,
|
||||||
.startup_mode = STARTUP_WINDOWED,
|
.startup_mode = STARTUP_WINDOWED,
|
||||||
.fonts = {tll_init(), tll_init(), tll_init(), tll_init()},
|
.fonts = {tll_init(), tll_init(), tll_init(), tll_init()},
|
||||||
.dpi_aware = true, /* Use DPI by default, not scale factor */
|
.dpi_aware = DPI_AWARE_AUTO, /* DPI-aware when scaling-factor == 1 */
|
||||||
.scrollback = {
|
.scrollback = {
|
||||||
.lines = 1000,
|
.lines = 1000,
|
||||||
.indicator = {
|
.indicator = {
|
||||||
|
|
|
||||||
2
config.h
2
config.h
|
|
@ -80,7 +80,7 @@ struct config {
|
||||||
|
|
||||||
enum { STARTUP_WINDOWED, STARTUP_MAXIMIZED, STARTUP_FULLSCREEN } startup_mode;
|
enum { STARTUP_WINDOWED, STARTUP_MAXIMIZED, STARTUP_FULLSCREEN } startup_mode;
|
||||||
|
|
||||||
bool dpi_aware;
|
enum {DPI_AWARE_AUTO, DPI_AWARE_YES, DPI_AWARE_NO} dpi_aware;
|
||||||
config_font_list_t fonts[4];
|
config_font_list_t fonts[4];
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
|
||||||
|
|
@ -44,19 +44,24 @@ in this order:
|
||||||
*font-italic*, *font-bold-italic*).
|
*font-italic*, *font-bold-italic*).
|
||||||
|
|
||||||
*dpi-aware*
|
*dpi-aware*
|
||||||
Boolean. When enabled, fonts are sized using the monitor's DPI,
|
*auto*, *yes*, or *no*. When set to *yes*, fonts are sized using
|
||||||
making a font of a given size have the same physical size,
|
the monitor's DPI, making a font of a given size have the same
|
||||||
regardless of monitor. In other words, if you drag a foot window
|
physical size, regardless of monitor. In other words, if you drag
|
||||||
between different monitors, the font size remains the same.
|
a foot window between different monitors, the font size remains
|
||||||
|
the same.
|
||||||
|
|
||||||
In this mode, the monitor's scale factor is ignored; doubling the
|
In this mode, the monitor's scaling factor is ignored; doubling
|
||||||
scale factor will *not* double the font size.
|
the scaling factor will *not* double the font size.
|
||||||
|
|
||||||
When disabled, the monitor's DPI is ignored. The font is instead
|
When set to *no*, the monitor's DPI is ignored. The font is
|
||||||
sized using the monitor's scale factor; doubling the scale factor
|
instead sized using the monitor's scaling factor; doubling the
|
||||||
*does* double the font size.
|
scaling factor *does* double the font size.
|
||||||
|
|
||||||
Default: _yes_
|
Finally, if set to *auto*, fonts will be sized using the monitor's
|
||||||
|
DPI on monitors with a scaling factor of 1, but otherwise size
|
||||||
|
fonts using the scaling factor.
|
||||||
|
|
||||||
|
Default: _auto_
|
||||||
|
|
||||||
*pad*
|
*pad*
|
||||||
Padding between border and glyphs, in pixels (subject to output
|
Padding between border and glyphs, in pixels (subject to output
|
||||||
|
|
|
||||||
61
terminal.c
61
terminal.c
|
|
@ -776,6 +776,26 @@ get_font_subpixel(const struct terminal *term)
|
||||||
return FCFT_SUBPIXEL_DEFAULT;
|
return FCFT_SUBPIXEL_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
font_should_size_by_dpi(const struct terminal *term, int new_scale)
|
||||||
|
{
|
||||||
|
return term->conf->dpi_aware == DPI_AWARE_YES ||
|
||||||
|
(term->conf->dpi_aware == DPI_AWARE_AUTO && new_scale <= 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
font_size_by_dpi(const struct terminal *term)
|
||||||
|
{
|
||||||
|
return font_should_size_by_dpi(term, term->font_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
font_size_by_scale(const struct terminal *term)
|
||||||
|
{
|
||||||
|
return !font_size_by_dpi(term);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct font_load_data {
|
struct font_load_data {
|
||||||
size_t count;
|
size_t count;
|
||||||
const char **names;
|
const char **names;
|
||||||
|
|
@ -812,7 +832,7 @@ reload_fonts(struct terminal *term)
|
||||||
bool use_px_size = term->font_sizes[i][j].px_size > 0;
|
bool use_px_size = term->font_sizes[i][j].px_size > 0;
|
||||||
char size[64];
|
char size[64];
|
||||||
|
|
||||||
const int scale = term->conf->dpi_aware ? 1 : term->scale;
|
const int scale = font_size_by_scale(term) ? term->scale : 1;
|
||||||
|
|
||||||
if (use_px_size)
|
if (use_px_size)
|
||||||
snprintf(size, sizeof(size), ":pixelsize=%d",
|
snprintf(size, sizeof(size), ":pixelsize=%d",
|
||||||
|
|
@ -848,7 +868,7 @@ reload_fonts(struct terminal *term)
|
||||||
const size_t count_bold_italic = custom_bold_italic ? counts[3] : counts[0];
|
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 char **names_bold_italic = (const char **)(custom_bold_italic ? names[3] : names[0]);
|
||||||
|
|
||||||
const bool use_dpi = term->conf->dpi_aware;
|
const bool use_dpi = font_size_by_dpi(term);
|
||||||
|
|
||||||
char *attrs[4] = {NULL};
|
char *attrs[4] = {NULL};
|
||||||
int attr_len[4] = {-1, -1, -1, -1}; /* -1, so that +1 (below) results in 0 */
|
int attr_len[4] = {-1, -1, -1, -1}; /* -1, so that +1 (below) results in 0 */
|
||||||
|
|
@ -1673,23 +1693,34 @@ term_font_size_reset(struct terminal *term)
|
||||||
bool
|
bool
|
||||||
term_font_dpi_changed(struct terminal *term)
|
term_font_dpi_changed(struct terminal *term)
|
||||||
{
|
{
|
||||||
if (term->conf->dpi_aware) {
|
float dpi = get_font_dpi(term);
|
||||||
float dpi = get_font_dpi(term);
|
int scale = get_font_scale(term);
|
||||||
if (dpi == term->font_dpi)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
LOG_DBG("DPI changed (%.2f -> %.2f): reloading fonts", term->font_dpi, dpi);
|
bool was_scaled_using_dpi = font_size_by_dpi(term);
|
||||||
term->font_dpi = dpi;
|
bool will_scale_using_dpi = font_should_size_by_dpi(term, scale);
|
||||||
} else {
|
|
||||||
int scale = get_font_scale(term);
|
|
||||||
if (scale == term->font_scale)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
LOG_DBG("scale factor changed (%d -> %d): reloading fonts",
|
bool need_font_reload =
|
||||||
term->font_scale, scale);
|
was_scaled_using_dpi != will_scale_using_dpi ||
|
||||||
term->font_scale = scale;
|
(will_scale_using_dpi
|
||||||
|
? term->font_dpi != dpi
|
||||||
|
: term->font_scale != scale);
|
||||||
|
|
||||||
|
if (need_font_reload) {
|
||||||
|
LOG_DBG("DPI/scale change: DPI-awareness=%s, "
|
||||||
|
"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_ON ? "yes" : "no",
|
||||||
|
term->font_dpi, dpi, term->font_scale, scale,
|
||||||
|
will_scale_using_dpi ? "DPI" : "scaling factor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
term->font_dpi = dpi;
|
||||||
|
term->font_scale = scale;
|
||||||
|
|
||||||
|
if (!need_font_reload)
|
||||||
|
return true;
|
||||||
|
|
||||||
return reload_fonts(term);
|
return reload_fonts(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue