{"record":{"id":"78ba23a8a9cf9ff9","repo":"LGUG2Z/komorebi","slug":"a-container-must-have-at-least-one-window","errorCode":null,"errorMessage":"a container must have at least one window","messagePattern":"a container must have at least one window","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"komorebi/src/window_manager.rs","lineNumber":3001,"sourceCode":"        tracing::info!(\"promoting focus\");\n\n        let target_idx = match &workspace.layout {\n            Layout::Default(_) => 0,\n            Layout::Custom(custom) => custom.first_container_idx(custom.primary_idx().unwrap_or(0)),\n        };\n\n        workspace.focus_container(target_idx);\n        self.update_focused_workspace(self.mouse_follows_focus, true)\n    }\n\n    #[tracing::instrument(skip(self))]\n    pub fn remove_window_from_container(&mut self) -> eyre::Result<()> {\n        self.handle_unmanaged_window_behaviour()?;\n\n        tracing::info!(\"removing window\");\n\n        if self.focused_container()?.windows().len() == 1 {\n            bail!(\"a container must have at least one window\");\n        }\n\n        let workspace = self.focused_workspace_mut()?;\n\n        workspace.new_container_for_focused_window()?;\n        self.update_focused_workspace(self.mouse_follows_focus, false)\n    }\n\n    #[tracing::instrument(skip(self))]\n    pub fn toggle_tiling(&mut self) -> eyre::Result<()> {\n        let workspace = self.focused_workspace_mut()?;\n        workspace.tile = !workspace.tile;\n        self.update_focused_workspace(false, false)\n    }\n\n    #[tracing::instrument(skip(self))]\n    pub fn toggle_float(&mut self, force_float: bool) -> eyre::Result<()> {\n        let hwnd = WindowsApi::foreground_window()?;","sourceCodeStart":2983,"sourceCodeEnd":3019,"githubUrl":"https://github.com/LGUG2Z/komorebi/blob/e0709f02bfae4e503bf4640f58ee75ecbbfdbb97/komorebi/src/window_manager.rs#L2983-L3019","documentation":"remove_window_from_container detaches the focused window into its own container. A container must retain at least one window, so when the focused container currently holds exactly one window the removal is rejected — otherwise komorebi's layout invariant (non-empty containers) would be violated.","triggerScenarios":"Calling remove_window_from_container (komorebic unstack / remove keybinds) when focused_container().windows().len() == 1, i.e. unstacking a window that has no stack partners.","commonSituations":"Unstack hotkey pressed on a normal single-window tiled container; scripts that unstack all containers blindly after stacking operations.","solutions":["Only call unstack when the container has 2+ windows (check state first)","Use a different command if the goal is closing/removing the window from the layout entirely","Swallow the error in batch unstack loops and continue with remaining containers","Restack a second window before attempting to remove one if the container must stay intact"],"exampleFix":"// before\nkomorebic unstack // fails on single-window container\n// after\nif [ \"$(komorebic query focused-container-length 2>/dev/null)\" -gt 1 ]; then komorebic unstack; fi","handlingStrategy":"validation","validationCode":"if query_focused_container_window_count() > 1 {\n    komorebic unstack\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check container window count before unstacking","In batch unstack loops, treat single-window containers as skippable","Understand that unstack moves a window out — it requires a stack partner"],"tags":["windows","window-manager","container","stack"],"backgroundTag":"operation-not-supported","analyzedSha":"e0709f02bfae4e503bf4640f58ee75ecbbfdbb97","analyzedAt":"2026-09-06T07:08:05.107Z","contentChangedAt":"2026-09-06T07:08:05.107Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}