Skip to content

Commit

Permalink
fix(terminal): report terminal window size in pixels
Browse files Browse the repository at this point in the history
Window size in pixels is required by some programs, reporting it can
help those programs work inside NeoVim terminals.

See also: neovim#8259, neovim#12991
  • Loading branch information
lumynou5 committed May 3, 2024
1 parent 01e4a70 commit ab50ab3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/nvim/os/pty_process_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ int pty_process_spawn(PtyProcess *ptyproc)
Process *proc = (Process *)ptyproc;
assert(proc->err.closed);
uv_signal_start(&proc->loop->children_watcher, chld_handler, SIGCHLD);
ptyproc->winsize = (struct winsize){ ptyproc->height, ptyproc->width, 0, 0 };
ioctl(1, TIOCGWINSZ, &ptyproc->winsize);
ptyproc->winsize = (struct winsize){
ptyproc->height,
ptyproc->width,
ptyproc->winsize.ws_xpixel / ptyproc->winsize.ws_col * ptyproc->width,
ptyproc->winsize.ws_ypixel / ptyproc->winsize.ws_row * ptyproc->height,
};
uv_disable_stdio_inheritance();
int master;
int pid = forkpty(&master, NULL, &termios_default, &ptyproc->winsize);
Expand Down Expand Up @@ -232,7 +238,13 @@ const char *pty_process_tty_name(PtyProcess *ptyproc)
void pty_process_resize(PtyProcess *ptyproc, uint16_t width, uint16_t height)
FUNC_ATTR_NONNULL_ALL
{
ptyproc->winsize = (struct winsize){ height, width, 0, 0 };
ioctl(ptyproc->tty_fd, TIOCGWINSZ, &ptyproc->winsize);
ptyproc->winsize = (struct winsize){
height,
width,
ptyproc->winsize.ws_xpixel / ptyproc->winsize.ws_col * width,
ptyproc->winsize.ws_ypixel / ptyproc->winsize.ws_row * height,
};
ioctl(ptyproc->tty_fd, TIOCSWINSZ, &ptyproc->winsize);
}

Expand Down

0 comments on commit ab50ab3

Please sign in to comment.