diff --git a/komorebi-core/src/layout.rs b/komorebi-core/src/layout.rs index 0d4dc21d..7dc401ab 100644 --- a/komorebi-core/src/layout.rs +++ b/komorebi-core/src/layout.rs @@ -1,3 +1,5 @@ +use std::num::NonZeroUsize; + use clap::Clap; use serde::Deserialize; use serde::Serialize; @@ -127,11 +129,12 @@ impl Layout { pub fn calculate( &self, area: &Rect, - len: usize, + len: NonZeroUsize, container_padding: Option, layout_flip: Option, resize_dimensions: &[Option], ) -> Vec { + let len = usize::from(len); let mut dimensions = match self { Layout::BSP => recursive_fibonacci( 0, diff --git a/komorebi/src/container.rs b/komorebi/src/container.rs index 1b3ca051..e1d9d6df 100644 --- a/komorebi/src/container.rs +++ b/komorebi/src/container.rs @@ -33,12 +33,6 @@ impl PartialEq for &Container { } impl Container { - pub fn hide(&mut self) { - for window in self.windows_mut() { - window.hide(); - } - } - pub fn load_focused_window(&mut self) { let focused_idx = self.focused_window_idx(); for (i, window) in self.windows_mut().iter_mut().enumerate() { diff --git a/komorebi/src/ring.rs b/komorebi/src/ring.rs index d732ec0b..446759c0 100644 --- a/komorebi/src/ring.rs +++ b/komorebi/src/ring.rs @@ -59,6 +59,7 @@ macro_rules! impl_ring_elements { self.[<$element:lower s>].elements_mut() } + #[allow(dead_code)] pub fn [](&self) -> Option<&$element> { self.[<$element:lower s>].focused() } diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 8195126a..fe5e71e9 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -154,6 +154,7 @@ impl Window { WindowsApi::set_focus(self.hwnd()) } + #[allow(dead_code)] pub fn update_style(self, style: GwlStyle) -> Result<()> { WindowsApi::update_style(self.hwnd(), isize::try_from(style.bits())?) } diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 15e2189e..2225cafc 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1,5 +1,6 @@ use std::collections::VecDeque; use std::io::ErrorKind; +use std::num::NonZeroUsize; use std::sync::Arc; use std::sync::Mutex; @@ -126,7 +127,9 @@ impl WindowManager { ) { let unaltered = workspace.layout().calculate( &work_area, - len, + NonZeroUsize::new(len).context( + "there must be at least one container to calculate a workspace layout", + )?, workspace.container_padding(), workspace.layout_flip(), &[], diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index 4e4bd053..f3216af6 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -371,6 +371,7 @@ impl WindowsApi { } } + #[allow(dead_code)] fn set_window_long_ptr_w( hwnd: HWND, index: WINDOW_LONG_PTR_INDEX, @@ -396,6 +397,7 @@ impl WindowsApi { })) } + #[allow(dead_code)] pub fn update_style(hwnd: HWND, new_value: isize) -> Result<()> { Self::set_window_long_ptr_w(hwnd, GWL_STYLE, new_value) } diff --git a/komorebi/src/winevent.rs b/komorebi/src/winevent.rs index e9209ae6..a7ea8885 100644 --- a/komorebi/src/winevent.rs +++ b/komorebi/src/winevent.rs @@ -1,3 +1,5 @@ +use strum::Display; + use bindings::Windows::Win32::UI::WindowsAndMessaging::EVENT_AIA_END; use bindings::Windows::Win32::UI::WindowsAndMessaging::EVENT_AIA_START; use bindings::Windows::Win32::UI::WindowsAndMessaging::EVENT_CONSOLE_CARET; @@ -83,8 +85,9 @@ use bindings::Windows::Win32::UI::WindowsAndMessaging::EVENT_UIA_EVENTID_START; use bindings::Windows::Win32::UI::WindowsAndMessaging::EVENT_UIA_PROPID_END; use bindings::Windows::Win32::UI::WindowsAndMessaging::EVENT_UIA_PROPID_START; -#[derive(Clone, Copy, PartialEq, Debug, strum::Display)] +#[derive(Clone, Copy, PartialEq, Debug, Display)] #[repr(u32)] +#[allow(dead_code)] pub enum WinEvent { AiaEnd = EVENT_AIA_END, AiaStart = EVENT_AIA_START, diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 7d9f85d6..8aed25ec 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -1,4 +1,5 @@ use std::collections::VecDeque; +use std::num::NonZeroUsize; use color_eyre::eyre::ContextCompat; use color_eyre::Result; @@ -110,10 +111,12 @@ impl Workspace { if let Some(window) = container.focused_window_mut() { window.set_position(&adjusted_work_area, true)?; } - } else { + } else if !self.containers().is_empty() { let layouts = self.layout().calculate( &adjusted_work_area, - self.containers().len(), + NonZeroUsize::new(self.containers().len()).context( + "there must be at least one container to calculate a workspace layout", + )?, self.container_padding(), self.layout_flip(), self.resize_dimensions(), @@ -409,14 +412,24 @@ impl Workspace { } pub fn new_container_for_window(&mut self, window: Window) { - let focused_idx = self.focused_container_idx(); + let next_idx = self.focused_container_idx() + 1; let mut container = Container::default(); container.add_window(window); - self.containers_mut().insert(focused_idx + 1, container); - self.resize_dimensions_mut().insert(focused_idx + 1, None); - self.focus_container(focused_idx + 1); + if next_idx > self.containers().len() { + self.containers_mut().push_back(container); + } else { + self.containers_mut().insert(next_idx, container); + } + + if next_idx > self.resize_dimensions().len() { + self.resize_dimensions_mut().push(None); + } else { + self.resize_dimensions_mut().insert(next_idx, None); + } + + self.focus_container(next_idx); } pub fn new_floating_window(&mut self) -> Result<()> {