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
mux: pane readers that can be parked, and ids a successor server can keep
RoversX34349f27d35f
diff --git a/mux/src/lib.rs b/mux/src/lib.rsindex b96b3ecb..4ccd7b1d 100644--- a/mux/src/lib.rs+++ b/mux/src/lib.rs@@ -625,8 +625,12 @@ fn parse_buffered_data(dead: &Arc<AtomicBool>,mut rx: FileDescriptor,heartbeat: Arc<parse_watchdog::ParseHeartbeat>,+ control: Option<Arc<ReaderControl>>,) {let mut buf = vec![0; configuration().mux_output_parser_buffer_size];+ // Bytes read and not yet turned into applied actions; settled against+ // the reader's count whenever nothing is left waiting to be sent.+ let mut unapplied = 0usize;let mut parser = termwiz::escape::parser::Parser::new();let mut actions = vec![];let mut hold = false;@@ -645,6 +649,7 @@ fn parse_buffered_data(break;}Ok(size) => {+ unapplied += size;let work_started = Instant::now();parser.parse(&buf[0..size], |action| {let mut flush = false;@@ -724,6 +729,13 @@ fn parse_buffered_data(let config = configuration();buf.resize(config.mux_output_parser_buffer_size, 0);delay = Duration::from_millis(config.mux_output_parser_coalesce_delay_ms);++ if actions.is_empty() {+ if let Some(control) = &control {+ control.pending_bytes.fetch_sub(unapplied, Ordering::SeqCst);+ }+ unapplied = 0;+ }}}}@@ -735,6 +747,9 @@ fn parse_buffered_data(if !actions.is_empty() {send_actions_to_mux(&pane, &dead, std::mem::take(&mut actions));}+ if let Some(control) = &control {+ control.pending_bytes.fetch_sub(unapplied, Ordering::SeqCst);+ }parse_watchdog::unregister(pane_id);}@@ -768,19 +783,152 @@ fn allocate_socketpair() -> anyhow::Result<(FileDescriptor, FileDescriptor)> {Ok((tx, rx))}+/// A pane's reader thread, from the outside. A takeover hands the pty to+/// another process, and while it does nothing here may read it; the+/// control lets the reader be parked and says when everything it read+/// has been applied to the terminal.+pub struct ReaderControl {+ /// A byte written here breaks the reader out of its poll.+ wake: parking_lot::Mutex<FileDescriptor>,+ paused: AtomicBool,+ /// Whether the reader is parked; `changed` is signalled by both sides.+ parked: std::sync::Mutex<bool>,+ changed: std::sync::Condvar,+ /// Bytes read from the pty and not yet applied to the terminal.+ pending_bytes: AtomicUsize,+}++impl ReaderControl {+ fn new(wake: FileDescriptor) -> Self {+ Self {+ wake: parking_lot::Mutex::new(wake),+ paused: AtomicBool::new(false),+ parked: std::sync::Mutex::new(false),+ changed: std::sync::Condvar::new(),+ pending_bytes: AtomicUsize::new(0),+ }+ }++ /// Park the reader and wait until what it read has been applied.+ /// Times out on a reader that never parks, or on a parser that never+ /// finishes: an output batch held for synchronized output, or a pane+ /// wedged for the test. Either way the reader runs again on return.+ fn pause(&self, timeout: Duration) -> anyhow::Result<()> {+ let deadline = Instant::now() + timeout;+ self.paused.store(true, Ordering::SeqCst);+ if let Err(err) = self.wake.lock().write_all(&[1]) {+ self.resume();+ return Err(err).context("waking the pane reader");+ }+ {+ let mut parked = self.parked.lock().unwrap();+ while !*parked {+ let left = deadline.saturating_duration_since(Instant::now());+ if left.is_zero() {+ drop(parked);+ self.resume();+ anyhow::bail!("the pane reader did not park within {timeout:?}");+ }+ parked = self.changed.wait_timeout(parked, left).unwrap().0;+ }+ }+ loop {+ let pending = self.pending_bytes.load(Ordering::SeqCst);+ if pending == 0 {+ return Ok(());+ }+ if Instant::now() >= deadline {+ self.resume();+ anyhow::bail!(+ "{pending} bytes read from the pty were still being applied after {timeout:?}"+ );+ }+ std::thread::sleep(Duration::from_millis(2));+ }+ }++ fn resume(&self) {+ self.paused.store(false, Ordering::SeqCst);+ let _parked = self.parked.lock().unwrap();+ self.changed.notify_all();+ }++ /// The reader's side: announce the park, wait for the resume.+ fn park(&self) {+ let mut parked = self.parked.lock().unwrap();+ *parked = true;+ self.changed.notify_all();+ while self.paused.load(Ordering::SeqCst) {+ parked = self.changed.wait(parked).unwrap();+ }+ *parked = false;+ self.changed.notify_all();+ }++ pub fn pending_bytes(&self) -> usize {+ self.pending_bytes.load(Ordering::SeqCst)+ }+}++lazy_static::lazy_static! {+ static ref PANE_READERS: parking_lot::Mutex<HashMap<PaneId, Arc<ReaderControl>>> =+ parking_lot::Mutex::new(HashMap::new());+}++/// A pane reader that is parked. Dropping it lets the reader run again;+/// `keep` does not, for the pty that now belongs to another process.+pub struct PausedReader {+ control: Arc<ReaderControl>,+ kept: bool,+}++impl PausedReader {+ /// The pty has been handed to another process: this reader must never+ /// run again. It ends with this process.+ pub fn keep(mut self) {+ self.kept = true;+ }+}++impl Drop for PausedReader {+ fn drop(&mut self) {+ if !self.kept {+ self.control.resume();+ }+ }+}++/// Park the reader of `pane_id` and wait until everything it read has been+/// applied to the terminal, so that the terminal is exactly what the pty+/// produced up to the park. Output the program writes meanwhile waits in+/// the kernel's pty buffer for whoever reads next. Panes without a pty+/// (or on a platform without poll) cannot be paused.+pub fn pause_pane_reader(pane_id: PaneId, timeout: Duration) -> anyhow::Result<PausedReader> {+ let control = PANE_READERS+ .lock()+ .get(&pane_id)+ .cloned()+ .ok_or_else(|| anyhow!("pane {pane_id} has no reader that can be paused"))?;+ control.pause(timeout)?;+ Ok(PausedReader {+ control,+ kept: false,+ })+}+/// This function is run in a separate thread; its purpose is to perform/// blocking reads from the pty (non-blocking reads are not portable to-/// all platforms and pty/tty types), parse the escape sequences and-/// relay the actions to the mux thread to apply them to the pane.+/// all platforms) and to feed the bytes to the parser thread over a+/// socketpair. With a pty file descriptor to poll, the reader can also be+/// parked; see [`pause_pane_reader`].fn read_from_pane_pty(pane: Weak<dyn Pane>,banner: Option<String>,mut reader: Box<dyn std::io::Read>,+ pty_fd: Option<i32>,) {let mut buf = vec![0; PTY_READ_BUFSIZE];- // This is used to signal that an error occurred either in this thread,- // or in the main mux thread. If `true`, this thread will terminate.let dead = Arc::new(AtomicBool::new(false));let (pane_id, exit_behavior) = match pane.upgrade() {@@ -803,10 +951,29 @@ fn read_from_pane_pty(}};+ // The wake pipe and the control exist only when the pty can be polled;+ // without them the loop below is the plain blocking read.+ let pausable = pty_fd.and_then(|fd| match filedescriptor::Pipe::new() {+ Ok(pipe) => Some((fd, pipe)),+ Err(err) => {+ log::warn!("pane {pane_id}: no wake pipe for the reader, it cannot be paused: {err:#}");+ None+ }+ });+ let (control, mut wake_read, poll_fd) = match pausable {+ Some((fd, pipe)) => {+ let control = Arc::new(ReaderControl::new(pipe.write));+ PANE_READERS.lock().insert(pane_id, Arc::clone(&control));+ (Some(control), Some(pipe.read), Some(fd))+ }+ None => (None, None, None),+ };+let heartbeat = parse_watchdog::register(pane_id);std::thread::spawn({let dead = Arc::clone(&dead);- move || parse_buffered_data(pane, pane_id, &dead, rx, heartbeat)+ let control = control.clone();+ move || parse_buffered_data(pane, pane_id, &dead, rx, heartbeat, control)});if let Some(banner) = banner {@@ -814,6 +981,38 @@ fn read_from_pane_pty(}while !dead.load(Ordering::Relaxed) {+ if let (Some(control), Some(wake_read), Some(fd)) = (&control, &mut wake_read, poll_fd) {+ let mut pfd = [+ pollfd {+ fd: fd as _,+ events: POLLIN,+ revents: 0,+ },+ pollfd {+ fd: wake_read.as_socket_descriptor(),+ events: POLLIN,+ revents: 0,+ },+ ];+ match poll(&mut pfd, None) {+ Ok(_) => {}+ Err(err) => {+ error!("read_pty poll failed: pane {} {:?}", pane_id, err);+ break;+ }+ }+ if pfd[1].revents != 0 {+ let mut drained = [0u8; 16];+ wake_read.read(&mut drained).ok();+ }+ if control.paused.load(Ordering::SeqCst) {+ control.park();+ continue;+ }+ if pfd[0].revents == 0 {+ continue;+ }+ }match reader.read(&mut buf) {Ok(size) if size == 0 => {log::trace!("read_pty EOF: pane_id {}", pane_id);@@ -826,7 +1025,15 @@ fn read_from_pane_pty(Ok(size) => {histogram!("read_from_pane_pty.bytes.rate").record(size as f64);log::trace!("read_pty pane {pane_id} read {size} bytes");+ // Counted before the parser can see the bytes, so the+ // count never dips below what is really pending.+ if let Some(control) = &control {+ control.pending_bytes.fetch_add(size, Ordering::SeqCst);+ }if let Err(err) = tx.write_all(&buf[..size]) {+ if let Some(control) = &control {+ control.pending_bytes.fetch_sub(size, Ordering::SeqCst);+ }error!("read_pty failed to write to parser: pane {} {:?}",pane_id, err@@ -837,10 +1044,12 @@ fn read_from_pane_pty(}}+ if control.is_some() {+ PANE_READERS.lock().remove(&pane_id);+ }+match exit_behavior.unwrap_or_else(|| configuration().exit_behavior) {ExitBehavior::Hold | ExitBehavior::CloseOnCleanExit => {- // We don't know if we can unilaterally close- // this pane right now, so don't!promise::spawn::spawn_into_main_thread(async move {let mux = Mux::get();log::trace!("checking for dead windows after EOF on pane {}", pane_id);@@ -919,6 +1128,17 @@ impl std::ops::Deref for MuxWindowBuilder {impl Mux {pub fn new(default_domain: Option<Arc<dyn Domain>>) -> Self {+ Self::new_with_runtime_server_id(default_domain, new_runtime_server_id())+ }++ /// A mux that answers to a runtime server id chosen by the caller: the+ /// one a server inherits from the predecessor it took over from, so+ /// that clients reconnecting to it find the same server rather than a+ /// replacement.+ pub fn new_with_runtime_server_id(+ default_domain: Option<Arc<dyn Domain>>,+ runtime_server_id: String,+ ) -> Self {let mut domains = HashMap::new();let mut domains_by_name = HashMap::new();if let Some(default_domain) = default_domain.as_ref() {@@ -937,7 +1157,7 @@ impl Mux {};Self {- runtime_server_id: new_runtime_server_id(),+ runtime_server_id,tabs: RwLock::new(HashMap::new()),panes: RwLock::new(HashMap::new()),windows: RwLock::new(HashMap::new()),@@ -2384,8 +2604,12 @@ impl Mux {let pane_id = pane.pane_id();if let Some(reader) = pane.reader()? {let banner = self.banner.read().clone();+ #[cfg(unix)]+ let pty_fd = pane.pty_raw_fd();+ #[cfg(not(unix))]+ let pty_fd = None;let pane = Arc::downgrade(pane);- thread::spawn(move || read_from_pane_pty(pane, banner, reader));+ thread::spawn(move || read_from_pane_pty(pane, banner, reader, pty_fd));}self.recompute_pane_count();self.notify(MuxNotification::PaneAdded(pane_id));@@ -2652,6 +2876,18 @@ impl Mux {}}+ /// Register a window built elsewhere, under its own id (one adopted+ /// from a predecessor server). The builder announces it like a new one.+ pub fn insert_window(&self, window: Window) -> MuxWindowBuilder {+ let window_id = window.window_id();+ self.windows.write().insert(window_id, window);+ MuxWindowBuilder {+ window_id,+ activity: Some(Activity::new()),+ notified: false,+ }+ }+pub fn add_tab_to_window(&self, tab: &Arc<Tab>, window_id: WindowId) -> anyhow::Result<()> {let tab_id = tab.tab_id();{diff --git a/mux/src/localpane.rs b/mux/src/localpane.rsindex 44f611e8..4a959ff7 100644--- a/mux/src/localpane.rs+++ b/mux/src/localpane.rs@@ -752,6 +752,11 @@ impl Pane for LocalPane {Ok(Some(self.pty.lock().try_clone_reader()?))}+ #[cfg(unix)]+ fn pty_raw_fd(&self) -> Option<std::os::unix::io::RawFd> {+ self.pty.lock().as_raw_fd()+ }+fn send_paste(&self, text: &str) -> Result<(), Error> {Mux::get().record_input_for_current_identity();if self.tmux_domain.lock().is_some() {@@ -1349,7 +1354,54 @@ fn split_child((rx, signaller, pid)}+/// What a pane hands to a successor server besides its terminal: see+/// `LocalPane::handoff_parts`.+#[cfg(unix)]+pub struct PaneHandoffParts {+ pub pid: u32,+ pub tty_name: Option<std::path::PathBuf>,+ /// The master pty, still owned here; the successor gets a duplicate.+ pub pty_fd: std::os::unix::io::RawFd,+ pub description: String,+}+impl LocalPane {+ /// The pieces a successor server needs to adopt this pane, or None+ /// for a pane that cannot travel: one over a channel rather than a+ /// pty (ssh, tmux), or one whose process has already exited.+ #[cfg(unix)]+ pub fn handoff_parts(&self) -> Option<PaneHandoffParts> {+ if self.tmux_domain.lock().is_some() {+ return None;+ }+ let pid = match &*self.process.lock() {+ ProcessState::Running { pid: Some(pid), .. } => *pid,+ _ => return None,+ };+ let pty = self.pty.lock();+ let pty_fd = pty.as_raw_fd()?;+ Some(PaneHandoffParts {+ pid,+ tty_name: pty.tty_name(),+ pty_fd,+ description: self.command_description.clone(),+ })+ }++ /// Forget the process without touching it: this pane was staged for+ /// a takeover that did not happen, and the process still belongs to+ /// the server that is keeping it. Dropping the pane afterwards sends+ /// nothing.+ pub fn release_process(&self) {+ *self.process.lock() = ProcessState::Dead;+ }++ /// Everything the terminal remembers. Take it with the reader paused+ /// (`crate::pause_pane_reader`), or it is a moment behind the pty.+ pub fn snapshot_terminal(&self) -> wezterm_term::TerminalSnapshot {+ self.terminal.lock().snapshot()+ }+pub fn new(pane_id: PaneId,mut terminal: Terminal,@@ -1703,18 +1755,22 @@ mod summary_tests {}}+ /// The waiter thread `LocalPane::new` starts hops to the main thread+ /// when the child exits; with no scheduler that is a panic that+ /// poisons promise's scheduler lock for every test after.+ fn ensure_scheduler() {+ static SCHEDULER: std::sync::Once = std::sync::Once::new();+ SCHEDULER.call_once(|| {+ promise::spawn::SimpleExecutor::new();+ });+ }+fn pane() -> (LocalPane,Arc<StdMutex<Vec<PtySize>>>,std::sync::mpsc::Sender<()>,) {- // The waiter thread `LocalPane::new` starts hops to the main- // thread when the child exits; with no scheduler that is a panic- // that poisons promise's scheduler lock for every test after.- static SCHEDULER: std::sync::Once = std::sync::Once::new();- SCHEDULER.call_once(|| {- promise::spawn::SimpleExecutor::new();- });+ ensure_scheduler();let (exit_tx, exit_rx) = std::sync::mpsc::channel();let sizes = Arc::new(StdMutex::new(vec![]));let terminal = Terminal::new(@@ -1912,4 +1968,93 @@ mod summary_tests {);drop(guard);}++ /// A pty whose output is a pipe the test writes into.+ #[cfg(unix)]+ struct PipePty {+ read: filedescriptor::FileDescriptor,+ }++ #[cfg(unix)]+ impl MasterPty for PipePty {+ fn resize(&self, _size: PtySize) -> anyhow::Result<()> {+ Ok(())+ }+ fn get_size(&self) -> anyhow::Result<PtySize> {+ Ok(PtySize::default())+ }+ fn try_clone_reader(&self) -> anyhow::Result<Box<dyn std::io::Read + Send>> {+ Ok(Box::new(self.read.try_clone()?))+ }+ fn take_writer(&self) -> anyhow::Result<Box<dyn Write + Send>> {+ anyhow::bail!("no writer")+ }+ fn process_group_leader(&self) -> Option<libc::pid_t> {+ None+ }+ fn as_raw_fd(&self) -> Option<std::os::unix::io::RawFd> {+ use std::os::unix::io::AsRawFd;+ Some(self.read.as_raw_fd())+ }+ fn tty_name(&self) -> Option<std::path::PathBuf> {+ None+ }+ }++ /// While a reader is paused, what the program writes stays in the pty;+ /// resuming applies it, and a kept pause never does.+ #[cfg(unix)]+ #[test]+ fn a_paused_reader_leaves_the_pty_output_where_it_is() {+ use std::os::unix::io::AsRawFd;+ ensure_scheduler();+ let pipe = filedescriptor::Pipe::new().unwrap();+ let mut program = pipe.write;+ let raw = pipe.read.as_raw_fd();+ let (_exit_tx, exit_rx) = std::sync::mpsc::channel();+ let terminal = Terminal::new(+ size(80, 24),+ Arc::new(config::TermConfig::new()),+ "ThinkTerm",+ "test",+ Box::new(Vec::new()),+ );+ let pane: Arc<dyn Pane> = Arc::new(LocalPane::new(+ 4242,+ terminal,+ Box::new(SleepingChild(exit_rx)),+ Box::new(PipePty { read: pipe.read }),+ Box::new(Vec::new()),+ 0,+ "test".into(),+ ));+ let reader = pane.reader().unwrap().unwrap();+ let weak = Arc::downgrade(&pane);+ std::thread::spawn(move || crate::read_from_pane_pty(weak, None, reader, Some(raw)));++ let title = |pane: &Arc<dyn Pane>| pane.summary_without_waiting().title;+ let wait_for = |pane: &Arc<dyn Pane>, want: &str| {+ let deadline = Instant::now() + Duration::from_secs(5);+ while title(pane) != want && Instant::now() < deadline {+ std::thread::sleep(Duration::from_millis(5));+ }+ assert_eq!(title(pane), want);+ };++ program.write_all(b"\x1b]0;first\x07").unwrap();+ wait_for(&pane, "first");++ let paused = crate::pause_pane_reader(4242, Duration::from_secs(2)).expect("pause");+ program.write_all(b"\x1b]0;second\x07").unwrap();+ std::thread::sleep(Duration::from_millis(150));+ assert_eq!(title(&pane), "first", "nothing is read while paused");+ drop(paused);+ wait_for(&pane, "second");++ let paused = crate::pause_pane_reader(4242, Duration::from_secs(2)).expect("pause again");+ program.write_all(b"\x1b]0;third\x07").unwrap();+ paused.keep();+ std::thread::sleep(Duration::from_millis(150));+ assert_eq!(title(&pane), "second", "a kept pause never resumes");+ }}diff --git a/mux/src/pane.rs b/mux/src/pane.rsindex e4263382..64d1ade7 100644--- a/mux/src/pane.rs+++ b/mux/src/pane.rs@@ -28,6 +28,18 @@ pub fn alloc_pane_id() -> PaneId {PANE_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed)}+/// Keep `alloc_pane_id` away from every id below `next`: a server that+/// adopts panes from its predecessor keeps their ids and must not hand+/// them out again.+pub fn reserve_pane_ids_below(next: PaneId) {+ PANE_ID.fetch_max(next, ::std::sync::atomic::Ordering::Relaxed);+}++/// The id the next pane would get; what a successor has to reserve.+pub fn next_pane_id() -> PaneId {+ PANE_ID.load(::std::sync::atomic::Ordering::Relaxed)+}+/// The cell geometry a frontend sizes this pane's PTY with.////// The split tree thinks in root-font cells and knows nothing of per-pane@@ -321,6 +333,13 @@ pub trait Pane: Downcast + Send + Sync {}fn send_paste(&self, text: &str) -> anyhow::Result<()>;fn reader(&self) -> anyhow::Result<Option<Box<dyn std::io::Read + Send>>>;+ /// The pty behind `reader`, when there is one: the reader thread waits+ /// for it with poll, which is what lets it be parked (see+ /// `crate::pause_pane_reader`).+ #[cfg(unix)]+ fn pty_raw_fd(&self) -> Option<std::os::unix::io::RawFd> {+ None+ }fn writer(&self) -> MappedMutexGuard<'_, dyn std::io::Write>;fn resize(&self, size: TerminalSize) -> anyhow::Result<()>;/// Called as a hint that the pane is being resized as part ofdiff --git a/mux/src/tab.rs b/mux/src/tab.rsindex 684213ad..c1161e79 100644--- a/mux/src/tab.rs+++ b/mux/src/tab.rs@@ -24,6 +24,24 @@ static PANE_STACK_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::Atpub fn alloc_pane_stack_id() -> PaneStackId {PANE_STACK_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed)}++/// Keep the allocators away from every id below `next`; see+/// `crate::pane::reserve_pane_ids_below`.+pub fn reserve_tab_ids_below(next: TabId) {+ TAB_ID.fetch_max(next, ::std::sync::atomic::Ordering::Relaxed);+}++pub fn reserve_pane_stack_ids_below(next: PaneStackId) {+ PANE_STACK_ID.fetch_max(next, ::std::sync::atomic::Ordering::Relaxed);+}++pub fn next_tab_id() -> TabId {+ TAB_ID.load(::std::sync::atomic::Ordering::Relaxed)+}++pub fn next_pane_stack_id() -> PaneStackId {+ PANE_STACK_ID.load(::std::sync::atomic::Ordering::Relaxed)+}pub use thinkterm_proto::TabId;#[derive(Default)]@@ -932,6 +950,18 @@ impl Tab {}}+ /// A tab under an id the caller chose: one adopted from a predecessor+ /// server. The id is reserved so no later tab is given it.+ pub fn new_with_id(size: &TerminalSize, tab_id: TabId) -> Self {+ reserve_tab_ids_below(tab_id + 1);+ let mut inner = TabInner::new(size);+ inner.id = tab_id;+ Self {+ inner: Mutex::new(inner),+ tab_id,+ }+ }+pub fn get_title(&self) -> String {self.inner.lock().title.clone()}diff --git a/mux/src/window.rs b/mux/src/window.rsindex b4aab4f1..4923ac75 100644--- a/mux/src/window.rs+++ b/mux/src/window.rs@@ -9,6 +9,17 @@ static WIN_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsipub use thinkterm_proto::WindowId;pub type WindowUiSurfaceId = String;+/// The id the next window would get; what a successor has to reserve.+pub fn next_window_id() -> WindowId {+ WIN_ID.load(::std::sync::atomic::Ordering::Relaxed)+}++/// Keep the allocator away from every id below `next`; see+/// `crate::pane::reserve_pane_ids_below`.+pub fn reserve_window_ids_below(next: WindowId) {+ WIN_ID.fetch_max(next, ::std::sync::atomic::Ordering::Relaxed);+}+pub struct Window {id: WindowId,tabs: Vec<Arc<Tab>>,@@ -44,6 +55,24 @@ impl Window {}}+ /// A window under an id the caller chose: one adopted from a+ /// predecessor server. The id is reserved so no later window is+ /// given it.+ pub fn new_with_id(id: WindowId, workspace: String, origin_domain: Option<DomainId>) -> Self {+ WIN_ID.fetch_max(id + 1, ::std::sync::atomic::Ordering::Relaxed);+ Self {+ id,+ tabs: vec![],+ ui_surfaces: BTreeSet::new(),+ active: 0,+ last_active: None,+ title: String::new(),+ workspace,+ initial_position: None,+ origin_domain,+ }+ }+pub fn origin_domain(&self) -> Option<DomainId> {self.origin_domain}