mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
Merge branch 'text-resize'
This commit is contained in:
commit
8955875584
7 changed files with 132 additions and 21 deletions
2
PKGBUILD
2
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() {
|
||||
|
|
|
|||
17
input.c
17
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);
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
26
render.c
26
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);
|
||||
|
||||
|
|
|
|||
2
render.h
2
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);
|
||||
|
|
|
|||
87
terminal.c
87
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)
|
||||
{
|
||||
|
|
|
|||
17
terminal.h
17
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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue