mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:28:11 +00:00
Support resizing the Terminal app.
I set it up so that TIOCSWINSZ on a master PTY gets forwarded to the slave. This feels intuitively right. Terminal can then use that to inform the shell or whoever is inside the slave that the window size has changed. TIOCSWINSZ also triggers the generation of a SIGWINCH signal. :^)
This commit is contained in:
parent
0ca3112301
commit
0aaec6b19a
6 changed files with 74 additions and 19 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <Kernel/Process.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
#include <LibC/signal_numbers.h>
|
||||
#include <LibC/sys/ioctl_numbers.h>
|
||||
|
||||
MasterPTY::MasterPTY(unsigned index)
|
||||
: CharacterDevice(10, index)
|
||||
|
@ -87,3 +88,10 @@ void MasterPTY::close()
|
|||
m_slave->hang_up();
|
||||
}
|
||||
}
|
||||
|
||||
int MasterPTY::ioctl(Process& process, unsigned request, unsigned arg)
|
||||
{
|
||||
if (request == TIOCSWINSZ)
|
||||
return m_slave->ioctl(process, request, arg);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ private:
|
|||
virtual bool can_write(Process&) const override;
|
||||
virtual void close() override;
|
||||
virtual bool is_master_pty() const override { return true; }
|
||||
virtual int ioctl(Process&, unsigned request, unsigned arg) override;
|
||||
virtual const char* class_name() const override { return "MasterPTY"; }
|
||||
|
||||
RetainPtr<SlavePTY> m_slave;
|
||||
|
|
|
@ -1868,6 +1868,7 @@ void Process::set_default_signal_dispositions()
|
|||
// FIXME: Set up all the right default actions. See signal(7).
|
||||
memset(&m_signal_action_data, 0, sizeof(m_signal_action_data));
|
||||
m_signal_action_data[SIGCHLD].handler_or_sigaction = LinearAddress((dword)SIG_IGN);
|
||||
m_signal_action_data[SIGWINCH].handler_or_sigaction = LinearAddress((dword)SIG_IGN);
|
||||
}
|
||||
|
||||
int Process::sys$sigaction(int signum, const sigaction* act, sigaction* old_act)
|
||||
|
|
|
@ -112,8 +112,13 @@ int TTY::ioctl(Process& process, unsigned request, unsigned arg)
|
|||
termios* tp;
|
||||
winsize* ws;
|
||||
|
||||
if (process.tty() && process.tty() != this)
|
||||
#if 0
|
||||
// FIXME: When should we block things?
|
||||
// How do we make this work together with MasterPTY forwarding to us?
|
||||
if (process.tty() && process.tty() != this) {
|
||||
return -ENOTTY;
|
||||
}
|
||||
#endif
|
||||
switch (request) {
|
||||
case TIOCGPGRP:
|
||||
return m_pgid;
|
||||
|
@ -145,6 +150,16 @@ int TTY::ioctl(Process& process, unsigned request, unsigned arg)
|
|||
ws->ws_row = m_rows;
|
||||
ws->ws_col = m_columns;
|
||||
return 0;
|
||||
case TIOCSWINSZ:
|
||||
ws = reinterpret_cast<winsize*>(arg);
|
||||
if (!process.validate_read(ws, sizeof(winsize)))
|
||||
return -EFAULT;
|
||||
if (ws->ws_col == m_columns && ws->ws_row == m_rows)
|
||||
return 0;
|
||||
m_rows = ws->ws_row;
|
||||
m_columns = ws->ws_col;
|
||||
generate_signal(SIGWINCH);
|
||||
return 0;
|
||||
case TIOCSCTTY:
|
||||
process.set_tty(this);
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue