mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
term: get rid of term->font_scale, use term->scale only
We only needed term->font_scale to be able to detect scaling factor changes (term->font_scale != term->scale). But, we already have the old scaling factor in all places where term_font_dpi_changed() is called, so let’s pass the old scaling factor as an argument instead.
This commit is contained in:
parent
e7c01f3e52
commit
2afc678236
3 changed files with 16 additions and 22 deletions
31
terminal.c
31
terminal.c
|
|
@ -769,22 +769,16 @@ get_font_subpixel(const struct terminal *term)
|
|||
}
|
||||
|
||||
static bool
|
||||
font_size_by_dpi_for_scale(const struct terminal *term, int new_scale)
|
||||
font_sized_by_dpi(const struct terminal *term, int scale)
|
||||
{
|
||||
return term->conf->dpi_aware == DPI_AWARE_YES ||
|
||||
(term->conf->dpi_aware == DPI_AWARE_AUTO && new_scale <= 1);
|
||||
(term->conf->dpi_aware == DPI_AWARE_AUTO && scale <= 1);
|
||||
}
|
||||
|
||||
static bool
|
||||
font_sized_by_dpi(const struct terminal *term)
|
||||
font_sized_by_scale(const struct terminal *term, int scale)
|
||||
{
|
||||
return font_size_by_dpi_for_scale(term, term->font_scale);
|
||||
}
|
||||
|
||||
static bool
|
||||
font_sized_by_scale(const struct terminal *term)
|
||||
{
|
||||
return !font_sized_by_dpi(term);
|
||||
return !font_sized_by_dpi(term, scale);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -824,7 +818,8 @@ reload_fonts(struct terminal *term)
|
|||
bool use_px_size = term->font_sizes[i][j].px_size > 0;
|
||||
char size[64];
|
||||
|
||||
const int scale = font_sized_by_scale(term) ? term->scale : 1;
|
||||
const int scale =
|
||||
font_sized_by_scale(term, term->scale) ? term->scale : 1;
|
||||
|
||||
if (use_px_size)
|
||||
snprintf(size, sizeof(size), ":pixelsize=%d",
|
||||
|
|
@ -860,7 +855,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 = font_sized_by_dpi(term);
|
||||
const bool use_dpi = font_sized_by_dpi(term, term->scale);
|
||||
|
||||
char *attrs[4] = {NULL};
|
||||
int attr_len[4] = {-1, -1, -1, -1}; /* -1, so that +1 (below) results in 0 */
|
||||
|
|
@ -1043,7 +1038,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
|||
xmalloc(sizeof(term->font_sizes[3][0]) * tll_length(conf->fonts[3])),
|
||||
},
|
||||
.font_dpi = 0.,
|
||||
.font_scale = 0,
|
||||
.font_subpixel = (conf->colors.alpha == 0xffff /* Can't do subpixel rendering on transparent background */
|
||||
? FCFT_SUBPIXEL_DEFAULT
|
||||
: FCFT_SUBPIXEL_NONE),
|
||||
|
|
@ -1169,7 +1163,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
|||
goto err;
|
||||
|
||||
/* Load fonts */
|
||||
if (!term_font_dpi_changed(term))
|
||||
if (!term_font_dpi_changed(term, 0))
|
||||
goto err;
|
||||
|
||||
term->font_subpixel = get_font_subpixel(term);
|
||||
|
|
@ -1770,19 +1764,19 @@ term_font_size_reset(struct terminal *term)
|
|||
}
|
||||
|
||||
bool
|
||||
term_font_dpi_changed(struct terminal *term)
|
||||
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 = font_sized_by_dpi(term);
|
||||
bool will_scale_using_dpi = font_size_by_dpi_for_scale(term, term->scale);
|
||||
bool was_scaled_using_dpi = font_sized_by_dpi(term, old_scale);
|
||||
bool will_scale_using_dpi = font_sized_by_dpi(term, term->scale);
|
||||
|
||||
bool need_font_reload =
|
||||
was_scaled_using_dpi != will_scale_using_dpi ||
|
||||
(will_scale_using_dpi
|
||||
? term->font_dpi != dpi
|
||||
: term->font_scale != term->scale);
|
||||
: old_scale != term->scale);
|
||||
|
||||
if (need_font_reload) {
|
||||
LOG_DBG("DPI/scale change: DPI-awareness=%s, "
|
||||
|
|
@ -1795,7 +1789,6 @@ term_font_dpi_changed(struct terminal *term)
|
|||
}
|
||||
|
||||
term->font_dpi = dpi;
|
||||
term->font_scale = term->scale;
|
||||
|
||||
if (!need_font_reload)
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -320,7 +320,6 @@ struct terminal {
|
|||
struct config_font *font_sizes[4];
|
||||
struct pt_or_px font_line_height;
|
||||
float font_dpi;
|
||||
int font_scale; /* scaling factor last time we loaded fonts */
|
||||
int16_t font_x_ofs;
|
||||
int16_t font_y_ofs;
|
||||
enum fcft_subpixel font_subpixel;
|
||||
|
|
@ -614,7 +613,7 @@ bool term_paste_data_to_slave(
|
|||
bool term_font_size_increase(struct terminal *term);
|
||||
bool term_font_size_decrease(struct terminal *term);
|
||||
bool term_font_size_reset(struct terminal *term);
|
||||
bool term_font_dpi_changed(struct terminal *term);
|
||||
bool term_font_dpi_changed(struct terminal *term, int old_scale);
|
||||
void term_font_subpixel_changed(struct terminal *term);
|
||||
int term_pt_or_px_as_pixels(
|
||||
const struct terminal *term, const struct pt_or_px *pt_or_px);
|
||||
|
|
|
|||
|
|
@ -285,8 +285,10 @@ update_term_for_output_change(struct terminal *term)
|
|||
if (tll_length(term->window->on_outputs) == 0)
|
||||
return;
|
||||
|
||||
int old_scale = term->scale;
|
||||
|
||||
render_resize(term, term->width / term->scale, term->height / term->scale);
|
||||
term_font_dpi_changed(term);
|
||||
term_font_dpi_changed(term, old_scale);
|
||||
term_font_subpixel_changed(term);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue