diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-10-01 18:50:32 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-10-01 18:50:32 +0000 |
| commit | a082fec786d44bfbe8d2172c6317121027735a6b (patch) | |
| tree | cf2a9fc4a822f4701a0a90db41b1c3ac03dd333a /terminal.c | |
| parent | meson/pkgbuild: bump version to 1.9.0 (diff) | |
| parent | Merge branch 'hacktober-theme' (diff) | |
Merge branch 'master' into releases/1.9
Diffstat (limited to 'terminal.c')
| -rw-r--r-- | terminal.c | 116 |
1 files changed, 82 insertions, 34 deletions
@@ -230,13 +230,11 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data) } uint8_t buf[24 * 1024]; - ssize_t count = sizeof(buf); - const size_t max_iterations = !hup ? 10 : (size_t)-1ll; for (size_t i = 0; i < max_iterations && pollin; i++) { xassert(pollin); - count = read(term->ptmx, buf, sizeof(buf)); + ssize_t count = read(term->ptmx, buf, sizeof(buf)); if (count < 0) { if (errno == EAGAIN || errno == EIO) { @@ -628,15 +626,28 @@ err_sem_destroy: } static void -free_box_drawing(struct fcft_glyph **box_drawing) +free_custom_glyph(struct fcft_glyph **glyph) { - if (*box_drawing == NULL) + if (*glyph == NULL) return; - free(pixman_image_get_data((*box_drawing)->pix)); - pixman_image_unref((*box_drawing)->pix); - free(*box_drawing); - *box_drawing = NULL; + free(pixman_image_get_data((*glyph)->pix)); + pixman_image_unref((*glyph)->pix); + free(*glyph); + *glyph = NULL; +} + +static void +free_custom_glyphs(struct fcft_glyph ***glyphs, size_t count) +{ + if (*glyphs == NULL) + return; + + for (size_t i = 0; i < count; i++) + free_custom_glyph(&(*glyphs)[i]); + + free(*glyphs); + *glyphs = NULL; } static bool @@ -649,18 +660,27 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4]) term->fonts[i] = fonts[i]; } - for (size_t i = 0; i < ALEN(term->box_drawing); i++) - free_box_drawing(&term->box_drawing[i]); + free_custom_glyphs( + &term->custom_glyphs.box_drawing, GLYPH_BOX_DRAWING_COUNT); + free_custom_glyphs( + &term->custom_glyphs.braille, GLYPH_BRAILLE_COUNT); + free_custom_glyphs( + &term->custom_glyphs.legacy, GLYPH_LEGACY_COUNT); const int old_cell_width = term->cell_width; const int old_cell_height = term->cell_height; const struct config *conf = term->conf; + const struct fcft_glyph *M = fcft_glyph_rasterize( + term->fonts[0], L'M', term->font_subpixel); + term->cell_width = - (term->fonts[0]->space_advance.x > 0 - ? term->fonts[0]->space_advance.x - : term->fonts[0]->max_advance.x) + (M != NULL + ? M->advance.x + : (term->fonts[0]->space_advance.x > 0 + ? term->fonts[0]->space_advance.x + : term->fonts[0]->max_advance.x)) + term_pt_or_px_as_pixels(term, &conf->letter_spacing); term->cell_height = term->font_line_height.px >= 0 @@ -793,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) @@ -858,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", @@ -894,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 */ @@ -1587,8 +1629,13 @@ term_destroy(struct terminal *term) for (size_t i = 0; i < 4; i++) free(term->font_sizes[i]); - for (size_t i = 0; i < ALEN(term->box_drawing); i++) - free_box_drawing(&term->box_drawing[i]); + + free_custom_glyphs( + &term->custom_glyphs.box_drawing, GLYPH_BOX_DRAWING_COUNT); + free_custom_glyphs( + &term->custom_glyphs.braille, GLYPH_BRAILLE_COUNT); + free_custom_glyphs( + &term->custom_glyphs.legacy, GLYPH_LEGACY_COUNT); free(term->search.buf); @@ -1983,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 || @@ -1994,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; |
