A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
feat(macos): list open Spaces in the Dock menu
RoversXed362c2871ef
diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rsindex 648f8be1..e8285106 100644--- a/wezterm-gui/src/frontend.rs+++ b/wezterm-gui/src/frontend.rs@@ -455,6 +455,15 @@ impl GuiFrontEnd {fn app_event_handler(event: ApplicationEvent) {log::trace!("Got app event {event:?}");match event {+ ApplicationEvent::DockMenuItem(owner) => {+ // A Space in the Dock menu: bring its window forward.+ let window = owner.parse().ok().and_then(|owner| {+ front_end().gui_window_for_recovery_slot(FrontendRecoverySlot::Window(owner))+ });+ if let Some(gui) = window {+ gui.window.focus();+ }+ }ApplicationEvent::OpenCommandScript(file_name) => {let quoted_file_name = match shlex::try_quote(&file_name) {Ok(name) => name.to_owned().to_string(),@@ -1205,10 +1214,40 @@ fn spawn_malloc_pressure_relief_thread() {#[cfg(not(target_os = "macos"))]fn spawn_malloc_pressure_relief_thread() {}+/// The Spaces open in windows, for the Dock menu: by name, the one in use+/// checked.+#[cfg(target_os = "macos")]+fn dock_menu_spaces() -> Vec<DockMenuItem> {+ let Some(front_end) = try_front_end() else {+ return vec![];+ };+ let mux = Mux::get();+ let in_use = mux+ .active_identity()+ .and_then(|client| mux.resolve_focused_pane(&client))+ .map(|(_domain, window_id, _tab_id, _pane_id)| window_id);+ let mut items: Vec<DockMenuItem> = crate::workspace_threads::open_spaces()+ .into_iter()+ .filter_map(|(owner, name)| {+ let gui =+ front_end.gui_window_for_recovery_slot(FrontendRecoverySlot::Window(owner))?;+ Some(DockMenuItem {+ title: name,+ checked: Some(gui.mux_window_id) == in_use,+ id: owner.to_string(),+ })+ })+ .collect();+ items.sort_by_key(|item| item.title.to_lowercase());+ items+}+pub fn try_new() -> Result<Rc<GuiFrontEnd>, Error> {let front_end = GuiFrontEnd::try_new()?;FRONT_END.with(|f| *f.borrow_mut() = Some(Rc::clone(&front_end)));crate::notification_click::install();+ #[cfg(target_os = "macos")]+ ::window::os::macos::set_dock_menu_items(dock_menu_spaces);let config_subscription = config::subscribe_to_config_reload({move || {diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rsindex 02e58fc9..42449809 100644--- a/wezterm-gui/src/workspace_threads.rs+++ b/wezterm-gui/src/workspace_threads.rs@@ -1284,6 +1284,20 @@ pub fn spaces_for_window(owner_id: u64) -> Vec<SpaceView> {views}+/// The Spaces windows show now, with the window owner showing each and the+/// Space's name.+pub fn open_spaces() -> Vec<(u64, String)> {+ // Copied out first: naming them takes the store's lock.+ let open: Vec<(u64, SpaceId)> = WINDOW_SPACES+ .lock()+ .iter()+ .map(|(owner, space)| (*owner, space.clone()))+ .collect();+ open.into_iter()+ .filter_map(|(owner, space)| Some((owner, active_space_name(&space)?)))+ .collect()+}+pub fn active_space_name(space_id: &str) -> Option<String> {let mut store = THREAD_STORE.lock();if store.normalize_after_load() {diff --git a/window/src/connection.rs b/window/src/connection.rsindex a0315357..2fc0eeb7 100644--- a/window/src/connection.rs+++ b/window/src/connection.rs@@ -51,6 +51,19 @@ pub enum ApplicationEvent {/// The system wants to open a command in the terminalOpenCommandScript(String),PerformKeyAssignment(KeyAssignment),+ /// One of the entries the app gave for its icon's menu in the Dock was+ /// chosen; this is its `DockMenuItem::id`.+ DockMenuItem(String),+}++/// An entry for the app's icon menu in the Dock (macOS).+#[derive(Clone, Debug, PartialEq)]+pub struct DockMenuItem {+ pub title: String,+ /// Shown with a check mark.+ pub checked: bool,+ /// What `ApplicationEvent::DockMenuItem` hands back when it is chosen.+ pub id: String,}pub trait ConnectionOps {diff --git a/window/src/os/macos/app.rs b/window/src/os/macos/app.rsindex 771d749a..b45dfe8a 100644--- a/window/src/os/macos/app.rs+++ b/window/src/os/macos/app.rs@@ -2,7 +2,7 @@ use crate::connection::ConnectionOps;use crate::macos::menu::RepresentedItem;use crate::macos::{nsstring, nsstring_to_str};use crate::menu::{Menu, MenuItem};-use crate::{ApplicationEvent, Connection};+use crate::{ApplicationEvent, Connection, DockMenuItem};use cocoa::appkit::{NSApp, NSApplicationTerminateReply, NSImage, NSImageNameApplicationIcon};use cocoa::base::{id, nil};use cocoa::foundation::{NSDictionary, NSInteger, NSUInteger};@@ -12,10 +12,22 @@ use objc::declare::ClassDecl;use objc::rc::StrongPtr;use objc::runtime::{Class, Object, Sel, BOOL, NO, YES};use objc::*;+use std::cell::RefCell;use std::path::{Path, PathBuf};const CLS_NAME: &str = "WezTermAppDelegate";+thread_local! {+ static DOCK_MENU_ITEMS: RefCell<Option<Box<dyn Fn() -> Vec<DockMenuItem>>>> =+ RefCell::new(None);+}++/// Have the Dock menu list the entries `items` gives, asked each time it+/// opens; choosing one sends `ApplicationEvent::DockMenuItem`.+pub fn set_dock_menu_items(items: impl Fn() -> Vec<DockMenuItem> + 'static) {+ DOCK_MENU_ITEMS.with(|slot| *slot.borrow_mut() = Some(Box::new(items)));+}+#[link(name = "AppKit", kind = "framework")]extern "C" {static NSAboutPanelOptionApplicationName: id;@@ -151,10 +163,24 @@ extern "C" fn wezterm_perform_key_assignment(}}Some(RepresentedItem::ContextMenuAction(_)) => {}+ Some(RepresentedItem::DockMenuItem(_)) => {}None => {}}}+extern "C" fn thinkterm_choose_dock_menu_item(+ _self: &mut Object,+ _sel: Sel,+ menu_item: *mut Object,+) {+ let menu_item = crate::os::macos::menu::MenuItem::with_menu_item(menu_item);+ if let Some(RepresentedItem::DockMenuItem(id)) = menu_item.get_represented_item() {+ if let Some(conn) = Connection::get() {+ conn.dispatch_app_event(ApplicationEvent::DockMenuItem(id));+ }+ }+}+extern "C" fn thinkterm_order_front_standard_about_panel(_self: &mut Object,_sel: Sel,@@ -231,6 +257,22 @@ extern "C" fn application_dock_menu(new_window_item.set_represented_item(RepresentedItem::KeyAssignment(KeyAssignment::SpawnWindow));dock_menu.add_item(&new_window_item);+ let items = DOCK_MENU_ITEMS.with(|slot| {+ slot.borrow()+ .as_ref()+ .map(|items| items())+ .unwrap_or_default()+ });+ if !items.is_empty() {+ dock_menu.add_item(&MenuItem::new_separator());+ }+ for item in items {+ let menu_item =+ MenuItem::new_with(&item.title, Some(sel!(thinktermChooseDockMenuItem:)), "");+ menu_item.set_checked(item.checked);+ menu_item.set_represented_item(RepresentedItem::DockMenuItem(item.id));+ dock_menu.add_item(&menu_item);+ }dock_menu.autorelease()}@@ -267,6 +309,10 @@ fn get_class() -> &'static Class {sel!(weztermPerformKeyAssignment:),wezterm_perform_key_assignment as extern "C" fn(&mut Object, Sel, *mut Object),);+ cls.add_method(+ sel!(thinktermChooseDockMenuItem:),+ thinkterm_choose_dock_menu_item as extern "C" fn(&mut Object, Sel, *mut Object),+ );cls.add_method(sel!(thinktermOrderFrontStandardAboutPanel:),thinkterm_order_front_standard_about_paneldiff --git a/window/src/os/macos/menu.rs b/window/src/os/macos/menu.rsindex 9e18cd13..ceb00815 100644--- a/window/src/os/macos/menu.rs+++ b/window/src/os/macos/menu.rs@@ -206,6 +206,8 @@ pub struct MenuItem {pub enum RepresentedItem {KeyAssignment(KeyAssignment),ContextMenuAction(ContextMenuAction),+ /// An app-given entry of the Dock menu, by its id.+ DockMenuItem(String),}impl RepresentedItem {diff --git a/window/src/os/macos/mod.rs b/window/src/os/macos/mod.rsindex 87be6605..e75a0924 100644--- a/window/src/os/macos/mod.rs+++ b/window/src/os/macos/mod.rs@@ -15,6 +15,7 @@ pub mod window;mod keycodes;pub use self::window::*;+pub use app::set_dock_menu_items;pub use bitmap::*;pub use connection::*;diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rsindex 51b2fa86..bfb3b102 100644--- a/window/src/os/macos/window.rs+++ b/window/src/os/macos/window.rs@@ -3754,7 +3754,8 @@ impl WindowView {this.inner.borrow_mut().events.dispatch(event);}}- None => {}+ // The Dock menu's own entries go to the app delegate.+ Some(RepresentedItem::DockMenuItem(_)) | None => {}}}