mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05: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:
parent
6d44ddd892
commit
a7af080101
@ -230,10 +230,12 @@ static void sigbreak(int sig)
|
|||||||
break_pressed = 1;
|
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();
|
*x = ScreenCols();
|
||||||
*y = ScreenRows();
|
*y = ScreenRows();
|
||||||
|
*cw = 8;
|
||||||
|
*ch = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_terminal_resize(int fd, void (*fn)(void))
|
void handle_terminal_resize(int fd, void (*fn)(void))
|
||||||
|
@ -39,7 +39,7 @@ int os_default_charset(void);
|
|||||||
|
|
||||||
void done_draw(void);
|
void done_draw(void);
|
||||||
int get_system_env(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_mouse(int cons, void (*fn)(void *, char *, int), void *data);
|
||||||
void handle_terminal_resize(int fd, void (*fn)(void));
|
void handle_terminal_resize(int fd, void (*fn)(void));
|
||||||
void init_osdep(void);
|
void init_osdep(void);
|
||||||
|
@ -66,11 +66,12 @@ winch_thread(void)
|
|||||||
the thread responsible to handle this. */
|
the thread responsible to handle this. */
|
||||||
static int old_xsize, old_ysize;
|
static int old_xsize, old_ysize;
|
||||||
static int cur_xsize, cur_ysize;
|
static int cur_xsize, cur_ysize;
|
||||||
|
int cw, ch;
|
||||||
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
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) {
|
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)) {
|
if ((old_xsize != cur_xsize) || (old_ysize != cur_ysize)) {
|
||||||
old_xsize = cur_xsize;
|
old_xsize = cur_xsize;
|
||||||
old_ysize = cur_ysize;
|
old_ysize = cur_ysize;
|
||||||
@ -112,7 +113,7 @@ unhandle_terminal_resize(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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()) {
|
if (is_xterm()) {
|
||||||
#ifdef X2
|
#ifdef X2
|
||||||
@ -128,10 +129,14 @@ get_terminal_size(int fd, int *x, int *y)
|
|||||||
*/
|
*/
|
||||||
*x = DEFAULT_TERMINAL_WIDTH;
|
*x = DEFAULT_TERMINAL_WIDTH;
|
||||||
*y = DEFAULT_TERMINAL_HEIGHT;
|
*y = DEFAULT_TERMINAL_HEIGHT;
|
||||||
|
*cw = 8;
|
||||||
|
*ch = 16;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*y = win.ws_row;
|
*y = win.ws_row;
|
||||||
*x = win.ws_col;
|
*x = win.ws_col;
|
||||||
|
*cw = win.ws_xpixel / win.ws_col;
|
||||||
|
*ch = win.ws_ypixel / win.ws_row;
|
||||||
/*
|
/*
|
||||||
DBG("%d %d", *x, *y);
|
DBG("%d %d", *x, *y);
|
||||||
*/
|
*/
|
||||||
@ -154,6 +159,8 @@ get_terminal_size(int fd, int *x, int *y)
|
|||||||
*y = get_e("LINES");
|
*y = get_e("LINES");
|
||||||
if (!*y) *y = DEFAULT_TERMINAL_HEIGHT;
|
if (!*y) *y = DEFAULT_TERMINAL_HEIGHT;
|
||||||
}
|
}
|
||||||
|
*cw = 8;
|
||||||
|
*ch = 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,9 +618,10 @@ want_draw(void)
|
|||||||
if (mouse_h != -1) {
|
if (mouse_h != -1) {
|
||||||
static int x = -1, y = -1;
|
static int x = -1, y = -1;
|
||||||
static int c = -1;
|
static int c = -1;
|
||||||
|
int cw, ch;
|
||||||
|
|
||||||
if (x == -1 || y == -1 || (c != resize_count)) {
|
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;
|
c = resize_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,16 +216,21 @@ unhandle_terminal_resize(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
struct winsize ws;
|
||||||
|
|
||||||
if (ioctl(1, TIOCGWINSZ, &ws) != -1) {
|
if (ioctl(1, TIOCGWINSZ, &ws) != -1) {
|
||||||
*x = ws.ws_col;
|
*x = ws.ws_col;
|
||||||
*y = ws.ws_row;
|
*y = ws.ws_row;
|
||||||
|
|
||||||
|
*cw = ws.ws_xpixel / ws.ws_col;
|
||||||
|
*ch = ws.ws_ypixel / ws.ws_row;
|
||||||
} else {
|
} else {
|
||||||
*x = 0;
|
*x = 0;
|
||||||
*y = 0;
|
*y = 0;
|
||||||
|
*cw = 8;
|
||||||
|
*ch = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*x) {
|
if (!*x) {
|
||||||
|
@ -24,7 +24,7 @@ int get_system_env(void);
|
|||||||
int get_e(const char *env);
|
int get_e(const char *env);
|
||||||
int is_xterm(void);
|
int is_xterm(void);
|
||||||
int is_twterm(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 handle_terminal_resize(int, void (*)(void));
|
||||||
void unhandle_terminal_resize(int);
|
void unhandle_terminal_resize(int);
|
||||||
void set_bin(int);
|
void set_bin(int);
|
||||||
|
@ -81,7 +81,7 @@ unhandle_terminal_resize(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
|
|
||||||
@ -97,6 +97,14 @@ get_terminal_size(int fd, int *x, int *y)
|
|||||||
if (!*y)
|
if (!*y)
|
||||||
*y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
*y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!*cw) {
|
||||||
|
*cw = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!*ch) {
|
||||||
|
*ch = 16;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,6 +87,10 @@ term_send_event(struct terminal *term, struct term_event *ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
resize_screen(term, width, height);
|
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);
|
erase_screen(term);
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
}
|
}
|
||||||
@ -250,7 +254,9 @@ handle_interlink_event(struct terminal *term, struct interlink_event *ilev)
|
|||||||
* possible. */
|
* possible. */
|
||||||
set_init_term_event(&tev,
|
set_init_term_event(&tev,
|
||||||
ilev->info.size.width,
|
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);
|
term_send_event(term, &tev);
|
||||||
|
|
||||||
/* Either the initialization of the first session failed or we
|
/* 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:
|
case EVENT_RESIZE:
|
||||||
set_wh_term_event(&tev, ilev->ev,
|
set_wh_term_event(&tev, ilev->ev,
|
||||||
ilev->info.size.width,
|
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);
|
term_send_event(term, &tev);
|
||||||
|
|
||||||
/* If textarea_data is set and the terminal is not blocked,
|
/* If textarea_data is set and the terminal is not blocked,
|
||||||
|
@ -22,6 +22,7 @@ enum term_event_type {
|
|||||||
|
|
||||||
struct term_event_size {
|
struct term_event_size {
|
||||||
int width, height;
|
int width, height;
|
||||||
|
int cell_width, cell_height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -112,28 +113,36 @@ set_abort_term_event(struct term_event *ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
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));
|
memset(ev, 0, sizeof(*ev));
|
||||||
ev->ev = type;
|
ev->ev = type;
|
||||||
ev->info.size.width = width;
|
ev->info.size.width = width;
|
||||||
ev->info.size.height = height;
|
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_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) set_wh_term_event(ev, EVENT_RESIZE, w, h)
|
#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) set_wh_term_event(ev, EVENT_REDRAW, w, h)
|
#define set_redraw_term_event(ev, w, h, cw, ch) set_wh_term_event(ev, EVENT_REDRAW, w, h, cw, ch)
|
||||||
|
|
||||||
static inline void
|
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));
|
memset(ev, 0, sizeof(*ev));
|
||||||
ev->ev = type;
|
ev->ev = type;
|
||||||
ev->info.size.width = width;
|
ev->info.size.width = width;
|
||||||
ev->info.size.height = height;
|
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
|
/** This holds the information used when handling the initial
|
||||||
|
@ -229,9 +229,10 @@ resize_terminal(void)
|
|||||||
{
|
{
|
||||||
struct interlink_event ev;
|
struct interlink_event ev;
|
||||||
int width, height;
|
int width, height;
|
||||||
|
int cell_width, cell_height;
|
||||||
|
|
||||||
get_terminal_size(ditrm->out.std, &width, &height);
|
get_terminal_size(ditrm->out.std, &width, &height, &cell_width, &cell_height);
|
||||||
set_resize_interlink_event(&ev, width, height);
|
set_resize_interlink_event(&ev, width, height, cell_width, cell_height);
|
||||||
itrm_queue_event(ditrm, (char *) &ev, sizeof(ev));
|
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);
|
dos_setraw(ctl_in, 1);
|
||||||
#endif
|
#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.event.ev = EVENT_INIT;
|
||||||
info.system_env = get_system_env();
|
info.system_env = get_system_env();
|
||||||
info.length = init_len;
|
info.length = init_len;
|
||||||
|
@ -56,7 +56,7 @@ redraw_terminal(struct terminal *term)
|
|||||||
{
|
{
|
||||||
struct term_event ev;
|
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);
|
term_send_event(term, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ redraw_terminal_cls(struct terminal *term)
|
|||||||
{
|
{
|
||||||
struct term_event ev;
|
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);
|
term_send_event(term, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,8 +120,6 @@ init_term(int fdin, int fdout)
|
|||||||
|
|
||||||
#ifdef CONFIG_LIBSIXEL
|
#ifdef CONFIG_LIBSIXEL
|
||||||
init_list(term->images);
|
init_list(term->images);
|
||||||
term->cell_height = 13;
|
|
||||||
term->cell_width = 6;
|
|
||||||
#endif
|
#endif
|
||||||
term->fdin = fdin;
|
term->fdin = fdin;
|
||||||
term->fdout = fdout;
|
term->fdout = fdout;
|
||||||
|
@ -45,7 +45,7 @@ redraw_windows(enum windows_to_redraw which, struct window *win)
|
|||||||
return;
|
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) {
|
for (; win != end; win = win->prev) {
|
||||||
if (!inactive_tab(win))
|
if (!inactive_tab(win))
|
||||||
win->handler(win, &ev);
|
win->handler(win, &ev);
|
||||||
@ -69,7 +69,7 @@ add_window(struct terminal *term, window_handler_T handler, void *data)
|
|||||||
win->term = term;
|
win->term = term;
|
||||||
win->type = WINDOW_NORMAL;
|
win->type = WINDOW_NORMAL;
|
||||||
add_at_pos((struct window *) &term->windows, win);
|
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);
|
win->handler(win, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user