From 9e2ca2b1a3603b58a138ad99d5606df264cc163f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 8 Feb 2020 14:08:16 +0100 Subject: [PATCH 1/9] render: add render_resize_force() This forces a full resize operation, even though actual window size (or scale) hasn't changed. --- render.c | 23 ++++++++++++++++++----- render.h | 2 ++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/render.c b/render.c index f97a957f..980d5fe2 100644 --- a/render.c +++ b/render.c @@ -995,10 +995,10 @@ reflow(struct row **new_grid, int new_cols, int new_rows, } /* Move to terminal.c? */ -void -render_resize(struct terminal *term, int width, int height) +static void +maybe_resize(struct terminal *term, int width, int height, bool force) { - if (width == 0 || height == 0) + if (!force && (width == 0 || height == 0)) return; int scale = -1; @@ -1015,12 +1015,12 @@ render_resize(struct terminal *term, int width, int height) width *= scale; height *= scale; - if (width == 0 && height == 0) { + if (!force && width == 0 && height == 0) { /* Assume we're not fully up and running yet */ return; } - if (width == term->width && height == term->height && scale == term->scale) + if (!force && width == term->width && height == term->height && scale == term->scale) return; /* Cancel an application initiated "Synchronized Update" */ @@ -1124,10 +1124,23 @@ render_resize(struct terminal *term, int width, int height) term->render.last_cursor.cell = NULL; + term->render.last_buf = NULL; term_damage_view(term); render_refresh(term); } +void +render_resize(struct terminal *term, int width, int height) +{ + return maybe_resize(term, width, height, false); +} + +void +render_resize_force(struct terminal *term, int width, int height) +{ + return maybe_resize(term, width, height, true); +} + static void xcursor_callback( void *data, struct wl_callback *wl_callback, uint32_t callback_data); diff --git a/render.h b/render.h index 43f5314e..3bd52fa5 100644 --- a/render.h +++ b/render.h @@ -9,6 +9,8 @@ struct renderer *render_init(struct fdm *fdm, struct wayland *wayl); void render_destroy(struct renderer *renderer); void render_resize(struct terminal *term, int width, int height); +void render_resize_force(struct terminal *term, int width, int height); + void render_set_title(struct terminal *term, const char *title); void render_refresh(struct terminal *term); bool render_xcursor_set(struct terminal *term); From 89cca2a5d1015670ee2fd335c7b38e8aabdaed44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 8 Feb 2020 14:09:06 +0100 Subject: [PATCH 2/9] term: add term_font_size_{increase,decrease}() --- terminal.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ terminal.h | 16 ++++++++++------ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/terminal.c b/terminal.c index ad8ba085..75b400d3 100644 --- a/terminal.c +++ b/terminal.c @@ -603,6 +603,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(), @@ -1099,6 +1100,49 @@ term_reset(struct terminal *term, bool hard) term_damage_all(term); } +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; + } + + for (size_t i = 0; i < 4; i++) { + 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); +} + +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_damage_rows(struct terminal *term, int start, int end) { diff --git a/terminal.h b/terminal.h index cf691f5e..e98b14c1 100644 --- a/terminal.h +++ b/terminal.h @@ -175,11 +175,18 @@ struct ptmx_buffer { struct terminal { struct fdm *fdm; + const struct config *conf; pid_t slave; int ptmx; bool quit; + struct grid normal; + struct grid alt; + struct grid *grid; + + struct font *fonts[4]; + tll(struct ptmx_buffer) ptmx_buffer; enum cursor_keys cursor_keys_mode; @@ -277,12 +284,6 @@ struct terminal { size_t match_len; } search; - struct grid normal; - struct grid alt; - struct grid *grid; - - struct font *fonts[4]; - struct { bool esc_prefix; bool eight_bit; @@ -362,6 +363,9 @@ int term_destroy(struct terminal *term); void term_reset(struct terminal *term, bool hard); bool term_to_slave(struct terminal *term, const void *data, size_t len); +void term_font_size_increase(struct terminal *term); +void term_font_size_decrease(struct terminal *term); + void term_damage_rows(struct terminal *term, int start, int end); void term_damage_rows_in_view(struct terminal *term, int start, int end); From 7ca8f85cd028825a4133a7cf16f70c059b54aa93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 8 Feb 2020 14:09:28 +0100 Subject: [PATCH 3/9] input: hook ctrl+{plus/KP-Add/minus/KP-Subtract} to term_font_size_{increase,decrease} --- input.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/input.c b/input.c index 2a4322c9..bb225f0c 100644 --- a/input.c +++ b/input.c @@ -385,6 +385,18 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, } } + else if (effective_mods == ctrl) { + if (sym == XKB_KEY_plus || sym == XKB_KEY_KP_Add) { + term_font_size_increase(term); + goto maybe_repeat; + } + + else if (sym == XKB_KEY_minus || sym == XKB_KEY_KP_Subtract) { + term_font_size_decrease(term); + goto maybe_repeat; + } + } + else if (effective_mods == (shift | ctrl)) { if (sym == XKB_KEY_C) { selection_to_clipboard(term, serial); From a96341368d737b0497a341417d4c4e399eda9d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 8 Feb 2020 14:10:18 +0100 Subject: [PATCH 4/9] meson/PKGBUILD: bump fcft required version to 1.2.0 --- PKGBUILD | 2 +- meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 720990c3..f5136be9 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -5,7 +5,7 @@ arch=('x86_64') url=https://codeberg.org/dnkl/foot license=(mit) makedepends=('meson' 'ninja' 'scdoc' 'python' 'ncurses' 'wayland-protocols' 'tllist>=1.0.0') -depends=('libxkbcommon' 'wayland' 'pixman' 'fcft>=1.1.0') +depends=('libxkbcommon' 'wayland' 'pixman' 'fcft>=1.2.0') source=() pkgver() { diff --git a/meson.build b/meson.build index 00933df3..083bce70 100644 --- a/meson.build +++ b/meson.build @@ -25,7 +25,7 @@ wayland_cursor = dependency('wayland-cursor') xkb = dependency('xkbcommon') tllist = dependency('tllist', version: '>=1.0.0', fallback: ['tllist', 'tllist']) -fcft = dependency('fcft', version: ['>=1.1.0', '<1.2.0'], fallback: ['fcft', 'fcft']) +fcft = dependency('fcft', version: ['>=1.2.0', '<1.3.0'], fallback: ['fcft', 'fcft']) wayland_protocols_datadir = wayland_protocols.get_pkgconfig_variable('pkgdatadir') From 6c0d00fcee760be86d13366cf5d1fbf9a78a34b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 8 Feb 2020 17:57:50 +0100 Subject: [PATCH 5/9] term: add term_font_size_reset() --- terminal.c | 45 ++++++++++++++++++++++++++++++++++++++------- terminal.h | 1 + 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/terminal.c b/terminal.c index 75b400d3..72d98104 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 * @@ -697,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 */ @@ -1143,6 +1154,26 @@ 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; + + for (size_t i = 0; i < 4; i++) { + 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); +} + void term_damage_rows(struct terminal *term, int start, int end) { diff --git a/terminal.h b/terminal.h index e98b14c1..b4ce1212 100644 --- a/terminal.h +++ b/terminal.h @@ -365,6 +365,7 @@ bool term_to_slave(struct terminal *term, const void *data, size_t len); void term_font_size_increase(struct terminal *term); void term_font_size_decrease(struct terminal *term); +void term_font_size_reset(struct terminal *term); void term_damage_rows(struct terminal *term, int start, int end); void term_damage_rows_in_view(struct terminal *term, int start, int end); From 1b81c700f94fa4571cab088e1a2e052dc1ab0dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 8 Feb 2020 17:58:06 +0100 Subject: [PATCH 6/9] input: hook ctrl+{=,0} to term_font_size_reset() --- input.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/input.c b/input.c index bb225f0c..21fc6f37 100644 --- a/input.c +++ b/input.c @@ -395,6 +395,11 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, term_font_size_decrease(term); goto maybe_repeat; } + + else if (sym == XKB_KEY_0 || sym == XKB_KEY_equal || sym == XKB_KEY_KP_Equal || sym == XKB_KEY_KP_0) { + term_font_size_reset(term); + goto maybe_repeat; + } } else if (effective_mods == (shift | ctrl)) { From fd5782d6e621df346cea01df0f306b8d634f6e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 8 Feb 2020 18:22:14 +0100 Subject: [PATCH 7/9] render: resize: reset scroll damage We've resized, and reset the render's 'last-buf' pointer; any scroll damage we have is **not** valid anymore. --- render.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/render.c b/render.c index 980d5fe2..7fa7dd86 100644 --- a/render.c +++ b/render.c @@ -1123,7 +1123,8 @@ maybe_resize(struct terminal *term, int width, int height, bool force) min(term->cursor.point.col, term->cols - 1)); term->render.last_cursor.cell = NULL; - + tll_free(term->normal.scroll_damage); + tll_free(term->alt.scroll_damage); term->render.last_buf = NULL; term_damage_view(term); render_refresh(term); From 1dfd121c449d9c9bba9c520885e517afdc80b795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 8 Feb 2020 18:23:08 +0100 Subject: [PATCH 8/9] term: factor out common font changing code --- terminal.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/terminal.c b/terminal.c index 72d98104..a07b1912 100644 --- a/terminal.c +++ b/terminal.c @@ -1111,6 +1111,24 @@ 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) { @@ -1129,17 +1147,7 @@ term_font_size_adjust(struct terminal *term, double amount) return; } - for (size_t i = 0; i < 4; i++) { - 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); + term_set_fonts(term, fonts); } void @@ -1161,17 +1169,7 @@ term_font_size_reset(struct terminal *term) if (!initialize_fonts(term, term->conf, fonts)) return; - for (size_t i = 0; i < 4; i++) { - 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); + term_set_fonts(term, fonts); } void From ac11909f80866f095c81149af3ec61ebc6534918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 9 Feb 2020 11:05:59 +0100 Subject: [PATCH 9/9] meson/PKGBUILD: adjust fcft requirements; the new version is 1.1.1 --- PKGBUILD | 2 +- meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index f5136be9..8a09db65 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -5,7 +5,7 @@ arch=('x86_64') url=https://codeberg.org/dnkl/foot license=(mit) makedepends=('meson' 'ninja' 'scdoc' 'python' 'ncurses' 'wayland-protocols' 'tllist>=1.0.0') -depends=('libxkbcommon' 'wayland' 'pixman' 'fcft>=1.2.0') +depends=('libxkbcommon' 'wayland' 'pixman' 'fcft>=1.1.1') source=() pkgver() { diff --git a/meson.build b/meson.build index 083bce70..d391303e 100644 --- a/meson.build +++ b/meson.build @@ -25,7 +25,7 @@ wayland_cursor = dependency('wayland-cursor') xkb = dependency('xkbcommon') tllist = dependency('tllist', version: '>=1.0.0', fallback: ['tllist', 'tllist']) -fcft = dependency('fcft', version: ['>=1.2.0', '<1.3.0'], fallback: ['fcft', 'fcft']) +fcft = dependency('fcft', version: ['>=1.1.1', '<1.2.0'], fallback: ['fcft', 'fcft']) wayland_protocols_datadir = wayland_protocols.get_pkgconfig_variable('pkgdatadir')