Kernel/LibC: Rework TIOC{G,S}WINSZ more linux like

Userspace can freely set terminal size, kernel just updates it when for
example new font is loaded. Also SIGWINCH is now sent by kernel instead
of userspace.
This commit is contained in:
2025-06-28 16:26:13 +03:00
parent 521457eb92
commit e8491b34b8
12 changed files with 62 additions and 77 deletions

View File

@@ -41,6 +41,8 @@ struct winsize
{
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel; /* unused by kernel */
unsigned short ws_ypixel; /* unused by kernel */
};
#define TIOCGWINSZ 50
#define TIOCSWINSZ 51

View File

@@ -128,9 +128,12 @@ void Terminal::run()
m_window->set_min_size(m_font.width() * 8, m_font.height() * 2);
{
winsize winsize;
winsize.ws_col = cols();
winsize.ws_row = rows();
winsize winsize {
.ws_row = static_cast<unsigned short>(rows()),
.ws_col = static_cast<unsigned short>(cols()),
.ws_xpixel = static_cast<unsigned short>(m_window->width()),
.ws_ypixel = static_cast<unsigned short>(m_window->height()),
};
if (ioctl(m_shell_info.pts_master, TIOCSWINSZ, &winsize) == -1)
perror("ioctl");
}
@@ -170,6 +173,8 @@ void Terminal::run()
const winsize winsize {
.ws_row = static_cast<unsigned short>(rows()),
.ws_col = static_cast<unsigned short>(cols()),
.ws_xpixel = static_cast<unsigned short>(m_window->width()),
.ws_ypixel = static_cast<unsigned short>(m_window->height()),
};
if (ioctl(m_shell_info.pts_master, TIOCSWINSZ, &winsize) == -1)
{
@@ -183,12 +188,6 @@ void Terminal::run()
perror("tcgetpgrp");
return;
}
if (kill(-fgpgrp, SIGWINCH) == -1)
{
perror("kill");
return;
}
});
const int max_fd = BAN::Math::max(m_shell_info.pts_master, m_window->server_fd());

View File

@@ -328,7 +328,7 @@ int main(int argc, char** argv)
tcsetattr(kb_fd, TCSANOW, &termios);
}
winsize ws { .ws_row = 0, .ws_col = 0 };
winsize ws {};
if (isatty(STDOUT_FILENO))
{
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)