1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-21 00:25:37 +00:00

[teminal] Added two output parameters to get_terminal_size.

cell_width and cell_height in pixels. It is a bit ugly, and not efficient.
This commit is contained in:
Witold Filipczyk 2023-05-24 21:52:45 +02:00
parent 6d44ddd892
commit a7af080101
11 changed files with 65 additions and 26 deletions

View File

@ -230,10 +230,12 @@ static void sigbreak(int sig)
break_pressed = 1;
}
void get_terminal_size(int fd, int *x, int *y)
void get_terminal_size(int fd, int *x, int *y, int *cw, int *ch)
{
*x = ScreenCols();
*y = ScreenRows();
*cw = 8;
*ch = 16;
}
void handle_terminal_resize(int fd, void (*fn)(void))

View File

@ -39,7 +39,7 @@ int os_default_charset(void);
void done_draw(void);
int get_system_env(void);
void get_terminal_size(int fd, int *x, int *y);
void get_terminal_size(int fd, int *x, int *y, int *cw, int *ch);
void *handle_mouse(int cons, void (*fn)(void *, char *, int), void *data);
void handle_terminal_resize(int fd, void (*fn)(void));
void init_osdep(void);

View File

@ -66,11 +66,12 @@ winch_thread(void)
the thread responsible to handle this. */
static int old_xsize, old_ysize;
static int cur_xsize, cur_ysize;
int cw, ch;
signal(SIGPIPE, SIG_IGN);
if (get_terminal_size(0, &old_xsize, &old_ysize)) return;
if (get_terminal_size(0, &old_xsize, &old_ysize, &cw, &ch)) return;
while (1) {
if (get_terminal_size(0, &cur_xsize, &cur_ysize)) return;
if (get_terminal_size(0, &cur_xsize, &cur_ysize, &cw, &ch)) return;
if ((old_xsize != cur_xsize) || (old_ysize != cur_ysize)) {
old_xsize = cur_xsize;
old_ysize = cur_ysize;
@ -112,7 +113,7 @@ unhandle_terminal_resize(int fd)
}
void
get_terminal_size(int fd, int *x, int *y)
get_terminal_size(int fd, int *x, int *y, int *cw, *ch)
{
if (is_xterm()) {
#ifdef X2
@ -128,10 +129,14 @@ get_terminal_size(int fd, int *x, int *y)
*/
*x = DEFAULT_TERMINAL_WIDTH;
*y = DEFAULT_TERMINAL_HEIGHT;
*cw = 8;
*ch = 16;
return 0;
}
*y = win.ws_row;
*x = win.ws_col;
*cw = win.ws_xpixel / win.ws_col;
*ch = win.ws_ypixel / win.ws_row;
/*
DBG("%d %d", *x, *y);
*/
@ -154,6 +159,8 @@ get_terminal_size(int fd, int *x, int *y)
*y = get_e("LINES");
if (!*y) *y = DEFAULT_TERMINAL_HEIGHT;
}
*cw = 8;
*ch = 16;
}
}
@ -611,9 +618,10 @@ want_draw(void)
if (mouse_h != -1) {
static int x = -1, y = -1;
static int c = -1;
int cw, ch;
if (x == -1 || y == -1 || (c != resize_count)) {
get_terminal_size(1, &x, &y);
get_terminal_size(1, &x, &y, &cw, &ch);
c = resize_count;
}

View File

@ -216,16 +216,21 @@ unhandle_terminal_resize(int fd)
}
void
get_terminal_size(int fd, int *x, int *y)
get_terminal_size(int fd, int *x, int *y, int *cw, int *ch)
{
struct winsize ws;
if (ioctl(1, TIOCGWINSZ, &ws) != -1) {
*x = ws.ws_col;
*y = ws.ws_row;
*cw = ws.ws_xpixel / ws.ws_col;
*ch = ws.ws_ypixel / ws.ws_row;
} else {
*x = 0;
*y = 0;
*cw = 8;
*ch = 16;
}
if (!*x) {

View File

@ -24,7 +24,7 @@ int get_system_env(void);
int get_e(const char *env);
int is_xterm(void);
int is_twterm(void);
void get_terminal_size(int, int *, int *);
void get_terminal_size(int, int *, int *, int *, int *);
void handle_terminal_resize(int, void (*)(void));
void unhandle_terminal_resize(int);
void set_bin(int);

View File

@ -81,7 +81,7 @@ unhandle_terminal_resize(int fd)
}
void
get_terminal_size(int fd, int *x, int *y)
get_terminal_size(int fd, int *x, int *y, int *cw, int *ch)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
@ -97,6 +97,14 @@ get_terminal_size(int fd, int *x, int *y)
if (!*y)
*y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
}
if (!*cw) {
*cw = 8;
}
if (!*ch) {
*ch = 16;
}
}

View File

@ -87,6 +87,10 @@ term_send_event(struct terminal *term, struct term_event *ev)
}
resize_screen(term, width, height);
#ifdef CONFIG_LIBSIXEL
term->cell_width = ev->info.size.cell_width;
term->cell_height = ev->info.size.cell_height;
#endif
erase_screen(term);
/* Fall through */
}
@ -250,7 +254,9 @@ handle_interlink_event(struct terminal *term, struct interlink_event *ilev)
* possible. */
set_init_term_event(&tev,
ilev->info.size.width,
ilev->info.size.height);
ilev->info.size.height,
ilev->info.size.cell_width,
ilev->info.size.cell_height);
term_send_event(term, &tev);
/* Either the initialization of the first session failed or we
@ -272,7 +278,9 @@ handle_interlink_event(struct terminal *term, struct interlink_event *ilev)
case EVENT_RESIZE:
set_wh_term_event(&tev, ilev->ev,
ilev->info.size.width,
ilev->info.size.height);
ilev->info.size.height,
ilev->info.size.cell_width,
ilev->info.size.cell_height);
term_send_event(term, &tev);
/* If textarea_data is set and the terminal is not blocked,

View File

@ -22,6 +22,7 @@ enum term_event_type {
struct term_event_size {
int width, height;
int cell_width, cell_height;
};
@ -112,28 +113,36 @@ set_abort_term_event(struct term_event *ev)
}
static inline void
set_wh_term_event(struct term_event *ev, enum term_event_type type, int width, int height)
set_wh_term_event(struct term_event *ev, enum term_event_type type, int width, int height, int cell_width, int cell_height)
{
memset(ev, 0, sizeof(*ev));
ev->ev = type;
ev->info.size.width = width;
ev->info.size.height = height;
#ifdef CONFIG_LIBSIXEL
ev->info.size.cell_width = cell_width;
ev->info.size.cell_height = cell_height;
#endif
}
#define set_init_term_event(ev, w, h) set_wh_term_event(ev, EVENT_INIT, w, h)
#define set_resize_term_event(ev, w, h) set_wh_term_event(ev, EVENT_RESIZE, w, h)
#define set_redraw_term_event(ev, w, h) set_wh_term_event(ev, EVENT_REDRAW, w, h)
#define set_init_term_event(ev, w, h, cw, ch) set_wh_term_event(ev, EVENT_INIT, w, h, cw, ch)
#define set_resize_term_event(ev, w, h, cw, ch) set_wh_term_event(ev, EVENT_RESIZE, w, h, cw, ch)
#define set_redraw_term_event(ev, w, h, cw, ch) set_wh_term_event(ev, EVENT_REDRAW, w, h, cw, ch)
static inline void
set_wh_interlink_event(struct interlink_event *ev, enum term_event_type type, int width, int height)
set_wh_interlink_event(struct interlink_event *ev, enum term_event_type type, int width, int height, int cell_width, int cell_height)
{
memset(ev, 0, sizeof(*ev));
ev->ev = type;
ev->info.size.width = width;
ev->info.size.height = height;
#ifdef CONFIG_LIBSIXEL
ev->info.size.cell_width = cell_width;
ev->info.size.cell_height = cell_height;
#endif
}
#define set_resize_interlink_event(ev, w, h) set_wh_interlink_event(ev, EVENT_RESIZE, w, h)
#define set_resize_interlink_event(ev, w, h, cw, ch) set_wh_interlink_event(ev, EVENT_RESIZE, w, h, cw, ch)
/** This holds the information used when handling the initial

View File

@ -229,9 +229,10 @@ resize_terminal(void)
{
struct interlink_event ev;
int width, height;
int cell_width, cell_height;
get_terminal_size(ditrm->out.std, &width, &height);
set_resize_interlink_event(&ev, width, height);
get_terminal_size(ditrm->out.std, &width, &height, &cell_width, &cell_height);
set_resize_interlink_event(&ev, width, height, cell_width, cell_height);
itrm_queue_event(ditrm, (char *) &ev, sizeof(ev));
}
@ -330,7 +331,7 @@ handle_trm(int std_in, int std_out, int sock_in, int sock_out, int ctl_in,
dos_setraw(ctl_in, 1);
#endif
get_terminal_size(ctl_in, &size->width, &size->height);
get_terminal_size(ctl_in, &size->width, &size->height, &size->cell_width, &size->cell_height);
info.event.ev = EVENT_INIT;
info.system_env = get_system_env();
info.length = init_len;

View File

@ -56,7 +56,7 @@ redraw_terminal(struct terminal *term)
{
struct term_event ev;
set_redraw_term_event(&ev, term->width, term->height);
set_redraw_term_event(&ev, term->width, term->height, term->cell_width, term->cell_height);
term_send_event(term, &ev);
}
@ -65,7 +65,7 @@ redraw_terminal_cls(struct terminal *term)
{
struct term_event ev;
set_resize_term_event(&ev, term->width, term->height);
set_resize_term_event(&ev, term->width, term->height, term->cell_width, term->cell_height);
term_send_event(term, &ev);
}
@ -120,8 +120,6 @@ init_term(int fdin, int fdout)
#ifdef CONFIG_LIBSIXEL
init_list(term->images);
term->cell_height = 13;
term->cell_width = 6;
#endif
term->fdin = fdin;
term->fdout = fdout;

View File

@ -45,7 +45,7 @@ redraw_windows(enum windows_to_redraw which, struct window *win)
return;
}
set_redraw_term_event(&ev, term->width, term->height);
set_redraw_term_event(&ev, term->width, term->height, term->cell_width, term->cell_height);
for (; win != end; win = win->prev) {
if (!inactive_tab(win))
win->handler(win, &ev);
@ -69,7 +69,7 @@ add_window(struct terminal *term, window_handler_T handler, void *data)
win->term = term;
win->type = WINDOW_NORMAL;
add_at_pos((struct window *) &term->windows, win);
set_init_term_event(&ev, term->width, term->height);
set_init_term_event(&ev, term->width, term->height, term->cell_width, term->cell_height);
win->handler(win, &ev);
}