From fb416e75fd5ecb0b718df59565e8889da91c63e1 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 27 Sep 2025 10:55:04 -0700 Subject: [PATCH] feat(wm): implement move resizing and moving This commit implements moving and resizing by mouse as it works in komorebi for Windows. We're able to make this a bit nicer here because macOS emits separate events for resizing and movement, so now we have MoveStart/MoveEnd and ResizeStart/ResizeEnd. Resizing is a little janky because the system does not update the position of resized windows quickly enough, so if you do a quick drag and release the left mouse button, sometimes the accessibility attributes for the size and position of that window won't have been updated, and no resize will take place. --- docs/known-issues.md | 2 - komorebi/src/macos_api.rs | 12 +- komorebi/src/process_event.rs | 314 +++++++++++++++++++++++++++ komorebi/src/static_config.rs | 2 + komorebi/src/window_manager.rs | 170 +++++++++++++++ komorebi/src/window_manager_event.rs | 56 ++++- komorebi/src/workspace.rs | 21 ++ 7 files changed, 568 insertions(+), 9 deletions(-) diff --git a/docs/known-issues.md b/docs/known-issues.md index fc89afcc..da251eb0 100644 --- a/docs/known-issues.md +++ b/docs/known-issues.md @@ -1,7 +1,5 @@ * The flow for manually adding Accessibility and Screen Recording permissions sucks -* Mouse resizing is not implemented -* Swapping window containers via mouse dragging is not implemented * Fullscreen windows aren't supported (and probably won't be) and break the state (probably shouldn't) * Application hiding isn't supported (and probably won't be) and breaks the diff --git a/komorebi/src/macos_api.rs b/komorebi/src/macos_api.rs index 8f981eca..0278e111 100644 --- a/komorebi/src/macos_api.rs +++ b/komorebi/src/macos_api.rs @@ -32,6 +32,9 @@ use objc2_core_foundation::CFString; use objc2_core_foundation::CGPoint; use objc2_core_foundation::CGRect; use objc2_core_foundation::CGSize; +use objc2_core_graphics::CGEvent; +use objc2_core_graphics::CGEventSource; +use objc2_core_graphics::CGEventSourceStateID; use objc2_core_graphics::CGMainDisplayID; use objc2_foundation::NSNumber; use std::collections::HashMap; @@ -398,12 +401,17 @@ impl MacosApi { pub fn cursor_pos() -> CGPoint { unsafe { - let point = NSEvent::mouseLocation(); - CGPoint::new(point.x, point.y) + let source = CGEventSource::new(CGEventSourceStateID::HIDSystemState); + let event = CGEvent::new(source.as_deref()); + CGEvent::location(event.as_deref()) } } pub fn monitor_from_point(point: CGPoint) -> Option { CoreGraphicsApi::display_with_point(point) } + + pub fn left_mouse_button_is_pressed() -> bool { + (unsafe { NSEvent::pressedMouseButtons() } & 0x1 != 0) + } } diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index e86cca7d..cb6b0418 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -10,10 +10,13 @@ use crate::accessibility::error::AccessibilityApiError; use crate::accessibility::error::AccessibilityError; use crate::accessibility::notification_constants::AccessibilityNotification; use crate::app_kit_notification_constants::AppKitWorkspaceNotification; +use crate::core::Sizing; use crate::core::WindowContainerBehaviour; use crate::core::config_generation::MatchingRule; use crate::core::default_layout::DefaultLayout; use crate::core::layout::Layout; +use crate::core::operation_direction::OperationDirection; +use crate::core::rect::Rect; use crate::macos_api::MacosApi; use crate::notify_subscribers; use crate::state::State; @@ -594,6 +597,317 @@ impl WindowManager { } } } + WindowManagerEvent::MoveStart(_, _, window_id) => { + if self.pending_move_op.is_none() && self.pending_resize_op.is_none() { + let monitor_idx = self.focused_monitor_idx(); + let workspace_idx = self + .focused_monitor() + .ok_or_eyre("there is no monitor with this idx")? + .focused_workspace_idx(); + + let pending_move_op = Arc::make_mut(&mut self.pending_move_op); + *pending_move_op = Option::from((monitor_idx, workspace_idx, window_id)); + } + } + WindowManagerEvent::MoveEnd(_, _, window_id) => { + // We need this because if the event ends on a different monitor, + // that monitor will already have been focused and updated in the state + let pending = *self.pending_move_op; + // Always consume the pending move op whenever this event is handled + let pending_move_op = Arc::make_mut(&mut self.pending_move_op); + *pending_move_op = None; + + if let Some((origin_monitor_idx, origin_workspace_idx, wid)) = pending { + // If the window handles don't match then something went wrong and the pending move + // is not related to this current move, if so abort this operation. + if wid != window_id { + eyre::bail!( + "window handles for move operation don't match: {} != {}", + wid, + window_id + ); + } + let known_window_ids = self.known_window_ids.clone(); + + let target_monitor_idx = self + .monitor_idx_from_current_pos() + .ok_or_eyre("cannot get monitor idx from current position")?; + + let focused_monitor_idx = self.focused_monitor_idx(); + let focused_workspace_idx = self.focused_workspace_idx().unwrap_or_default(); + let window_management_behaviour = self + .window_management_behaviour(focused_monitor_idx, focused_workspace_idx); + + let workspace = self.focused_workspace_mut()?; + let focused_container_idx = workspace.focused_container_idx(); + + if let Some(container) = workspace.focused_container() + && let Some(window) = container.focused_window() + { + // TODO: not sure about this clone + let window = window.clone(); + let new_position = Rect::from(MacosApi::window_rect(&window.element)?); + let old_position = *workspace + .latest_layout + .get(focused_container_idx) + // If the move was to another monitor with an empty workspace, the + // workspace here will refer to that empty workspace, which won't + // have any latest layout set. We fall back to a Default for Rect + // which allows us to make a reasonable guess that the drag has taken + // place across a monitor boundary to an empty workspace + .unwrap_or(&Rect::default()); + + // This will be true if we have moved to another monitor + let mut moved_across_monitors = false; + + if let Some((m_idx, _)) = known_window_ids.get(&window_id) + && *m_idx != target_monitor_idx + { + moved_across_monitors = true; + } + + // If we didn't move to another monitor with an empty workspace, it is + // still possible that we moved to another monitor with a populated workspace + if !moved_across_monitors { + // So we'll check if the origin monitor index and the target monitor index + // are different, if they are, we can set the override + moved_across_monitors = origin_monitor_idx != target_monitor_idx; + + if moved_across_monitors { + // Want to make sure that we exclude unmanaged windows from cross-monitor + // moves with a mouse, otherwise the currently focused idx container will + // be moved when we just want to drag an unmanaged window + let origin_workspace = self + .monitors() + .get(origin_monitor_idx) + .ok_or_eyre("cannot get monitor idx")? + .workspaces() + .get(origin_workspace_idx) + .ok_or_eyre("cannot get workspace idx")?; + + let managed_window = origin_workspace.contains_window(window_id); + + if !managed_window { + moved_across_monitors = false; + } + } + } + + let workspace = self.focused_workspace_mut()?; + if (workspace.tile && workspace.contains_managed_window(window_id)) + || moved_across_monitors + { + let resize = Rect { + left: new_position.left - old_position.left, + top: new_position.top - old_position.top, + right: new_position.right - old_position.right, + bottom: new_position.bottom - old_position.bottom, + }; + + // If we have moved across the monitors, use that override, otherwise determine + // if a move has taken place by ruling out a resize + let right_bottom_constant = 0; + + let is_move = moved_across_monitors + || resize.right.abs() == right_bottom_constant + && resize.bottom.abs() == right_bottom_constant; + + if is_move { + tracing::info!("moving with mouse"); + + if moved_across_monitors { + if let Some(( + origin_monitor_idx, + origin_workspace_idx, + w_hwnd, + )) = pending + { + let target_workspace_idx = self + .monitors() + .get(target_monitor_idx) + .ok_or_eyre("there is no monitor at this idx")? + .focused_workspace_idx(); + + let target_container_idx = self + .monitors() + .get(target_monitor_idx) + .ok_or_eyre("there is no monitor at this idx")? + .focused_workspace() + .ok_or_eyre( + "there is no focused workspace for this monitor", + )? + .container_idx_from_current_point() + // Default to 0 in the case of an empty workspace + .unwrap_or(0); + + let origin = + (origin_monitor_idx, origin_workspace_idx, w_hwnd); + let target = ( + target_monitor_idx, + target_workspace_idx, + target_container_idx, + ); + self.transfer_window(origin, target)?; + + // We want to make sure both the origin and target monitors are updated, + // so that we don't have ghost tiles until we force an interaction on + // the origin monitor's focused workspace + self.focus_monitor(origin_monitor_idx)?; + let origin_monitor = self + .monitors_mut() + .get_mut(origin_monitor_idx) + .ok_or_eyre("there is no monitor at this idx")?; + origin_monitor.focus_workspace(origin_workspace_idx)?; + self.update_focused_workspace(false, false)?; + + self.focus_monitor(target_monitor_idx)?; + let target_monitor = self + .monitors_mut() + .get_mut(target_monitor_idx) + .ok_or_eyre("there is no monitor at this idx")?; + target_monitor.focus_workspace(target_workspace_idx)?; + self.update_focused_workspace(false, false)?; + + // Make sure to give focus to the moved window again + window.focus(self.mouse_follows_focus)?; + } + } else if window_management_behaviour.float_override { + // TODO: unsure of this clone + workspace.floating_windows_mut().push_back(window); + self.update_focused_workspace(false, false)?; + } else { + match window_management_behaviour.current_behaviour { + WindowContainerBehaviour::Create => { + match workspace.container_idx_from_current_point() { + Some(target_idx) => { + workspace.swap_containers( + focused_container_idx, + target_idx, + ); + self.update_focused_workspace(false, false)?; + } + None => { + self.update_focused_workspace( + self.mouse_follows_focus, + false, + )?; + } + } + } + WindowContainerBehaviour::Append => { + match workspace.container_idx_from_current_point() { + Some(target_idx) => { + workspace + .move_window_to_container(target_idx)?; + self.update_focused_workspace(false, false)?; + } + None => { + self.update_focused_workspace( + self.mouse_follows_focus, + false, + )?; + } + } + } + } + } + } + } + } + } + } + WindowManagerEvent::ResizeStart(_, _, window_id) => { + let workspace = self.focused_workspace_mut()?; + if let Some(container) = workspace.focused_container() + && let Some(window) = container.focused_window() + { + let window = window.clone(); + let new_position = Rect::from(MacosApi::window_rect(&window.element)?); + + let pending_resize_op = Arc::make_mut(&mut self.pending_resize_op); + *pending_resize_op = Option::from((window_id, Some(new_position))); + } + } + WindowManagerEvent::ResizeEnd(_, _, window_id) => { + let pending = *self.pending_resize_op; + // Always consume the pending resize op whenever this event is handled + let pending_resize_op = Arc::make_mut(&mut self.pending_resize_op); + *pending_resize_op = None; + + if let Some((wid, Some(new_position))) = pending { + // If the window handles don't match then something went wrong and the pending resize + // is not related to this current resize, if so abort this operation. + if wid != window_id { + eyre::bail!( + "window handles for resize operation don't match: {} != {}", + wid, + window_id + ); + } + + let workspace = self.focused_workspace_mut()?; + let focused_container_idx = workspace.focused_container_idx(); + + if let Some(container) = workspace.focused_container() + && let Some(window) = container.focused_window() + { + let window = window.clone(); + + let old_position = *workspace + .latest_layout + .get(focused_container_idx) + .unwrap_or(&Rect::default()); + + let workspace = self.focused_workspace_mut()?; + if workspace.tile && workspace.contains_managed_window(window.id) { + let resize = Rect { + left: new_position.left - old_position.left, + top: new_position.top - old_position.top, + right: new_position.right - old_position.right, + bottom: new_position.bottom - old_position.bottom, + }; + + tracing::info!("resizing with mouse"); + let mut ops = vec![]; + + macro_rules! resize_op { + ($coordinate:expr, $comparator:tt, $direction:expr) => {{ + let adjusted = $coordinate * 2; + let sizing = if adjusted $comparator 0 { + Sizing::Decrease + } else { + Sizing::Increase + }; + + ($direction, sizing, adjusted.abs()) + }}; + } + + if resize.left != 0 { + ops.push(resize_op!(resize.left, >, OperationDirection::Left)); + } + + if resize.top != 0 { + ops.push(resize_op!(resize.top, >, OperationDirection::Up)); + } + + if resize.right != 0 && (resize.left == 0) { + ops.push(resize_op!(resize.right, <, OperationDirection::Right)); + } + + if resize.bottom != 0 && (resize.top == 0) { + ops.push(resize_op!(resize.bottom, <, OperationDirection::Down)); + } + + for (edge, sizing, delta) in ops { + self.resize_window(edge, sizing, delta, true)?; + } + + self.update_focused_workspace(false, false)?; + } + } + } + } } self.update_known_window_ids(); diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 268b17a5..b4eff49f 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -1159,6 +1159,8 @@ impl StaticConfig { hotwatch: Hotwatch::new()?, run_loop: CoreFoundationRunLoop(run_loop.clone()), minimized_windows: HashMap::new(), + pending_move_op: Arc::new(None), + pending_resize_op: Arc::new(None), already_moved_window_handles: Default::default(), known_window_ids: HashMap::new(), }; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 9d520e40..22ed3bdc 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -74,6 +74,8 @@ pub struct WindowManager { pub work_area_offset: Option, pub incoming_events: Receiver, pub minimized_windows: HashMap, + pub pending_move_op: Arc>, + pub pending_resize_op: Arc)>>, pub already_moved_window_handles: Arc>>, /// Maps each known window id to the (monitor, workspace) index pair managing it pub known_window_ids: HashMap, @@ -154,6 +156,8 @@ impl WindowManager { work_area_offset: None, incoming_events: incoming, minimized_windows: HashMap::new(), + pending_move_op: Arc::new(None), + pending_resize_op: Arc::new(None), already_moved_window_handles: Default::default(), known_window_ids: Default::default(), }) @@ -2959,4 +2963,170 @@ impl WindowManager { Ok(()) } + + #[tracing::instrument(skip(self))] + pub fn transfer_window( + &mut self, + origin: (usize, usize, u32), + target: (usize, usize, usize), + ) -> eyre::Result<()> { + let (origin_monitor_idx, origin_workspace_idx, window_id) = origin; + let (target_monitor_idx, target_workspace_idx, target_container_idx) = target; + + let origin_workspace = self + .monitors_mut() + .get_mut(origin_monitor_idx) + .ok_or_eyre("cannot get monitor idx")? + .workspaces_mut() + .get_mut(origin_workspace_idx) + .ok_or_eyre("cannot get workspace idx")?; + + let origin_container_idx = origin_workspace + .container_for_window(window_id) + .and_then(|c| origin_workspace.containers().iter().position(|cc| cc == c)); + + if let Some(origin_container_idx) = origin_container_idx { + // Moving normal container window + self.transfer_container( + ( + origin_monitor_idx, + origin_workspace_idx, + origin_container_idx, + ), + ( + target_monitor_idx, + target_workspace_idx, + target_container_idx, + ), + )?; + } else if let Some(idx) = origin_workspace + .floating_windows() + .iter() + .position(|w| w.id == window_id) + { + // Moving floating window + // There is no need to physically move the floating window between areas with + // `move_to_area` because the user already did that, so we only need to transfer the + // window to the target `floating_windows` + if let Some(floating_window) = origin_workspace.floating_windows_mut().remove(idx) { + let target_workspace = self + .monitors_mut() + .get_mut(target_monitor_idx) + .ok_or_eyre("there is no monitor at this idx")? + .focused_workspace_mut() + .ok_or_eyre("there is no focused workspace for this monitor")?; + + target_workspace + .floating_windows_mut() + .push_back(floating_window); + } + } else if origin_workspace + .monocle_container + .as_ref() + .and_then(|monocle| monocle.focused_window().map(|w| w.id == window_id)) + .unwrap_or_default() + { + // Moving monocle container + if let Some(monocle_idx) = origin_workspace.monocle_container_restore_idx { + let origin_workspace = self + .monitors_mut() + .get_mut(origin_monitor_idx) + .ok_or_eyre("there is no monitor at this idx")? + .workspaces_mut() + .get_mut(origin_workspace_idx) + .ok_or_eyre("there is no workspace for this monitor")?; + + for container in origin_workspace.containers_mut() { + container.restore()?; + } + + origin_workspace.reintegrate_monocle_container()?; + + self.transfer_container( + (origin_monitor_idx, origin_workspace_idx, monocle_idx), + ( + target_monitor_idx, + target_workspace_idx, + target_container_idx, + ), + )?; + // TODO: don't think this is needed on macOS + // After we restore the origin workspace, some windows that were cloacked + // by the monocle might now be uncloacked which would trigger a workspace + // reconciliation since the focused monitor would be different from origin. + // That workspace reconciliation would focus the window on the origin monitor. + // So we need to ignore the uncloak events produced by the origin workspace + // restore to avoid that issue. + // self.uncloack_to_ignore = uncloack_amount; + } + // TODO: this probably won't be used on macOS + } else if origin_workspace + .maximized_window + .as_ref() + .map(|max| max.id == window_id) + .unwrap_or_default() + { + // Moving maximized_window + // TODO: not sure if we'll support maximized windows on macOS + // if let Some(maximized_idx) = origin_workspace.maximized_window_restore_idx { + // self.focus_monitor(origin_monitor_idx)?; + // let origin_monitor = self + // .focused_monitor_mut() + // .ok_or_eyre("there is no origin monitor")?; + // origin_monitor.focus_workspace(origin_workspace_idx)?; + // self.unmaximize_window()?; + // self.focus_monitor(target_monitor_idx)?; + // let target_monitor = self + // .focused_monitor_mut() + // .ok_or_eyre("there is no target monitor")?; + // target_monitor.focus_workspace(target_workspace_idx)?; + // + // self.transfer_container( + // (origin_monitor_idx, origin_workspace_idx, maximized_idx), + // ( + // target_monitor_idx, + // target_workspace_idx, + // target_container_idx, + // ), + // )?; + // } + } + Ok(()) + } + + #[tracing::instrument(skip(self))] + pub fn transfer_container( + &mut self, + origin: (usize, usize, usize), + target: (usize, usize, usize), + ) -> eyre::Result<()> { + let (origin_monitor_idx, origin_workspace_idx, origin_container_idx) = origin; + let (target_monitor_idx, target_workspace_idx, target_container_idx) = target; + + let origin_container = self + .monitors_mut() + .get_mut(origin_monitor_idx) + .ok_or_eyre("there is no monitor at this index")? + .workspaces_mut() + .get_mut(origin_workspace_idx) + .ok_or_eyre("there is no workspace at this index")? + .remove_container(origin_container_idx) + .ok_or_eyre("there is no container at this index")?; + + let target_workspace = self + .monitors_mut() + .get_mut(target_monitor_idx) + .ok_or_eyre("there is no monitor at this index")? + .workspaces_mut() + .get_mut(target_workspace_idx) + .ok_or_eyre("there is no workspace at this index")?; + + target_workspace + .containers_mut() + .insert(target_container_idx, origin_container); + + target_workspace.focus_container(target_container_idx); + + Ok(()) + } } diff --git a/komorebi/src/window_manager_event.rs b/komorebi/src/window_manager_event.rs index f8948dad..eb00cbfa 100644 --- a/komorebi/src/window_manager_event.rs +++ b/komorebi/src/window_manager_event.rs @@ -2,6 +2,7 @@ use crate::accessibility::notification_constants::AccessibilityNotification; use crate::app_kit_notification_constants::AppKitWorkspaceNotification; +use crate::macos_api::MacosApi; use serde::Deserialize; use serde::Serialize; use strum::Display; @@ -37,6 +38,10 @@ pub enum WindowManagerEvent { Restore(SystemNotification, i32, u32), Manage(SystemNotification, i32, u32), Unmanage(SystemNotification, i32, u32), + MoveStart(SystemNotification, i32, u32), + MoveEnd(SystemNotification, i32, u32), + ResizeStart(SystemNotification, i32, u32), + ResizeEnd(SystemNotification, i32, u32), } impl WindowManagerEvent { @@ -87,11 +92,40 @@ impl WindowManagerEvent { .map(|window_id| WindowManagerEvent::Manage(notification, process_id, window_id)), SystemNotification::Manual(ManualNotification::Unmanage) => window_id .map(|window_id| WindowManagerEvent::Unmanage(notification, process_id, window_id)), - // kAXWindowMovedNotification => {} - // kAXWindowResizedNotification => {} - // kAXTitleChangedNotification => {} - // kAXApplicationDeactivatedNotification => {} - _ => None, + SystemNotification::Accessibility(AccessibilityNotification::AXWindowMoved) => { + if MacosApi::left_mouse_button_is_pressed() { + window_id.map(|window_id| { + WindowManagerEvent::MoveStart(notification, process_id, window_id) + }) + } else { + window_id.map(|window_id| { + WindowManagerEvent::MoveEnd(notification, process_id, window_id) + }) + } + } + SystemNotification::Accessibility(AccessibilityNotification::AXWindowResized) => { + if MacosApi::left_mouse_button_is_pressed() { + window_id.map(|window_id| { + WindowManagerEvent::ResizeStart(notification, process_id, window_id) + }) + } else { + window_id.map(|window_id| { + WindowManagerEvent::ResizeEnd(notification, process_id, window_id) + }) + } + } + notification => { + let notification_string = match notification { + SystemNotification::Accessibility(n) => n.to_string(), + SystemNotification::AppKitWorkspace(n) => n.to_string(), + SystemNotification::Manual(n) => n.to_string(), + }; + + tracing::trace!( + "ignoring system notification: {notification_string} (pid: {process_id}, window id: {window_id:?})" + ); + None + } } } @@ -103,6 +137,10 @@ impl WindowManagerEvent { | WindowManagerEvent::Minimize(_, process_id, _) | WindowManagerEvent::Manage(_, process_id, _) | WindowManagerEvent::Unmanage(_, process_id, _) + | WindowManagerEvent::MoveStart(_, process_id, _) + | WindowManagerEvent::MoveEnd(_, process_id, _) + | WindowManagerEvent::ResizeStart(_, process_id, _) + | WindowManagerEvent::ResizeEnd(_, process_id, _) | WindowManagerEvent::Restore(_, process_id, _) => *process_id, } } @@ -114,6 +152,10 @@ impl WindowManagerEvent { | WindowManagerEvent::Destroy(n, _) | WindowManagerEvent::Minimize(n, _, _) | WindowManagerEvent::Manage(n, _, _) + | WindowManagerEvent::MoveStart(n, _, _) + | WindowManagerEvent::MoveEnd(n, _, _) + | WindowManagerEvent::ResizeStart(n, _, _) + | WindowManagerEvent::ResizeEnd(n, _, _) | WindowManagerEvent::Unmanage(n, _, _) | WindowManagerEvent::Restore(n, _, _) => match n { SystemNotification::Accessibility(a) => a.to_string(), @@ -130,6 +172,10 @@ impl WindowManagerEvent { WindowManagerEvent::Minimize(_, _, window_id) | WindowManagerEvent::Manage(_, _, window_id) | WindowManagerEvent::Unmanage(_, _, window_id) + | WindowManagerEvent::MoveStart(_, _, window_id) + | WindowManagerEvent::MoveEnd(_, _, window_id) + | WindowManagerEvent::ResizeStart(_, _, window_id) + | WindowManagerEvent::ResizeEnd(_, _, window_id) | WindowManagerEvent::Restore(_, _, window_id) => Some(*window_id), } } diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index fc709cb3..49d8298b 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -1128,6 +1128,27 @@ impl Workspace { Ok(()) } + + pub fn container_idx_from_current_point(&self) -> Option { + let mut idx = None; + + let point = MacosApi::cursor_pos(); + + for (i, _container) in self.containers().iter().enumerate() { + if let Some(rect) = self.latest_layout.get(i) + && rect.contains_point((point.x as i32, point.y as i32)) + { + idx = Option::from(i); + } + } + + idx + } + + pub fn container_for_window(&self, window_id: u32) -> Option<&Container> { + self.containers() + .get(self.container_idx_for_window(window_id)?) + } } impl Workspace {