term can now notify application about potential title updates

When the title, icon, OSC 7 and SetUserVars sequences are processed,
notify the embedding application.

The gui layer uses this to trigger a titlebar update.

refs: #647
This commit is contained in:
Wez Furlong committed 2021-04-30 07:28:02 -07:00
1 parent 35eb7383b1
commit 0316dfeb83
4 files changed
+66 -24

No files matched your search

+3
View File
@@ -48,6 +48,9 @@ pub enum Alert {
/// window/tab/pane that generated it
focus: bool,
},
/// When the title, or something that likely influences the title,
/// has been changed
TitleMaybeChanged,
}
pub trait AlertHandler {
+15
View File
@@ -3274,15 +3274,24 @@ impl<'a> Performer<'a> {
} else {
self.icon_title = Some(title.clone());
}
if let Some(handler) = self.alert_handler.as_mut() {
handler.alert(Alert::TitleMaybeChanged);
}
}
OperatingSystemCommand::SetIconNameAndWindowTitle(title) => {
self.icon_title.take();
self.title = title.clone();
if let Some(handler) = self.alert_handler.as_mut() {
handler.alert(Alert::TitleMaybeChanged);
}
}
OperatingSystemCommand::SetWindowTitleSun(title)
| OperatingSystemCommand::SetWindowTitle(title) => {
self.title = title.clone();
if let Some(handler) = self.alert_handler.as_mut() {
handler.alert(Alert::TitleMaybeChanged);
}
}
OperatingSystemCommand::SetHyperlink(link) => {
self.set_hyperlink(link);
@@ -3312,6 +3321,9 @@ impl<'a> Performer<'a> {
ITermProprietary::File(image) => self.set_image(*image),
ITermProprietary::SetUserVar { name, value } => {
self.user_vars.insert(name, value);
if let Some(handler) = self.alert_handler.as_mut() {
handler.alert(Alert::TitleMaybeChanged);
}
}
_ => log::warn!("unhandled iterm2: {:?}", iterm),
},
@@ -3389,6 +3401,9 @@ impl<'a> Performer<'a> {
}
OperatingSystemCommand::CurrentWorkingDirectory(url) => {
self.current_dir = Url::parse(&url).ok();
if let Some(handler) = self.alert_handler.as_mut() {
handler.alert(Alert::TitleMaybeChanged);
}
}
OperatingSystemCommand::ChangeColorNumber(specs) => {
log::trace!("ChangeColorNumber: {:?}", specs);
+4
View File
@@ -58,6 +58,10 @@ impl GuiFrontEnd {
// persistent_toast_notification("Ding!", "This is the bell");
log::info!("Ding! (this is the bell)");
}
MuxNotification::Alert {
pane_id: _,
alert: Alert::TitleMaybeChanged,
} => {}
}
true
} else {
+44 -24
View File
@@ -46,7 +46,7 @@ use termwiz::image::ImageData;
use wezterm_font::FontConfiguration;
use wezterm_term::color::ColorPalette;
use wezterm_term::input::LastMouseClick;
use wezterm_term::{StableRowIndex, TerminalConfiguration};
use wezterm_term::{Alert, StableRowIndex, TerminalConfiguration};
pub mod clipboard;
mod keyevent;
@@ -663,35 +663,55 @@ impl TermWindow {
return false;
}
if let MuxNotification::PaneOutput(pane_id) = n {
let mut pane_in_window = false;
match n {
MuxNotification::Alert {
pane_id,
alert: Alert::TitleMaybeChanged,
}
| MuxNotification::PaneOutput(pane_id) => {
let mut pane_in_window = false;
let mux = Mux::get().expect("mux is calling us");
if let Some(mux_window) = mux.get_window(mux_window_id) {
for tab in mux_window.iter() {
if tab.contains_pane(pane_id) {
pane_in_window = true;
break;
let mux = Mux::get().expect("mux is calling us");
if let Some(mux_window) = mux.get_window(mux_window_id) {
for tab in mux_window.iter() {
if tab.contains_pane(pane_id) {
pane_in_window = true;
break;
}
}
} else {
// Something inconsistent: cancel subscription
return false;
}
if !pane_in_window {
return true;
}
}
_ => return true,
}
let dead = Arc::clone(dead);
window.apply(move |myself, _window| {
if let Some(myself) = myself.downcast_mut::<Self>() {
match n {
MuxNotification::Alert {
alert: Alert::TitleMaybeChanged,
..
} => {
myself.update_title();
}
MuxNotification::PaneOutput(pane_id) => {
myself.mux_pane_output_event(pane_id);
}
_ => {}
}
} else {
// Something inconsistent: cancel subscription
return false;
dead.store(true, Ordering::Relaxed);
}
if pane_in_window {
let dead = Arc::clone(dead);
window.apply(move |myself, _window| {
if let Some(myself) = myself.downcast_mut::<Self>() {
myself.mux_pane_output_event(pane_id);
} else {
// Something inconsistent: cancel subscription
dead.store(true, Ordering::Relaxed);
}
Ok(())
});
}
}
Ok(())
});
true
}