~sircmpwn/scurvy

7d9bb6dd0fe298f0ac3fd75949f16364855f3b90 — Drew DeVault 4 years ago d224a93
Handle resizing "correctly"
3 files changed, 31 insertions(+), 21 deletions(-)

M src/main.c
M src/term.c
M src/wayland/main.c
M src/main.c => src/main.c +1 -1
@@ 13,7 13,7 @@ int main(int argc, char **argv) {
	if (!load_scurvy_config(NULL)) {
		return 1;
	}
	char *_argv[] = { "/usr/bin/vim", NULL };
	char *_argv[] = { "/usr/bin/sh", "-c", "vim ~/.config/scurvy.conf", NULL };
	struct scurvy_child *child = child_spawn(_argv);
	int status = wayland_main(child);
	child_free(child);

M src/term.c => src/term.c +12 -8
@@ 59,17 59,21 @@ void term_init() {
	vtscreen = vterm_obtain_screen(vterm);

	vterm_set_utf8(vterm, 1);
	vterm_screen_set_damage_merge(vtscreen, VTERM_DAMAGE_SCROLL);
	vterm_screen_set_damage_merge(vtscreen, VTERM_DAMAGE_CELL);
	vterm_screen_reset(vtscreen, 1);
	vterm_state_set_bold_highbright(vtstate, true);
}

void set_term_size(cairo_t *cairo, int width, int height) {
	int w, h;
	get_text_size(cairo, config->font, &w, &h, 1, false, "H");
	h = height / h;
	w = width / w;
	scurvy_log(L_DEBUG, "Setting size to %d rows %d cols", h, w);
	vterm_set_size(vterm, h, w);
	vterm_screen_flush_damage(vtscreen);
	int rows, cols;
	get_text_size(cairo, config->font, &cols, &rows, 1, false, "H");
	rows = height / rows;
	cols = width / cols;
	int old_rows, old_cols;
	vterm_get_size(vterm, &old_rows, &old_cols);
	if ((rows && cols) && (old_rows != rows || old_cols != cols)) {
		scurvy_log(L_DEBUG, "Setting size to %d rows %d cols", rows, cols);
		vterm_set_size(vterm, rows, cols);
		vterm_screen_flush_damage(vtscreen);
	}
}

M src/wayland/main.c => src/wayland/main.c +18 -12
@@ 3,6 3,9 @@
#include <cairo/cairo.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <termios.h>
#include "wayland/window.h"
#include "wayland/registry.h"
#include "config.h"


@@ 14,48 17,51 @@ struct registry *registry;
struct window *win;

static int term_damage(VTermRect rect, void *data) {
	scurvy_log(L_DEBUG, "damage");
	return 0;
}

static int term_moverect(VTermRect dest, VTermRect src, void *data) {
	scurvy_log(L_DEBUG, "moverect");
	return 0;
}

static int term_movecursor(VTermPos new, VTermPos old, int visible, void *data) {
	scurvy_log(L_DEBUG, "movecursor");
	return 0;
}

static int term_settermprop(VTermProp prop, VTermValue *val, void *data) {
	scurvy_log(L_DEBUG, "prop");
	return 0;
}

static int term_bell(void *data) {
	scurvy_log(L_DEBUG, "bell");
	return 0;
}

static int term_sb_push(int cols, const VTermScreenCell *cells, void *data) {
	scurvy_log(L_DEBUG, "sb_push");
	return 0;
}

static int term_sb_pop(int cols, VTermScreenCell *cells, void *data) {
	scurvy_log(L_DEBUG, "sb_pop");
	return 0;
}

static int term_resize(int rows, int cols, void *data) {
	if (rows + cols) {
		struct scurvy_child *child = data;
		struct winsize ws = { .ws_row = rows, .ws_col = cols };
		ioctl(child->fd, TIOCSWINSZ, &ws);
	}
	return 1;
}

static VTermScreenCallbacks vterm_screen_callbacks = {
	.damage      = term_damage,
	.moverect    = term_moverect,
	.movecursor  = term_movecursor,
	.damage = term_damage,
	.moverect = term_moverect,
	.movecursor = term_movecursor,
	.settermprop = term_settermprop,
	.bell        = term_bell,
	.bell = term_bell,
	.sb_pushline = term_sb_push,
	.sb_popline  = term_sb_pop,
	.resize = term_resize
};

static void window_resize(struct window *_win) {


@@ 68,7 74,7 @@ static void keyboard_event(enum wl_keyboard_key_state state,
}

int wayland_main(struct scurvy_child *child) {
	vterm_screen_set_callbacks(vtscreen, &vterm_screen_callbacks, NULL);
	vterm_screen_set_callbacks(vtscreen, &vterm_screen_callbacks, child);
	registry = registry_poll();
	registry->input->notify = keyboard_event;
	win = window_setup(registry, 640, 480, 1, true);