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/cli.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'alacritty/src/cli.rs') diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs index b1e12007..ce0563ff 100644 --- a/alacritty/src/cli.rs +++ b/alacritty/src/cli.rs @@ -10,7 +10,7 @@ use alacritty_terminal::config::Program; use crate::config::window::{Class, DEFAULT_NAME}; use crate::config::{serde_utils, Config}; -/// Options specified on the command line. +/// CLI options for the main Alacritty executable. #[derive(StructOpt, Debug)] #[structopt(author, about, version = env!("VERSION"))] pub struct Options { @@ -57,9 +57,10 @@ pub struct Options { #[structopt(long)] pub hold: bool, - /// CLI options for config overrides. - #[structopt(skip)] - pub config_options: Value, + /// Path for IPC socket creation. + #[cfg(unix)] + #[structopt(long)] + pub socket: Option, /// Reduces the level of verbosity (the min level is -qq). #[structopt(short, conflicts_with("verbose"), parse(from_occurrences))] @@ -76,6 +77,15 @@ pub struct Options { /// Override configuration file options [example: cursor.style=Beam]. #[structopt(short = "o", long)] option: Vec, + + /// CLI options for config overrides. + #[structopt(skip)] + pub config_options: Value, + + /// Subcommand passed to the CLI. + #[cfg(unix)] + #[structopt(subcommand)] + pub subcommands: Option, } impl Options { @@ -118,6 +128,11 @@ impl Options { config.ui_config.window.class = class.clone(); } + #[cfg(unix)] + { + config.ui_config.ipc_socket |= self.socket.is_some(); + } + config.ui_config.window.dynamic_title &= self.title.is_none(); config.ui_config.window.embed = self.embed.as_ref().and_then(|embed| embed.parse().ok()); config.ui_config.debug.print_events |= self.print_events; @@ -199,6 +214,34 @@ fn parse_class(input: &str) -> Result { } } +/// Available CLI subcommands. +#[cfg(unix)] +#[derive(StructOpt, Debug)] +pub enum Subcommands { + Msg(MessageOptions), +} + +/// Send a message to the Alacritty socket. +#[cfg(unix)] +#[derive(StructOpt, Debug)] +pub struct MessageOptions { + /// IPC socket connection path override. + #[structopt(long, short)] + pub socket: Option, + + /// Message which should be sent. + #[structopt(subcommand)] + pub message: SocketMessage, +} + +/// Available socket messages. +#[cfg(unix)] +#[derive(StructOpt, Debug)] +pub enum SocketMessage { + /// Create a new window in the same Alacritty process. + CreateWindow, +} + #[cfg(test)] mod tests { use super::*; -- cgit