Repository: alacritty/alacritty (language: rust)

Issue:
`--daemon` mode ignores `-e` for first window with `msg create-window`
I use another terminal to not interfere with alacritty instances. Then do:
- `alacritty --daemon`
- `alacritty msg create-window -e nnn`

→ Alacritty opens and is a child process of the daemon, as it should. It is a blank, interactive terminal window though. `nnn` (or any other command) did not execute. When using `alacritty msg create-window -e nnn` a second time, even after closing the first window, it works as intended.

### System

OS: Linux
Version: alacritty 0.14.0 (22a44757)
Linux/BSD: X11, i3wm

### Logs

Sadly, nothing of value. `alacritty msg create-window -e nnn` does not produce any output.

`alacritty --daemon` produces the following. 6.[…] is the first, unsuccessful use of `alacritty msg create-window`, 9.[…] is the second one.
```
❯ alacritty --daemon
ALACRITTY_SOCKET=/run/user/1000/Alacritty-:0-4690.sock; export ALACRITTY_SOCKET
Created log file at "/tmp/Alacritty-4690.log"
[6.685035667s] [INFO ] [alacritty] Using GLX 1.4
[6.731810987s] [DEBUG] [alacritty] Picked GL Config:
                                     buffer_type: Some(Rgb { r_size: 8, g_size: 8, b_size: 8 })
                                     alpha_size: 8
                                     num_samples: 0
                                     hardware_accelerated: true
                                     supports_transparency: Some(true)
                                     config_api: Api(OPENGL | GLES1 | GLES2)
                                     srgb_capable: false
[6.733080791s] [INFO ] [alacritty] Window scale factor: 1.1354166666666667
[6.735497376s] [DEBUG] [alacritty] Loading "monospace" font
[6.747956223s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Regular, load_flags: LoadFlag(0x0), render_mode: "Normal", lcd_filter: 1 }
[6.751520900s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Bold, load_flags: LoadFlag(0x0), render_mode: "Normal", lcd_filter: 1 }
[6.755152785s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Regular, load_flags: LoadFlag(NO_BITMAP), render_mode: "Normal", lcd_filter: 1 }
[6.758946778s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Bold, load_flags: LoadFlag(NO_BITMAP), render_mode: "Normal", lcd_filter: 1 }
[6.762142955s] [INFO ] [alacritty] Running on AMD Radeon RX 580 Series (radeonsi, polaris10, LLVM 18.1.8, DRM 3.59, 6.11.11-hardened1-1-hardened)
[6.762156901s] [INFO ] [alacritty] OpenGL version 4.6 (Core Profile) Mesa 24.3.1-arch1.3, shader_version 4.60
[6.762167441s] [INFO ] [alacritty] Using OpenGL 3.3 renderer
[6.776950928s] [DEBUG] [alacritty] Enabled debug logging for OpenGL
[6.777039627s] [DEBUG] [alacritty] Filling glyph cache with common glyphs
[6.798030936s] [INFO ] [alacritty] Cell size: 12 x 26
[6.798055242s] [INFO ] [alacritty] Padding: 4 x 1
[6.798064319s] [INFO ] [alacritty] Width: 800, Height: 600
[6.804284075s] [INFO ] [alacritty] PTY dimensions: 23 x 66
[6.811177551s] [DEBUG] [alacritty_terminal] New num_cols is 105 and num_lines is 26
[6.813260831s] [INFO ] [alacritty] Padding: 3 x 7
[6.813277253s] [INFO ] [alacritty] Width: 1266, Height: 690
[6.917197337s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Regular, load_flags: LoadFlag(0x0), render_mode: "Normal", lcd_filter: 1 }
[6.917597738s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Regular, load_flags: LoadFlag(0x0), render_mode: "Normal", lcd_filter: 1 }
[9.726376377s] [INFO ] [alacritty] Window scale factor: 1.1354166666666667
[9.728275928s] [DEBUG] [alacritty] Loading "monospace" font
[9.730893835s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Regular, load_flags: LoadFlag(0x0), render_mode: "Normal", lcd_filter: 1 }
[9.734716353s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Bold, load_flags: LoadFlag(0x0), render_mode: "Normal", lcd_filter: 1 }
[9.738351434s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Regular, load_flags: LoadFlag(NO_BITMAP), render_mode: "Normal", lcd_filter: 1 }
[9.742213867s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Bold, load_flags: LoadFlag(NO_BITMAP), render_mode: "Normal", lcd_filter: 1 }
[9.744627586s] [INFO ] [alacritty] Running on AMD Radeon RX 580 Series (radeonsi, polaris10, LLVM 18.1.8, DRM 3.59, 6.11.11-hardened1-1-hardened)
[9.744640250s] [INFO ] [alacritty] OpenGL version 4.6 (Core Profile) Mesa 24.3.1-arch1.3, shader_version 4.60
[9.744648687s] [INFO ] [alacritty] Using OpenGL 3.3 renderer
[9.746431446s] [DEBUG] [alacritty] Enabled debug logging for OpenGL
[9.746509915s] [DEBUG] [alacritty] Filling glyph cache with common glyphs
[9.762323680s] [INFO ] [alacritty] Cell size: 12 x 26
[9.762351894s] [INFO ] [alacritty] Padding: 4 x 1
[9.762362313s] [INFO ] [alacritty] Width: 800, Height: 600
[9.765687004s] [INFO ] [alacritty] PTY dimensions: 23 x 66
[9.771741265s] [DEBUG] [alacritty_terminal] New num_cols is 105 and num_lines is 17
[9.774571766s] [INFO ] [alacritty] Padding: 3 x 6
[9.774589039s] [INFO ] [alacritty] Width: 1266, Height: 455
[9.775390092s] [DEBUG] [alacritty_terminal] New num_cols is 105 and num_lines is 17
[9.775689692s] [INFO ] [alacritty] Padding: 3 x 8
[9.775704119s] [INFO ] [alacritty] Width: 1266, Height: 459
[9.775863562s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Regular, load_flags: LoadFlag(0x0), render_mode: "Normal", lcd_filter: 1 }
[9.785250999s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Regular, load_flags: LoadFlag(0x0), render_mode: "Normal", lcd_filter: 1 }
```


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f2ca2761c5f..94672511797 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its
 - `SemanticRight`/`SemanticLeft` vi motions breaking with wide semantic escape characters
 - `alacritty migrate` crashing with recursive toml imports
 - Migrating nonexistent toml import breaking the entire migration
+- First daemon mode window ignoring window options passed through CLI
 
 ## 0.14.0
 
diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs
index e82d797475f..79f31eef044 100644
--- a/alacritty/src/event.rs
+++ b/alacritty/src/event.rs
@@ -140,14 +140,14 @@ impl Processor {
     pub fn create_initial_window(
         &mut self,
         event_loop: &ActiveEventLoop,
+        window_options: WindowOptions,
     ) -> Result<(), Box<dyn Error>> {
-        let options = match self.initial_window_options.take() {
-            Some(options) => options,
-            None => return Ok(()),
-        };
-
-        let window_context =
-            WindowContext::initial(event_loop, self.proxy.clone(), self.config.clone(), options)?;
+        let window_context = WindowContext::initial(
+            event_loop,
+            self.proxy.clone(),
+            self.config.clone(),
+            window_options,
+        )?;
 
         self.gl_config = Some(window_context.display.gl_context().config());
         self.windows.insert(window_context.id(), window_context);
@@ -225,10 +225,12 @@ impl ApplicationHandler<Event> for Processor {
             return;
         }
 
-        if let Err(err) = self.create_initial_window(event_loop) {
-            self.initial_window_error = Some(err);
-            event_loop.exit();
-            return;
+        if let Some(window_options) = self.initial_window_options.take() {
+            if let Err(err) = self.create_initial_window(event_loop, window_options) {
+                self.initial_window_error = Some(err);
+                event_loop.exit();
+                return;
+            }
         }
 
         info!("Initialisation complete");
@@ -276,7 +278,7 @@ impl ApplicationHandler<Event> for Processor {
         }
 
         // Handle events which don't mandate the WindowId.
-        match (&event.payload, event.window_id.as_ref()) {
+        match (event.payload, event.window_id.as_ref()) {
             // Process IPC config update.
             #[cfg(unix)]
             (EventType::IpcConfig(ipc_config), window_id) => {
@@ -315,7 +317,7 @@ impl ApplicationHandler<Event> for Processor {
                 }
 
                 // Load config and update each terminal.
-                if let Ok(config) = config::reload(path, &mut self.cli_options) {
+                if let Ok(config) = config::reload(&path, &mut self.cli_options) {
                     self.config = Rc::new(config);
 
                     // Restart config monitor if imports changed.
@@ -346,17 +348,17 @@ impl ApplicationHandler<Event> for Processor {
 
                 if self.gl_config.is_none() {
                     // Handle initial window creation in daemon mode.
-                    if let Err(err) = self.create_initial_window(event_loop) {
+                    if let Err(err) = self.create_initial_window(event_loop, options) {
                         self.initial_window_error = Some(err);
                         event_loop.exit();
                     }
-                } else if let Err(err) = self.create_window(event_loop, options.clone()) {
+                } else if let Err(err) = self.create_window(event_loop, options) {
                     error!("Could not open window: {:?}", err);
                 }
             },
             // Process events affecting all windows.
-            (_, None) => {
-                let event = WinitEvent::UserEvent(event);
+            (payload, None) => {
+                let event = WinitEvent::UserEvent(Event::new(payload, None));
                 for window_context in self.windows.values_mut() {
                     window_context.handle_event(
                         #[cfg(target_os = "macos")]
@@ -405,7 +407,7 @@ impl ApplicationHandler<Event> for Processor {
                     }
                 }
             },
-            (_, Some(window_id)) => {
+            (payload, Some(window_id)) => {
                 if let Some(window_context) = self.windows.get_mut(window_id) {
                     window_context.handle_event(
                         #[cfg(target_os = "macos")]
@@ -413,7 +415,7 @@ impl ApplicationHandler<Event> for Processor {
                         &self.proxy,
                         &mut self.clipboard,
                         &mut self.scheduler,
-                        WinitEvent::UserEvent(event),
+                        WinitEvent::UserEvent(Event::new(payload, *window_id)),
                     );
                 }
             },


Test patch: