From 1df7dc5171abfe1eab3e95be964f61c5876198f1 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 23 Oct 2021 07:16:47 +0000 Subject: 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. --- alacritty_terminal/src/tty/unix.rs | 42 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'alacritty_terminal/src/tty/unix.rs') 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(config: &Config, size: &SizeInfo, window_id: Option) -> } } +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}; -- cgit