From c042005ee02c3754ef8824bdfda55695ee20a0f1 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 19 Jan 2023 07:45:44 -0700 Subject: [PATCH] mux: try harder to use default_workspace from config There were a couple of cases where we didn't look at the config when deciding on the workspace name. refs: https://github.com/wez/wezterm/issues/2981 --- docs/changelog.md | 2 ++ mux/src/lib.rs | 13 +++++++++++-- wezterm-gui/src/main.rs | 13 ++++++------- wezterm/src/main.rs | 10 +++++++++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 8e76538d0..668324027 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -71,6 +71,8 @@ As features stabilize some brief notes about them will accumulate here. * Wayland: mouse cursor didn't auto-hide when typing. Thanks to [@jmbaur](https://github.com/jmbaur)! [#2977](https://github.com/wez/wezterm/pull/2977) +* mux: `default_workspace` was not always respected when spawning + [#2981](https://github.com/wez/wezterm/issues/2981) #### Changed * `CTRL-SHIFT-P` now activates the new command palette, instead of `PaneSelect` diff --git a/mux/src/lib.rs b/mux/src/lib.rs index e772d6448..51b335d81 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -392,6 +392,15 @@ impl Mux { } } + fn get_default_workspace(&self) -> String { + let config = configuration(); + config + .default_workspace + .as_deref() + .unwrap_or(DEFAULT_WORKSPACE) + .to_string() + } + pub fn is_main_thread(&self) -> bool { std::thread::current().id() == self.main_thread_id } @@ -496,7 +505,7 @@ impl Mux { .get(&ident) .and_then(|info| info.active_workspace.clone()) }) - .unwrap_or_else(|| DEFAULT_WORKSPACE.to_string()) + .unwrap_or_else(|| self.get_default_workspace()) } /// Returns the effective active workspace name for a given client @@ -505,7 +514,7 @@ impl Mux { .read() .get(&ident) .and_then(|info| info.active_workspace.clone()) - .unwrap_or_else(|| DEFAULT_WORKSPACE.to_string()) + .unwrap_or_else(|| self.get_default_workspace()) } pub fn set_active_workspace_for_client(&self, ident: &Arc, workspace: &str) { diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 3b2ecd8cd..2cddf74b0 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -642,14 +642,13 @@ fn setup_mux( let client_id = Arc::new(mux::client::ClientId::new()); mux.register_client(client_id.clone()); mux.replace_identity(Some(client_id)); - mux.set_active_workspace( - default_workspace_name.unwrap_or( - config - .default_workspace - .as_deref() - .unwrap_or(mux::DEFAULT_WORKSPACE), - ), + let default_workspace_name = default_workspace_name.unwrap_or( + config + .default_workspace + .as_deref() + .unwrap_or(mux::DEFAULT_WORKSPACE), ); + mux.set_active_workspace(&default_workspace_name); crate::update::load_last_release_info_and_set_banner(); update_mux_domains(config)?; diff --git a/wezterm/src/main.rs b/wezterm/src/main.rs index 320c03bfb..e49417201 100644 --- a/wezterm/src/main.rs +++ b/wezterm/src/main.rs @@ -1121,7 +1121,15 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow: } }; - let workspace = workspace.unwrap_or_else(|| mux::DEFAULT_WORKSPACE.to_string()); + let workspace = workspace + .as_deref() + .unwrap_or( + config + .default_workspace + .as_deref() + .unwrap_or(mux::DEFAULT_WORKSPACE), + ) + .to_string(); let size = config.initial_size(0);