Repository: alacritty/alacritty (language: rust)

Issue:
Setting title doesn't work in terminals launched via 'msg create-window' when instance was created with `--title`
Hello,

When I launch a terminal with "alacritty" that terminal's title is updated with the running command / pwd as I do stuff in it. When I launch` a terminal with "alacritty msg create-window" the title isn't being updated, it just stays as "Alacritty"

the zsh snippet responsible for updating the terminals title is:
```
case $TERM in
    xterm*|alacritty)
        preexec () {
	    print -Pn "\e]0;$1\a"
	}
	precmd () {
	    print -Pn "\e]0;$PWD\a"
	}
        ;;
esac
```

### System

OS: Fedora Linux 39 (Rawhide Prerelease)
Version: alacritty 0.10.1
Linux/BSD: X11 i3wm





Discussion / hints:
Maybe your snippet is not being red in this case?

I'd assume that if you manually request to set title with one of those escapes it'll work just fine.
if I run `print -Pn "\e]0;FOO\a"` in the shell (zsh) the title of the alacritty terminal window remains "Alacritty"

so no, it doesn't work just fine in that case either
Are you sure that you're not disabling title setting somewhere in the config or launch with the `--title`? You can try default config `alacritty --config-file=/dev/null` and then create by `alacritty msg create-window`.
Ah, I see, somewhere I did launch another alacritty with --title, and now all my terminals are children of that process, and those are the ones where setting the title isn't working.

It seems like either children of alacritty process started with `--title` should be able to set their own title, or those children should use the title set with `--title` too. 
Hm, yeah, you're correct.

I think we shouldn't persist the `--title` on the CLI for the terminals created with the `alacritty msg create-window`.

Not sure about the binding though, what do you think @chrisduerr ? The issue is that running `alacritty --title foo` will create an instance with title `foo`, but then `alacritty msg create-window` will create a window with fixed title `Alacritty`(default).
Should probably be persisted, yeah.
Persisted or reset to dynamic one? I think we should reset to dynamic, because `alacritty msg create-window` has the `--title` option?
Honestly I don't really care either way.
making children handle their own titles dynamically would be appreciated here (until then children are unusable because they can't be differentiated in window switcher 😅

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b41ed24fb0e..959ae73e38b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its
 - Crash when trying to create a new tab without decorations enabled
 - New window being treated as focused when it's not on Wayland
 - IME preview blending into text below it
+- Dynamic title disabled for new windows when initial one has title as CLI option
 
 ## 0.13.2
 
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs
index 91ba2fd606d..e7f2d3efd7e 100644
--- a/alacritty/src/cli.rs
+++ b/alacritty/src/cli.rs
@@ -92,7 +92,6 @@ impl Options {
             config.ipc_socket |= self.socket.is_some();
         }
 
-        config.window.dynamic_title &= self.window_options.window_identity.title.is_none();
         config.window.embed = self.embed.as_ref().and_then(|embed| parse_hex_or_decimal(embed));
         config.debug.print_events |= self.print_events;
         config.debug.log_level = max(config.debug.log_level, self.log_level());
@@ -425,19 +424,6 @@ mod tests {
         assert_eq!(old_dynamic_title, config.window.dynamic_title);
     }
 
-    #[test]
-    fn dynamic_title_overridden_by_options() {
-        let mut config = UiConfig::default();
-
-        let title = Some(String::from("foo"));
-        let window_identity = WindowIdentity { title, ..WindowIdentity::default() };
-        let new_window_options = WindowOptions { window_identity, ..WindowOptions::default() };
-        let mut options = Options { window_options: new_window_options, ..Options::default() };
-        options.override_config(&mut config);
-
-        assert!(!config.window.dynamic_title);
-    }
-
     #[test]
     fn dynamic_title_not_overridden_by_config() {
         let mut config = UiConfig::default();
diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs
index 4fa397adcc2..5276776a90f 100644
--- a/alacritty/src/event.rs
+++ b/alacritty/src/event.rs
@@ -217,6 +217,7 @@ pub struct ActionContext<'a, N, T> {
     pub message_buffer: &'a mut MessageBuffer,
     pub config: &'a UiConfig,
     pub cursor_blink_timed_out: &'a mut bool,
+    #[cfg(target_os = "macos")]
     pub event_loop: &'a EventLoopWindowTarget<Event>,
     pub event_proxy: &'a EventLoopProxy<Event>,
     pub scheduler: &'a mut Scheduler,
@@ -1213,7 +1214,6 @@ pub struct Mouse {
     pub click_state: ClickState,
     pub accumulated_scroll: AccumulatedScroll,
     pub cell_side: Side,
-    pub lines_scrolled: f32,
     pub block_hint_launcher: bool,
     pub hint_highlight_dirty: bool,
     pub inside_text_area: bool,
@@ -1234,7 +1234,6 @@ impl Default for Mouse {
             hint_highlight_dirty: Default::default(),
             block_hint_launcher: Default::default(),
             inside_text_area: Default::default(),
-            lines_scrolled: Default::default(),
             accumulated_scroll: Default::default(),
             x: Default::default(),
             y: Default::default(),
@@ -1313,7 +1312,7 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> {
                     },
                     TerminalEvent::ResetTitle => {
                         let window_config = &self.ctx.config.window;
-                        if window_config.dynamic_title {
+                        if !self.ctx.preserve_title && window_config.dynamic_title {
                             self.ctx.display.window.set_title(window_config.identity.title.clone());
                         }
                     },
@@ -1694,6 +1693,7 @@ impl Processor {
                     };
 
                     window_context.handle_event(
+                        #[cfg(target_os = "macos")]
                         event_loop,
                         &proxy,
                         &mut clipboard,
@@ -1708,6 +1708,7 @@ impl Processor {
                     // Dispatch event to all windows.
                     for window_context in self.windows.values_mut() {
                         window_context.handle_event(
+                            #[cfg(target_os = "macos")]
                             event_loop,
                             &proxy,
                             &mut clipboard,
@@ -1794,6 +1795,7 @@ impl Processor {
                 WinitEvent::UserEvent(event @ Event { window_id: None, .. }) => {
                     for window_context in self.windows.values_mut() {
                         window_context.handle_event(
+                            #[cfg(target_os = "macos")]
                             event_loop,
                             &proxy,
                             &mut clipboard,
@@ -1807,6 +1809,7 @@ impl Processor {
                 | WinitEvent::UserEvent(Event { window_id: Some(window_id), .. }) => {
                     if let Some(window_context) = self.windows.get_mut(&window_id) {
                         window_context.handle_event(
+                            #[cfg(target_os = "macos")]
                             event_loop,
                             &proxy,
                             &mut clipboard,
diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs
index 891551bbf6b..f0f24fe841f 100644
--- a/alacritty/src/window_context.rs
+++ b/alacritty/src/window_context.rs
@@ -399,7 +399,7 @@ impl WindowContext {
     /// Process events for this terminal window.
     pub fn handle_event(
         &mut self,
-        event_loop: &EventLoopWindowTarget<Event>,
+        #[cfg(target_os = "macos")] event_loop: &EventLoopWindowTarget<Event>,
         event_proxy: &EventLoopProxy<Event>,
         clipboard: &mut Clipboard,
         scheduler: &mut Scheduler,
@@ -445,6 +445,7 @@ impl WindowContext {
             preserve_title: self.preserve_title,
             config: &self.config,
             event_proxy,
+            #[cfg(target_os = "macos")]
             event_loop,
             clipboard,
             scheduler,


Test patch: