diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-10-23 07:16:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 07:16:47 +0000 |
commit | 1df7dc5171abfe1eab3e95be964f61c5876198f1 (patch) | |
tree | 315ceaa093b86b8e875512825302f38e32f697a4 /alacritty_terminal/src/tty | |
parent | d8a98f88295e59d6518ae780a9857c033a83161c (diff) | |
download | alacritty-1df7dc5171abfe1eab3e95be964f61c5876198f1.tar.gz alacritty-1df7dc5171abfe1eab3e95be964f61c5876198f1.zip |
Add multi-window support
Previously Alacritty would always initialize only a single terminal
emulator window feeding into the winit event loop, however some
platforms like macOS expect all windows to be spawned by the same
process and this "daemon-mode" can also come with the advantage of
increased memory efficiency.
The event loop has been restructured to handle all window-specific
events only by the event processing context with the associated window
id. This makes it possible to add new terminal windows at any time using
the WindowContext::new function call.
Some preliminary tests have shown that for empty terminals, this reduces
the cost of additional terminal emulators from ~100M to ~6M. However at
this point the robustness of the daemon against issues with individual
terminals has not been refined, making the reliability of this system
questionable.
New windows can be created either by using the new `CreateNewWindow`
action, or with the `alacritty msg create-window` subcommand. The
subcommand sends a message to an IPC socket which Alacritty listens on,
its location can be found in the `ALACRITTY_SOCKET` environment
variable.
Fixes #607.
Diffstat (limited to 'alacritty_terminal/src/tty')
-rw-r--r-- | alacritty_terminal/src/tty/unix.rs | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs index 483333e7..a52f8329 100644 --- a/alacritty_terminal/src/tty/unix.rs +++ b/alacritty_terminal/src/tty/unix.rs @@ -246,6 +246,16 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) -> } } +impl Drop for Pty { + fn drop(&mut self) { + // Make sure the PTY is terminated properly. + unsafe { + libc::kill(self.child.id() as i32, libc::SIGHUP); + } + let _ = self.child.wait(); + } +} + impl EventedReadWrite for Pty { type Reader = File; type Writer = File; @@ -339,6 +349,22 @@ impl EventedPty for Pty { } } +impl OnResize for Pty { + /// Resize the PTY. + /// + /// Tells the kernel that the window size changed with the new pixel + /// dimensions and line/column counts. + fn on_resize(&mut self, size: &SizeInfo) { + let win = size.to_winsize(); + + let res = unsafe { libc::ioctl(self.fd.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _) }; + + if res < 0 { + die!("ioctl TIOCSWINSZ failed: {}", io::Error::last_os_error()); + } + } +} + /// Types that can produce a `libc::winsize`. pub trait ToWinsize { /// Get a `libc::winsize`. @@ -356,22 +382,6 @@ impl<'a> ToWinsize for &'a SizeInfo { } } -impl OnResize for Pty { - /// Resize the PTY. - /// - /// Tells the kernel that the window size changed with the new pixel - /// dimensions and line/column counts. - fn on_resize(&mut self, size: &SizeInfo) { - let win = size.to_winsize(); - - let res = unsafe { libc::ioctl(self.fd.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _) }; - - if res < 0 { - die!("ioctl TIOCSWINSZ failed: {}", io::Error::last_os_error()); - } - } -} - unsafe fn set_nonblocking(fd: c_int) { use libc::{fcntl, F_GETFL, F_SETFL, O_NONBLOCK}; |