aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-02-09 10:24:50 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-02-09 10:24:50 +0000
commit8955875584714ece0929840eb941f33e068f1f69 (patch)
tree177e86a4977efcb5801e8d1e1a723648ef357e8b /terminal.c
parentterm: reduce max number of iterations when trying to drain client (diff)
parentmeson/PKGBUILD: adjust fcft requirements; the new version is 1.1.1 (diff)
Merge branch 'text-resize'
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c87
1 files changed, 80 insertions, 7 deletions
diff --git a/terminal.c b/terminal.c
index ad8ba085..a07b1912 100644
--- a/terminal.c
+++ b/terminal.c
@@ -507,7 +507,8 @@ initialize_render_workers(struct terminal *term)
}
static bool
-initialize_fonts(struct terminal *term, const struct config *conf)
+initialize_fonts(const struct terminal *term, const struct config *conf,
+ struct font *fonts[static 4])
{
const size_t count = tll_length(conf->fonts);
const char *names[count];
@@ -529,11 +530,21 @@ initialize_fonts(struct terminal *term, const struct config *conf)
snprintf(attrs2, sizeof(attrs2), "dpi=%u:slant=italic", dpi);
snprintf(attrs3, sizeof(attrs3), "dpi=%u:weight=bold:slant=italic", dpi);
- return (
- (term->fonts[0] = font_from_name(count, names, attrs0)) != NULL &&
- (term->fonts[1] = font_from_name(count, names, attrs1)) != NULL &&
- (term->fonts[2] = font_from_name(count, names, attrs2)) != NULL &&
- (term->fonts[3] = font_from_name(count, names, attrs3)) != NULL);
+ fonts[0] = fonts[1] = fonts[2] = fonts[3] = NULL;
+ bool ret =
+ (fonts[0] = font_from_name(count, names, attrs0)) != NULL &&
+ (fonts[1] = font_from_name(count, names, attrs1)) != NULL &&
+ (fonts[2] = font_from_name(count, names, attrs2)) != NULL &&
+ (fonts[3] = font_from_name(count, names, attrs3)) != NULL;
+
+ if (!ret) {
+ for (size_t i = 0; i < 4; i++) {
+ font_destroy(fonts[i]);
+ fonts[i] = NULL;
+ }
+ }
+
+ return ret;
}
struct terminal *
@@ -603,6 +614,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
/* Initialize configure-based terminal attributes */
*term = (struct terminal) {
.fdm = fdm,
+ .conf = conf,
.quit = false,
.ptmx = ptmx,
.ptmx_buffer = tll_init(),
@@ -696,7 +708,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
initialize_color_cube(term);
if (!initialize_render_workers(term))
goto err;
- if (!initialize_fonts(term, conf))
+ if (!initialize_fonts(term, conf, term->fonts))
goto err;
/* Cell dimensions are based on the font metrics. Obviously */
@@ -1099,6 +1111,67 @@ term_reset(struct terminal *term, bool hard)
term_damage_all(term);
}
+static void
+term_set_fonts(struct terminal *term, struct font *fonts[static 4])
+{
+ for (size_t i = 0; i < 4; i++) {
+ assert(fonts[i] != NULL);
+
+ font_destroy(term->fonts[i]);
+ term->fonts[i] = fonts[i];
+ }
+
+ term->cell_width = term->fonts[0]->space_x_advance > 0
+ ? term->fonts[0]->space_x_advance : term->fonts[0]->max_x_advance;
+ term->cell_height = term->fonts[0]->height;
+ LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height);
+
+ render_resize_force(term, term->width, term->height);
+}
+
+static void
+term_font_size_adjust(struct terminal *term, double amount)
+{
+ struct font *fonts[4] = {
+ font_size_adjust(term->fonts[0], amount),
+ font_size_adjust(term->fonts[1], amount),
+ font_size_adjust(term->fonts[2], amount),
+ font_size_adjust(term->fonts[3], amount),
+ };
+
+ if (fonts[0] == NULL || fonts[1] == NULL ||
+ fonts[2] == NULL || fonts[3] == NULL)
+ {
+ for (size_t i = 0; i < 4; i++)
+ font_destroy(fonts[i]);
+ return;
+ }
+
+ term_set_fonts(term, fonts);
+}
+
+void
+term_font_size_increase(struct terminal *term)
+{
+ term_font_size_adjust(term, 1.);
+}
+
+void
+term_font_size_decrease(struct terminal *term)
+{
+ term_font_size_adjust(term, -1.);
+}
+
+void
+term_font_size_reset(struct terminal *term)
+{
+ struct font *fonts[4];
+ if (!initialize_fonts(term, term->conf, fonts))
+ return;
+
+ term_set_fonts(term, fonts);
+}
+
void
term_damage_rows(struct terminal *term, int start, int end)
{