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/src/renderer/mod.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'alacritty/src/renderer/mod.rs') diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index 23be70be..b9ec728c 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -673,11 +673,7 @@ impl QuadRenderer { gl::BlendFunc(gl::SRC1_COLOR, gl::ONE_MINUS_SRC1_COLOR); // Restore viewport with padding. - let padding_x = size_info.padding_x() as i32; - let padding_y = size_info.padding_y() as i32; - let width = size_info.width() as i32; - let height = size_info.height() as i32; - gl::Viewport(padding_x, padding_y, width - 2 * padding_x, height - 2 * padding_y); + self.set_viewport(&size_info); } } @@ -730,15 +726,9 @@ impl QuadRenderer { }) } - pub fn resize(&mut self, size: &SizeInfo) { - // Viewport. + pub fn resize(&self, size: &SizeInfo) { unsafe { - gl::Viewport( - size.padding_x() as i32, - size.padding_y() as i32, - size.width() as i32 - 2 * size.padding_x() as i32, - size.height() as i32 - 2 * size.padding_y() as i32, - ); + self.set_viewport(size); // Update projection. gl::UseProgram(self.program.id); @@ -751,6 +741,19 @@ impl QuadRenderer { gl::UseProgram(0); } } + + /// Set the viewport for cell rendering. + #[inline] + pub fn set_viewport(&self, size: &SizeInfo) { + unsafe { + gl::Viewport( + size.padding_x() as i32, + size.padding_y() as i32, + size.width() as i32 - 2 * size.padding_x() as i32, + size.height() as i32 - 2 * size.padding_y() as i32, + ); + } + } } impl Drop for QuadRenderer { -- cgit