From 283e5438fc8d4a98d7d9c16fe4fe3d357cbcced1 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 13:39:57 -0700 Subject: [PATCH] refactor(mac): the daemon's Container is komorebi_core::Container Step 11(iii), the Container layer. BEHAVIOUR (type-checked and unit-test oracle only; macOS cannot run here). pub type Container = komorebi_core::Container, with ContainerWindow implemented for the macOS Window (id is the CGWindowID, exe_name its exe; hide_window and restore_window use the default corner and log a failure, because the daemon does not hide through them). The container's own struct, accessors, preselect, idx_from_exe, contains_window, idx_for_window, remove_window_by_idx, remove_focused_window and focus_window are now the shared ones. The four functions that carry the monitor's WindowHidingPosition (and for hide the display bounds), return a Result and skip the work under cfg!(test) stay macOS's own, as ContainerExt, under names the shared type does not use: add_window_at, load_focused_window_at, hide_on and restore_focused_window (an inherent method of the shared type would shadow an extension method of the same name); about 35 call sites follow. The shared Container reads a missing 'locked' as false (macOS used to require it). komorebi-core is a dependency of the macOS daemon (and its schemars feature). State JSON: two new tests pin the shape ({id, locked, windows: {elements, focused}}) and the missing-locked read; the existing round-trip test is kept. They can only run on a Mac. Verified: fake-CC type-check (tools/fast-check) PASS on all targets; Windows clippy, KDE check and tests unaffected PASS. Not verified: any run. Verified on the Mini: not yet. Gate: the Mini's cargo test; then the hand check added to docs/dev/macos-handcheck.md (stacks, workspaces, state JSON, per-monitor hiding corner). --- Cargo.lock | 1 + docs/dev/macos-handcheck.md | 1 + komorebi-for-mac/komorebi/Cargo.toml | 3 +- komorebi-for-mac/komorebi/src/container.rs | 220 +++++++++--------- komorebi-for-mac/komorebi/src/monitor.rs | 5 +- .../komorebi/src/process_event.rs | 3 +- komorebi-for-mac/komorebi/src/scrolling.rs | 13 +- .../komorebi/src/window_manager.rs | 21 +- komorebi-for-mac/komorebi/src/workspace.rs | 39 ++-- 9 files changed, 162 insertions(+), 144 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf996037..3b0094ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3684,6 +3684,7 @@ dependencies = [ "komorebi-backend", "komorebi-collections", "komorebi-config", + "komorebi-core", "komorebi-layouts", "komorebi-protocol", "komorebi-settings", diff --git a/docs/dev/macos-handcheck.md b/docs/dev/macos-handcheck.md index d6f939cb..a85c1f0e 100644 --- a/docs/dev/macos-handcheck.md +++ b/docs/dev/macos-handcheck.md @@ -24,6 +24,7 @@ The real-Mac runs so far (Mac Mini, rustc and clippy 1.93, tip a35573d8) are **c | `oywqqkuy` f0b1a448 `register every Window in ax_registry and forget the dead` | `Window::new` registers the window in the id registry (`ax_registry`); entries are removed in `Window::drop` of a dead window, in `reap_window`, and (`forget_pid`) when an application terminates. No AX call is added; the table holds retained AX references and observers. | Open and close 50 windows (Finder, Terminal, Safari) and quit several apps, then check the daemon's memory in Activity Monitor does not climb and nothing behaves differently (focus, tiling, borders). If a quit app's windows were not forgotten the symptom is memory growth only. Run with `RUST_LOG=debug` and check no new errors at app quit. | | `oqnvyqvw` e0687167 `keep ax_registry in step when a native tab changes a window's id` | The two places that swap a window's id and element in place for native tabs also update the registry (`sync`). | A native-tabbed app (Terminal, Finder, Safari tabs): switch tabs, close the first tab, open a new tab, focus the window with `komorebic focus ...`, move and resize it. Must behave as on the baseline (no window lost, no stuck border). | | Bar: `nottqpms` 086833af, `zvuyspku` b8de056b, `uxzpkmnk` 7cd85bd4, `yopuwouu` 6da27dda (bar-core, platform hooks) | macOS now builds `sysinfo` 0.39 and `starship-battery` 0.11 (the Windows versions); cpu, battery, memory, date, update widgets are the shared code. | Bar renders; CPU %, memory, battery % and charging state show sane values; date and the calendar icon; clicking CPU, battery, network, update (see bug list D below: these click handlers are broken on macOS and stay broken). | +| 11(iii) Container: `refactor(mac): the daemon's Container is komorebi_core::Container` (see `jj log -r wip-u-kfm2`) | `Container` is the shared generic type over the macOS `Window` (its id, windows, focus, `remove_*`, `idx_*` functions are the shared ones). The four functions that need the monitor's hiding corner and can fail (`add_window`, `load_focused_window`, `hide`, `restore`) stay macOS's, renamed `add_window_at`, `load_focused_window_at`, `hide_on`, `restore_focused_window` (`ContainerExt`); `Window::hide/restore/minimize/unminimize` take `&self`. State JSON must not change (pinned by two tests in container.rs). | Run `cargo test` (the container, workspace and scrolling tests use these). Then by hand: stack windows (`komorebic stack`), unstack, cycle the stack (hidden members go to the monitor's corner, the front one is restored); switch workspaces and come back (restore of the front window of each stack); `komorebic state | jq '.monitors.elements[0].workspaces.elements[0].containers.elements[0]'` still has `id`, `locked`, `windows.{elements,focused}` and nothing else. Set `window_hiding_position` per monitor in the config and check each monitor hides into its own corner. | Revisions in section B change no behaviour on purpose (rename, move, route); they still need the sections C walk-through, because a mechanical mistake would show there. diff --git a/komorebi-for-mac/komorebi/Cargo.toml b/komorebi-for-mac/komorebi/Cargo.toml index 276a1f21..0e984dc8 100644 --- a/komorebi-for-mac/komorebi/Cargo.toml +++ b/komorebi-for-mac/komorebi/Cargo.toml @@ -8,6 +8,7 @@ edition = "2024" komorebi-themes = { path = "../../komorebi-themes" } komorebi-backend = { path = "../../crates/komorebi-backend" } komorebi-collections = { path = "../../crates/komorebi-collections" } +komorebi-core = { path = "../../crates/komorebi-core" } komorebi-layouts = { path = "../../komorebi-layouts", features = ["darwin", "schemars"] } komorebi-config = { path = "../../crates/komorebi-config", default-features = false, features = ["schemars"] } komorebi-settings = { path = "../../crates/komorebi-settings" } @@ -133,7 +134,7 @@ uuid = { version = "1", features = ["v4"] } [features] default = ["schemars"] deadlock_detection = ["parking_lot/deadlock_detection"] -schemars = ["dep:schemars", "komorebi-collections/schemars"] +schemars = ["dep:schemars", "komorebi-collections/schemars", "komorebi-core/schemars"] [lib] name = "komorebi" diff --git a/komorebi-for-mac/komorebi/src/container.rs b/komorebi-for-mac/komorebi/src/container.rs index b6ecd950..44ed4a69 100644 --- a/komorebi-for-mac/komorebi/src/container.rs +++ b/komorebi-for-mac/komorebi/src/container.rs @@ -1,96 +1,93 @@ +//! [`Container`], the windows that share one tile of a workspace's layout. +//! +//! The container is [`komorebi_core::Container`], shared with the other komorebi daemons, over the +//! macOS [`Window`]. What it cannot share is how a window is hidden: macOS needs the monitor's +//! `WindowHidingPosition` (and for a whole container the bounds of its display) with every hide, +//! and a hide can fail. Those four operations are [`ContainerExt`], under names the shared +//! container does not use (`add_window_at`, `load_focused_window_at`, `hide_on`, +//! `restore_focused_window`), because an inherent method of the shared type would hide an +//! extension method of the same name. + use crate::accessibility::error::AccessibilityError; use crate::core::WindowHidingPosition; -use crate::lockable_sequence::Lockable; -use crate::ring::Ring; use crate::window::Window; use color_eyre::eyre; -use nanoid::nanoid; +use komorebi_core::ContainerWindow; use objc2_core_foundation::CGRect; -use serde::Deserialize; -use serde::Serialize; -impl_ring_elements!(Container, Window); +/// The windows that share one tile of a workspace's layout +pub type Container = komorebi_core::Container; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub struct Container { - pub id: String, - pub locked: bool, - pub windows: Ring, -} +impl ContainerWindow for Window { + type Id = u32; -impl Default for Container { - fn default() -> Self { - Self { - id: nanoid!(), - locked: false, - windows: Default::default(), + fn id(&self) -> u32 { + self.id + } + + fn exe_name(&self) -> Option { + self.exe() + } + + /// Hides the window in the default corner. The macOS daemon does not hide through this: it + /// uses [`ContainerExt`], which carries the monitor's corner and display, and logs a failure + /// instead of ignoring it. This is the shared model's one-argument form. + fn hide_window(&self) { + if let Err(error) = self.hide(WindowHidingPosition::default()) { + tracing::warn!("failed to hide window {}: {error}", self.id); } } + + fn restore_window(&self) { + if let Err(error) = self.restore() { + tracing::warn!("failed to restore window {}: {error}", self.id); + } + } + + fn hide_stacked(&self) { + self.hide_window(); + } + + fn restore_stacked(&self) { + self.restore_window(); + } } -impl Lockable for Container { - fn locked(&self) -> bool { - self.locked - } +/// What a macOS container does that the shared one cannot: hide and restore its windows with the +/// monitor's hiding position, and say when that failed. +pub trait ContainerExt { + /// Puts a window at the back of the container and gives it the front, hiding every other + /// window of the container at `hiding_position` + fn add_window_at( + &mut self, + window: &Window, + hiding_position: WindowHidingPosition, + ) -> eyre::Result<()>; - fn set_locked(&mut self, locked: bool) -> &mut Self { - self.locked = locked; - self - } + /// Hides the unfocused windows of the container and restores the focused one. This function + /// is used to make sure we update the window that should be shown on a stack. If the container + /// isn't a stack this function won't change anything. + fn load_focused_window_at( + &mut self, + hiding_position: WindowHidingPosition, + ) -> Result<(), AccessibilityError>; + + /// Hide the windows of the container, other than `omit`, on `screen`, the bounds of the display + /// of the monitor that has the container, or on whichever display they are found on if that is + /// not given + fn hide_on( + &mut self, + hiding_position: WindowHidingPosition, + omit: Option, + screen: Option, + ) -> eyre::Result<()>; + + /// Restores the window in front, which is the one that is shown when the container is a stack + fn restore_focused_window(&mut self) -> eyre::Result<()>; } -impl Container { - pub fn preselect() -> Self { - Self { - id: "PRESELECT".to_string(), - locked: false, - windows: Default::default(), - } - } - - pub fn is_preselect(&self) -> bool { - self.id == "PRESELECT" - } - - pub fn idx_from_exe(&self, exe: &str) -> Option { - for (idx, window) in self.windows().iter().enumerate() { - if let Some(window_exe) = window.exe() - && exe == window_exe - { - return Option::from(idx); - } - } - - None - } - - pub fn contains_window(&self, window_id: u32) -> bool { - for window in self.windows() { - if window.id == window_id { - return true; - } - } - - false - } - - pub fn idx_for_window(&self, window_id: u32) -> Option { - for (i, window) in self.windows().iter().enumerate() { - if window.id == window_id { - return Option::from(i); - } - } - - None - } - - pub fn remove_focused_window(&mut self) -> Option { - let focused_idx = self.focused_window_idx(); - self.remove_window_by_idx(focused_idx) - } - - pub fn add_window( +impl ContainerExt for Container { + fn add_window_at( &mut self, window: &Window, hiding_position: WindowHidingPosition, @@ -113,16 +110,7 @@ impl Container { Ok(()) } - #[tracing::instrument(skip(self))] - pub fn focus_window(&mut self, idx: usize) { - tracing::info!("focusing window"); - self.windows.focus(idx); - } - - /// Hides the unfocused windows of the container and restores the focused one. This function - /// is used to make sure we update the window that should be shown on a stack. If the container - /// isn't a stack this function won't change anything. - pub fn load_focused_window( + fn load_focused_window_at( &mut self, hiding_position: WindowHidingPosition, ) -> Result<(), AccessibilityError> { @@ -145,16 +133,7 @@ impl Container { Ok(()) } - pub fn remove_window_by_idx(&mut self, idx: usize) -> Option { - let window = self.windows_mut().remove(idx); - self.focus_window(idx.saturating_sub(1)); - window - } - - /// Hide the windows of the container, other than `omit`, on `screen`, the bounds of the display - /// of the monitor that has the container, or on whichever display they are found on if that is - /// not given - pub fn hide( + fn hide_on( &mut self, hiding_position: WindowHidingPosition, omit: Option, @@ -179,7 +158,7 @@ impl Container { Ok(()) } - pub fn restore(&mut self) -> eyre::Result<()> { + fn restore_focused_window(&mut self) -> eyre::Result<()> { if let Some(window) = self.focused_window_mut() { window.restore()?; } @@ -191,6 +170,7 @@ impl Container { #[cfg(test)] mod tests { use super::*; + use komorebi_collections::Lockable; use serde_json; #[test] @@ -199,7 +179,7 @@ mod tests { for i in 0..3 { container - .add_window(&Window::from(i), WindowHidingPosition::BottomLeft) + .add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft) .unwrap(); } @@ -218,7 +198,7 @@ mod tests { for i in 0..3 { container - .add_window(&Window::from(i), WindowHidingPosition::BottomLeft) + .add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft) .unwrap(); } @@ -238,7 +218,7 @@ mod tests { for i in 0..3 { container - .add_window(&Window::from(i), WindowHidingPosition::BottomLeft) + .add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft) .unwrap(); } @@ -260,7 +240,7 @@ mod tests { let mut container = Container::default(); container - .add_window(&Window::from(1), WindowHidingPosition::BottomLeft) + .add_window_at(&Window::from(1), WindowHidingPosition::BottomLeft) .unwrap(); assert_eq!(container.windows().len(), 1); @@ -274,7 +254,7 @@ mod tests { for i in 0..3 { container - .add_window(&Window::from(i), WindowHidingPosition::BottomLeft) + .add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft) .unwrap(); } @@ -300,7 +280,7 @@ mod tests { for i in 0..3 { container - .add_window(&Window::from(i), WindowHidingPosition::BottomLeft) + .add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft) .unwrap(); } @@ -324,3 +304,33 @@ mod tests { assert_eq!(deserialized.id, container.id); } } + +#[cfg(test)] +mod state_pin { + use super::*; + + /// `komorebic state` prints a container as `{id, locked, windows: {elements, focused}}`; the + /// shared container must keep writing exactly that for macOS. + #[test] + fn a_container_is_written_as_id_locked_and_windows() { + let container = Container { + id: "c1".to_string(), + locked: true, + ..Default::default() + }; + + assert_eq!( + serde_json::to_string(&container).unwrap(), + r#"{"id":"c1","locked":true,"windows":{"elements":[],"focused":0}}"# + ); + } + + /// the old macOS container needed `locked` to be present; the shared one does not + #[test] + fn a_container_without_locked_is_read() { + let container: Container = + serde_json::from_str(r#"{"id":"c1","windows":{"elements":[],"focused":0}}"#).unwrap(); + + assert!(!container.locked); + } +} diff --git a/komorebi-for-mac/komorebi/src/monitor.rs b/komorebi-for-mac/komorebi/src/monitor.rs index 967abe51..bf46d1e9 100644 --- a/komorebi-for-mac/komorebi/src/monitor.rs +++ b/komorebi-for-mac/komorebi/src/monitor.rs @@ -1,6 +1,7 @@ use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_WORKSPACE_PADDING; use crate::container::Container; +use crate::container::ContainerExt; use crate::core::DefaultLayout; use crate::core::FloatingLayerBehaviour; use crate::core::Layout; @@ -361,7 +362,7 @@ impl Monitor { if target_workspace.monocle_container.is_some() { for container in target_workspace.containers_mut() { - container.restore()?; + container.restore_focused_window()?; } for window in target_workspace.floating_windows_mut() { @@ -419,7 +420,7 @@ impl Monitor { if target_workspace.monocle_container.is_some() { for container in target_workspace.containers_mut() { - container.restore()?; + container.restore_focused_window()?; } target_workspace.reintegrate_monocle_container()?; diff --git a/komorebi-for-mac/komorebi/src/process_event.rs b/komorebi-for-mac/komorebi/src/process_event.rs index 2a86faa9..6ff8edba 100644 --- a/komorebi-for-mac/komorebi/src/process_event.rs +++ b/komorebi-for-mac/komorebi/src/process_event.rs @@ -1,4 +1,5 @@ use crate::AccessibilityUiElement; +use crate::container::ContainerExt; use crate::FLOATING_APPLICATIONS; use crate::Notification; use crate::NotificationEvent; @@ -691,7 +692,7 @@ impl WindowManager { workspace .focused_container_mut() .ok_or_eyre("there is no focused container")? - .add_window(&window, window_hiding_position)?; + .add_window_at(&window, window_hiding_position)?; workspace.layer = WorkspaceLayer::Tiling; self.update_focused_workspace(true, false)?; } diff --git a/komorebi-for-mac/komorebi/src/scrolling.rs b/komorebi-for-mac/komorebi/src/scrolling.rs index c87bc504..8c2bade4 100644 --- a/komorebi-for-mac/komorebi/src/scrolling.rs +++ b/komorebi-for-mac/komorebi/src/scrolling.rs @@ -13,6 +13,7 @@ use crate::arrival; use crate::container::Container; +use crate::container::ContainerExt; use crate::core::DefaultLayout; use crate::core::Layout; use crate::core::LayoutOptions; @@ -61,7 +62,7 @@ fn show(container: &mut Container) -> eyre::Result<()> { }); #[cfg(not(test))] - container.restore()?; + container.restore_focused_window()?; Ok(()) } @@ -542,7 +543,7 @@ impl Workspace { if let Some(container) = self.containers_mut().get_mut(idx) { for window in &windows { - container.add_window(window, hiding_position)?; + container.add_window_at(window, hiding_position)?; } // the window that had focus is the one that is showing @@ -553,7 +554,7 @@ impl Workspace { } if !cfg!(test) { - container.load_focused_window(hiding_position)?; + container.load_focused_window_at(hiding_position)?; } } @@ -593,7 +594,7 @@ impl Workspace { let mut ids = vec![]; for (offset, window) in rest.iter().enumerate() { let mut container = Container::default(); - container.add_window(window, hiding_position)?; + container.add_window_at(window, hiding_position)?; ids.push(container.id.clone()); // it was one of the tabs that were out of sight, and has to be put where it is shown @@ -1371,7 +1372,7 @@ mod tests { .containers_mut() .front_mut() .unwrap() - .add_window(&Window::from(6_000_062), WindowHidingPosition::default()) + .add_window_at(&Window::from(6_000_062), WindowHidingPosition::default()) .unwrap(); workspace.layout_scrolling(&AREA, 0); @@ -1762,7 +1763,7 @@ mod tests { .containers_mut() .front_mut() .unwrap() - .add_window(&Window::from(212), WindowHidingPosition::default()) + .add_window_at(&Window::from(212), WindowHidingPosition::default()) .unwrap(); workspace.layout_scrolling(&AREA, 0); assert_eq!(windows_of(&workspace), [vec![210, 212], vec![211]]); diff --git a/komorebi-for-mac/komorebi/src/window_manager.rs b/komorebi-for-mac/komorebi/src/window_manager.rs index b39db0a7..be728bcf 100644 --- a/komorebi-for-mac/komorebi/src/window_manager.rs +++ b/komorebi-for-mac/komorebi/src/window_manager.rs @@ -17,6 +17,7 @@ use crate::application::Application; use crate::border_manager; use crate::border_manager::BorderLook; use crate::container::Container; +use crate::container::ContainerExt; use crate::core::Arrangement; use crate::core::Axis; use crate::core::CrossBoundaryBehaviour; @@ -1259,7 +1260,7 @@ impl WindowManager { let window_hiding_position = workspace.globals.window_hiding_position; if changed_focus && let Some(container) = workspace.focused_container_mut() { - container.load_focused_window(window_hiding_position)?; + container.load_focused_window_at(window_hiding_position)?; if let Some(window) = container.focused_window() { window.focus(mouse_follows_focus)?; } @@ -1355,7 +1356,7 @@ impl WindowManager { let next_idx = direction.next_idx(current_idx, len); container.focus_window(next_idx); - container.load_focused_window(window_hiding_position)?; + container.load_focused_window_at(window_hiding_position)?; if let Some(window) = container.focused_window() { window.focus(mouse_follows_focus)?; @@ -1561,7 +1562,7 @@ impl WindowManager { workspace.new_monocle_container()?; for container in workspace.containers_mut() { - container.hide(hiding_position, None, None)?; + container.hide_on(hiding_position, None, None)?; } Ok(()) @@ -1574,7 +1575,7 @@ impl WindowManager { let workspace = self.focused_workspace_mut()?; for container in workspace.containers_mut() { - container.restore()?; + container.restore_focused_window()?; } workspace.reintegrate_monocle_container() @@ -1597,7 +1598,7 @@ impl WindowManager { .cycle_monocle_container(direction)?; for container in self.focused_workspace_mut()?.containers_mut() { - container.hide(hiding_position, None, None)?; + container.hide_on(hiding_position, None, None)?; } self.update_focused_workspace(true, true) @@ -2617,7 +2618,7 @@ impl WindowManager { if target_workspace.monocle_container.is_some() { for container in target_workspace.containers_mut() { - container.restore()?; + container.restore_focused_window()?; } for window in target_workspace.floating_windows_mut() { @@ -2909,7 +2910,7 @@ impl WindowManager { container.windows_mut().swap(current_idx, next_idx); container.focus_window(next_idx); - container.load_focused_window(window_hiding_position)?; + container.load_focused_window_at(window_hiding_position)?; if let Some(window) = container.focused_window() { window.focus(mouse_follows_focus)?; @@ -2944,7 +2945,7 @@ impl WindowManager { } container.focus_window(idx); - container.load_focused_window(window_hiding_position)?; + container.load_focused_window_at(window_hiding_position)?; if let Some(window) = container.focused_window() { window.focus(mouse_follows_focus)?; @@ -2986,7 +2987,7 @@ impl WindowManager { && let Some(w_idx_to_focus) = c.idx_for_window(hwnd) { c.focus_window(w_idx_to_focus); - c.load_focused_window(window_hiding_position)?; + c.load_focused_window_at(window_hiding_position)?; } self.update_focused_workspace(self.mouse_follows_focus, true) } @@ -3790,7 +3791,7 @@ impl WindowManager { .ok_or_eyre("there is no workspace for this monitor")?; for container in origin_workspace.containers_mut() { - container.restore()?; + container.restore_focused_window()?; } origin_workspace.reintegrate_monocle_container()?; diff --git a/komorebi-for-mac/komorebi/src/workspace.rs b/komorebi-for-mac/komorebi/src/workspace.rs index 7666bf3b..7ee488d6 100644 --- a/komorebi-for-mac/komorebi/src/workspace.rs +++ b/komorebi-for-mac/komorebi/src/workspace.rs @@ -1,5 +1,6 @@ use crate::DATA_DIR; use crate::container::Container; +use crate::container::ContainerExt; use crate::core::Axis; use crate::core::CycleDirection; use crate::core::DefaultLayout; @@ -438,7 +439,7 @@ impl Workspace { if !cfg!(test) { if should_load { - container.load_focused_window(window_hiding_position)?; + container.load_focused_window_at(window_hiding_position)?; } } else { tracing::info!( @@ -466,7 +467,7 @@ impl Workspace { }; let mut container = Container::default(); - container.add_window(window, self.globals.window_hiding_position)?; + container.add_window_at(window, self.globals.window_hiding_position)?; self.insert_container_at_idx(next_idx, container); @@ -651,7 +652,7 @@ impl Workspace { } for c in self.containers_mut() { - c.restore()?; + c.restore_focused_window()?; } return Ok(window); @@ -689,7 +690,7 @@ impl Workspace { self.focus_previous_container(); } } else { - container.load_focused_window(window_hiding_position)?; + container.load_focused_window_at(window_hiding_position)?; if let Some(window) = container.focused_window() { window.focus(false)?; } @@ -849,7 +850,7 @@ impl Workspace { target_container_idx } } else { - container.load_focused_window(window_hiding_position)?; + container.load_focused_window_at(window_hiding_position)?; target_container_idx }; @@ -858,12 +859,12 @@ impl Workspace { .get_mut(adjusted_target_container_index) .ok_or_eyre("there is no container")?; - target_container.add_window(&window, window_hiding_position)?; + target_container.add_window_at(&window, window_hiding_position)?; self.focus_container(adjusted_target_container_index); self.focused_container_mut() .ok_or_eyre("there is no container")? - .load_focused_window(window_hiding_position)?; + .load_focused_window_at(window_hiding_position)?; Ok(()) } @@ -883,13 +884,13 @@ impl Workspace { if container.windows().is_empty() { self.remove_container_by_idx(focused_container_idx); } else { - container.load_focused_window(window_hiding_position)?; + container.load_focused_window_at(window_hiding_position)?; } self.new_container_for_window(&window)?; let mut container = Container::default(); - container.add_window(&window, window_hiding_position)?; + container.add_window_at(&window, window_hiding_position)?; Ok(()) } @@ -920,7 +921,7 @@ impl Workspace { } for container in self.containers_mut() { - container.hide(window_hiding_position, omit, screen)?; + container.hide_on(window_hiding_position, omit, screen)?; } // if let Some(window) = self.maximized_window() { @@ -928,7 +929,7 @@ impl Workspace { // } if let Some(container) = &mut self.monocle_container { - container.hide(window_hiding_position, omit, screen)?; + container.hide_on(window_hiding_position, omit, screen)?; } Ok(()) @@ -948,7 +949,7 @@ impl Workspace { /// which is all of [`Workspace::restore`] that is windows being moved pub fn restore_windows(&mut self, mouse_follows_focus: bool) -> eyre::Result<()> { if let Some(container) = &mut self.monocle_container { - container.restore()?; + container.restore_focused_window()?; if let Some(window) = container.focused_window() { window.focus(mouse_follows_focus)?; @@ -969,7 +970,7 @@ impl Workspace { } for container in self.containers_mut() { - container.restore()?; + container.restore_focused_window()?; } if let Some(container) = self.focused_container_mut() { @@ -1077,7 +1078,7 @@ impl Workspace { self.monocle_container .as_mut() .ok_or_eyre("there is no monocle container")? - .load_focused_window(self.globals.window_hiding_position)?; + .load_focused_window_at(self.globals.window_hiding_position)?; Ok(()) } @@ -1124,7 +1125,7 @@ impl Workspace { self.focus_container(restore_idx); self.focused_container_mut() .ok_or_eyre("there is no container")? - .load_focused_window(window_hiding_position)?; + .load_focused_window_at(window_hiding_position)?; self.monocle_container = None; self.monocle_container_restore_idx = None; @@ -1144,7 +1145,7 @@ impl Workspace { self.monocle_container = None; self.monocle_container_restore_idx = None; } else { - monocle_container.load_focused_window(self.globals.window_hiding_position)?; + monocle_container.load_focused_window_at(self.globals.window_hiding_position)?; } window @@ -1166,7 +1167,7 @@ impl Workspace { self.focus_container(focused_idx.saturating_sub(1)); } } else { - container.load_focused_window(window_hiding_position)?; + container.load_focused_window_at(window_hiding_position)?; } window @@ -1184,7 +1185,7 @@ impl Workspace { .ok_or_eyre("there is no floating window")?; let mut container = Container::default(); - container.add_window(&window, self.globals.window_hiding_position)?; + container.add_window_at(&window, self.globals.window_hiding_position)?; self.insert_container_at_idx(focused_idx, container); @@ -2028,7 +2029,7 @@ mod tests { let window = ws.floating_windows_mut().pop_back().unwrap(); let mut container = Container::default(); container - .add_window(&window, WindowHidingPosition::BottomLeft) + .add_window_at(&window, WindowHidingPosition::BottomLeft) .unwrap(); ws.insert_container_at_idx(ws.focused_container_idx(), container);