aboutsummaryrefslogtreecommitdiff
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
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'
-rw-r--r--PKGBUILD2
-rw-r--r--input.c17
-rw-r--r--meson.build2
-rw-r--r--render.c26
-rw-r--r--render.h2
-rw-r--r--terminal.c87
-rw-r--r--terminal.h17
7 files changed, 132 insertions, 21 deletions
diff --git a/PKGBUILD b/PKGBUILD
index 720990c3..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.1.0')
+depends=('libxkbcommon' 'wayland' 'pixman' 'fcft>=1.1.1')
source=()
pkgver() {
diff --git a/input.c b/input.c
index 2a4322c9..21fc6f37 100644
--- a/input.c
+++ b/input.c
@@ -385,6 +385,23 @@ 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 (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)) {
if (sym == XKB_KEY_C) {
selection_to_clipboard(term, serial);
diff --git a/meson.build b/meson.build
index 00933df3..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.1.0', '<1.2.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')
diff --git a/render.c b/render.c
index f97a957f..7fa7dd86 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" */
@@ -1123,11 +1123,25 @@ render_resize(struct terminal *term, int width, int height)
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);
}
+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);
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)
{
diff --git a/terminal.h b/terminal.h
index cf691f5e..b4ce1212 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,10 @@ 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_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);