Kernel/LibC: Implement ioctl(TIOCGWINSZ)

This allows ncurses to get the window size!
This commit is contained in:
Bananymous 2024-08-01 22:56:26 +03:00
parent af78a2d080
commit a578527012
3 changed files with 18 additions and 5 deletions

View File

@ -127,16 +127,22 @@ namespace Kernel
{ {
switch (request) switch (request)
{ {
case KD_LOADFONT: case KDLOADFONT:
{ {
auto absolute_path = TRY(Process::current().absolute_path_of(BAN::StringView(reinterpret_cast<const char*>(argument)))); auto absolute_path = TRY(Process::current().absolute_path_of(BAN::StringView(reinterpret_cast<const char*>(argument))));
auto new_font = TRY(LibFont::Font::load(absolute_path)); auto new_font = TRY(LibFont::Font::load(absolute_path));
set_font(new_font); set_font(new_font);
return 0; return 0;
} }
default: case TIOCGWINSZ:
return BAN::Error::from_errno(EINVAL); {
auto* winsize = static_cast<struct winsize*>(argument);
winsize->ws_col = width();
winsize->ws_row = height();
return 0;
}
} }
return BAN::Error::from_errno(ENOTSUP);
} }
void TTY::on_key_event(LibInput::KeyEvent event) void TTY::on_key_event(LibInput::KeyEvent event)

View File

@ -101,7 +101,14 @@ struct str_list
#define I_SWROPT 28 #define I_SWROPT 28
#define I_UNLINK 29 #define I_UNLINK 29
#define KD_LOADFONT 30 #define KDLOADFONT 30
struct winsize
{
unsigned short ws_row;
unsigned short ws_col;
};
#define TIOCGWINSZ 50
#define FLUSHR 1 #define FLUSHR 1
#define FLUSHRW 2 #define FLUSHRW 2

View File

@ -20,7 +20,7 @@ int main(int argc, char** argv)
return 1; return 1;
} }
if (ioctl(STDOUT_FILENO, KD_LOADFONT, argv[1]) == -1) if (ioctl(STDOUT_FILENO, KDLOADFONT, argv[1]) == -1)
{ {
perror("ioctl"); perror("ioctl");
return 1; return 1;