From bbe317438192ee695c86b904ff6e1f3843eb94c2 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Mon, 7 Aug 2023 23:14:53 +0200 Subject: [PATCH] Copy global IPC options for new windows This patch stores all options set for the Window ID `-1` and automatically applies them to new windows after their creation. This in theory makes it possible to have a fully dynamic "default config" without having to reapply it for every new window. Closes #7128. --- CHANGELOG.md | 1 + alacritty/src/event.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 927ca0d3..5d66beeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Support for dynamically loading conpty.dll on Windows - Support for keybindings with dead keys - `Back`/`Forward` mouse buttons support in bindings +- Copy global IPC options (`-w -1`) for new windows ### Changed diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 0ffc46a0..add30722 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -1403,6 +1403,8 @@ pub struct Processor { #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] wayland_event_queue: Option, windows: HashMap, + #[cfg(unix)] + global_ipc_options: Vec, cli_options: CliOptions, config: Rc, } @@ -1424,11 +1426,13 @@ impl Processor { }); Processor { - windows: Default::default(), config: Rc::new(config), cli_options, #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] wayland_event_queue, + #[cfg(unix)] + global_ipc_options: Default::default(), + windows: Default::default(), } } @@ -1464,7 +1468,9 @@ impl Processor { options: WindowOptions, ) -> Result<(), Box> { let window = self.windows.iter().next().as_ref().unwrap().1; - let window_context = window.additional( + + #[allow(unused_mut)] + let mut window_context = window.additional( event_loop, proxy, self.config.clone(), @@ -1473,6 +1479,14 @@ impl Processor { self.wayland_event_queue.as_ref(), )?; + // Apply global IPC options. + #[cfg(unix)] + { + let options = self.global_ipc_options.clone(); + let ipc_config = IpcConfig { options, window_id: None, reset: false }; + window_context.update_ipc_config(self.config.clone(), ipc_config); + } + self.windows.insert(window_context.id(), window_context); Ok(()) } @@ -1609,6 +1623,15 @@ impl Processor { payload: EventType::IpcConfig(ipc_config), window_id, }) => { + // Persist global options for future windows. + if window_id.is_none() { + if ipc_config.reset { + self.global_ipc_options.clear(); + } else { + self.global_ipc_options.extend_from_slice(&ipc_config.options); + } + } + for (_, window_context) in self .windows .iter_mut()