From 7943fccb1bd372b4ccf67764b6119c58a6a414ff Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 11 Oct 2024 10:30:35 -0700 Subject: [PATCH] chore(cargo): +nightly fmt --- komorebi-bar/src/battery.rs | 2 +- komorebi-bar/src/date.rs | 2 +- komorebi-bar/src/storage.rs | 2 +- komorebi/src/core/mod.rs | 16 +++++++--- komorebi/src/process_command.rs | 32 +++++++++++++------- komorebi/src/process_event.rs | 7 +++-- komorebi/src/static_config.rs | 12 ++++++-- komorebi/src/window_manager.rs | 53 ++++++++++++++++++++------------- komorebi/src/workspace.rs | 8 ++--- 9 files changed, 85 insertions(+), 49 deletions(-) diff --git a/komorebi-bar/src/battery.rs b/komorebi-bar/src/battery.rs index 0925b109..3f1e198e 100644 --- a/komorebi-bar/src/battery.rs +++ b/komorebi-bar/src/battery.rs @@ -43,7 +43,7 @@ impl From for Battery { State::Discharging => state = Some(BatteryState::Discharging), _ => {} } - + last_state = match prefix { LabelPrefix::Text | LabelPrefix::IconAndText => { format!("BAT: {percentage:.0}%") diff --git a/komorebi-bar/src/date.rs b/komorebi-bar/src/date.rs index 9a2727c3..666fb2f1 100644 --- a/komorebi-bar/src/date.rs +++ b/komorebi-bar/src/date.rs @@ -112,7 +112,7 @@ impl BarWidget for Date { if let LabelPrefix::Text | LabelPrefix::IconAndText = self.label_prefix { output.insert_str(0, "DATE: "); } - + layout_job.append( &output, 10.0, diff --git a/komorebi-bar/src/storage.rs b/komorebi-bar/src/storage.rs index c81f66da..a4498dc5 100644 --- a/komorebi-bar/src/storage.rs +++ b/komorebi-bar/src/storage.rs @@ -62,7 +62,7 @@ impl Storage { let total = disk.total_space(); let available = disk.available_space(); let used = total - available; - + disks.push(match self.label_prefix { LabelPrefix::Text | LabelPrefix::IconAndText => { format!("{} {}%", mount.to_string_lossy(), (used * 100) / total) diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 7cbe7836..93f785bd 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -345,9 +345,7 @@ pub enum FocusFollowsMouseImplementation { Windows, } -#[derive( - Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, -)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)] pub struct WindowManagementBehaviour { /// The current WindowContainerBehaviour to be used pub current_behaviour: WindowContainerBehaviour, @@ -358,7 +356,17 @@ pub struct WindowManagementBehaviour { } #[derive( - Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, JsonSchema, PartialEq + Clone, + Copy, + Debug, + Default, + Serialize, + Deserialize, + Display, + EnumString, + ValueEnum, + JsonSchema, + PartialEq, )] pub enum WindowContainerBehaviour { /// Create a new container for each new window diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index ac0aa242..b3525c0b 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1348,30 +1348,39 @@ impl WindowManager { SocketMessage::ToggleWindowContainerBehaviour => { match self.window_management_behaviour.current_behaviour { WindowContainerBehaviour::Create => { - self.window_management_behaviour.current_behaviour = WindowContainerBehaviour::Append; + self.window_management_behaviour.current_behaviour = + WindowContainerBehaviour::Append; } WindowContainerBehaviour::Append => { - self.window_management_behaviour.current_behaviour = WindowContainerBehaviour::Create; + self.window_management_behaviour.current_behaviour = + WindowContainerBehaviour::Create; } } } SocketMessage::ToggleFloatOverride => { - self.window_management_behaviour.float_override = !self.window_management_behaviour.float_override; + self.window_management_behaviour.float_override = + !self.window_management_behaviour.float_override; } SocketMessage::ToggleWorkspaceWindowContainerBehaviour => { let current_global_behaviour = self.window_management_behaviour.current_behaviour; - if let Some(behaviour) = self.focused_workspace_mut()?.window_container_behaviour_mut() { + if let Some(behaviour) = self + .focused_workspace_mut()? + .window_container_behaviour_mut() + { match behaviour { - WindowContainerBehaviour::Create => *behaviour = WindowContainerBehaviour::Append, - WindowContainerBehaviour::Append => *behaviour = WindowContainerBehaviour::Create, + WindowContainerBehaviour::Create => { + *behaviour = WindowContainerBehaviour::Append + } + WindowContainerBehaviour::Append => { + *behaviour = WindowContainerBehaviour::Create + } } } else { - self.focused_workspace_mut()?.set_window_container_behaviour( - Some(match current_global_behaviour { + self.focused_workspace_mut()? + .set_window_container_behaviour(Some(match current_global_behaviour { WindowContainerBehaviour::Create => WindowContainerBehaviour::Append, WindowContainerBehaviour::Append => WindowContainerBehaviour::Create, - }) - ); + })); }; } SocketMessage::ToggleWorkspaceFloatOverride => { @@ -1379,7 +1388,8 @@ impl WindowManager { if let Some(float_override) = self.focused_workspace_mut()?.float_override_mut() { *float_override = !*float_override; } else { - self.focused_workspace_mut()?.set_float_override(Some(!current_global_override)); + self.focused_workspace_mut()? + .set_float_override(Some(!current_global_override)); }; } SocketMessage::WindowHidingBehaviour(behaviour) => { diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 46fd9e03..71d6e090 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -333,8 +333,8 @@ impl WindowManager { } if proceed { - let mut behaviour = - self.window_management_behaviour(focused_monitor_idx, focused_workspace_idx); + let mut behaviour = self + .window_management_behaviour(focused_monitor_idx, focused_workspace_idx); let workspace = self.focused_workspace_mut()?; let workspace_contains_window = workspace.contains_window(window.hwnd); let monocle_container = workspace.monocle_container().clone(); @@ -360,7 +360,8 @@ impl WindowManager { } } - behaviour.float_override = behaviour.float_override || (should_float && !matches!(event, WindowManagerEvent::Manage(_))); + behaviour.float_override = behaviour.float_override + || (should_float && !matches!(event, WindowManagerEvent::Manage(_))); if behaviour.float_override { workspace.floating_windows_mut().push(window); diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index dd1385f1..e3a0d70d 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -527,7 +527,9 @@ impl From<&WindowManager> for StaticConfig { single: Option::from(Colour::from(border_manager::FOCUSED.load(Ordering::SeqCst))), stack: Option::from(Colour::from(border_manager::STACK.load(Ordering::SeqCst))), monocle: Option::from(Colour::from(border_manager::MONOCLE.load(Ordering::SeqCst))), - floating: Option::from(Colour::from(border_manager::FLOATING.load(Ordering::SeqCst))), + floating: Option::from(Colour::from( + border_manager::FLOATING.load(Ordering::SeqCst), + )), unfocused: Option::from(Colour::from( border_manager::UNFOCUSED.load(Ordering::SeqCst), )), @@ -537,7 +539,9 @@ impl From<&WindowManager> for StaticConfig { Self { invisible_borders: None, resize_delta: Option::from(value.resize_delta), - window_container_behaviour: Option::from(value.window_management_behaviour.current_behaviour), + window_container_behaviour: Option::from( + value.window_management_behaviour.current_behaviour, + ), float_override: Option::from(value.window_management_behaviour.float_override), cross_monitor_move_behaviour: Option::from(value.cross_monitor_move_behaviour), cross_boundary_behaviour: Option::from(value.cross_boundary_behaviour), @@ -1054,7 +1058,9 @@ impl StaticConfig { virtual_desktop_id: current_virtual_desktop(), work_area_offset: value.global_work_area_offset, window_management_behaviour: WindowManagementBehaviour { - current_behaviour: value.window_container_behaviour.unwrap_or(WindowContainerBehaviour::Create), + current_behaviour: value + .window_container_behaviour + .unwrap_or(WindowContainerBehaviour::Create), float_override: value.float_override.unwrap_or_default(), }, cross_monitor_move_behaviour: value diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 3f69e233..2d3c7da3 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -321,19 +321,27 @@ impl WindowManager { ) -> WindowManagementBehaviour { if let Some(monitor) = self.monitors().get(monitor_idx) { if let Some(workspace) = monitor.workspaces().get(workspace_idx) { - let current_behaviour = if let Some(behaviour) = workspace.window_container_behaviour() { - if workspace.containers().is_empty() && matches!(behaviour, WindowContainerBehaviour::Append) { + let current_behaviour = + if let Some(behaviour) = workspace.window_container_behaviour() { + if workspace.containers().is_empty() + && matches!(behaviour, WindowContainerBehaviour::Append) + { + // You can't append to an empty workspace + WindowContainerBehaviour::Create + } else { + *behaviour + } + } else if workspace.containers().is_empty() + && matches!( + self.window_management_behaviour.current_behaviour, + WindowContainerBehaviour::Append + ) + { // You can't append to an empty workspace WindowContainerBehaviour::Create } else { - *behaviour - } - } else if workspace.containers().is_empty() && matches!(self.window_management_behaviour.current_behaviour, WindowContainerBehaviour::Append) { - // You can't append to an empty workspace - WindowContainerBehaviour::Create - } else { - self.window_management_behaviour.current_behaviour - }; + self.window_management_behaviour.current_behaviour + }; let float_override = if let Some(float_override) = workspace.float_override() { *float_override @@ -343,7 +351,7 @@ impl WindowManager { return WindowManagementBehaviour { current_behaviour, - float_override + float_override, }; } } @@ -1190,20 +1198,20 @@ impl WindowManager { bail!("cannot move native maximized window to another monitor or workspace"); } - let foreground_hwnd = WindowsApi::foreground_window()?; let floating_window_index = workspace .floating_windows() .iter() .position(|w| w.hwnd == foreground_hwnd); - let floating_window = floating_window_index.map(|idx| { - workspace.floating_windows_mut().remove(idx) - }); + let floating_window = + floating_window_index.map(|idx| workspace.floating_windows_mut().remove(idx)); let container = if floating_window_index.is_none() { - Some(workspace - .remove_focused_container() - .ok_or_else(|| anyhow!("there is no container"))?) + Some( + workspace + .remove_focused_container() + .ok_or_else(|| anyhow!("there is no container"))?, + ) } else { None }; @@ -1217,12 +1225,14 @@ impl WindowManager { if let Some(workspace_idx) = workspace_idx { target_monitor.focus_workspace(workspace_idx)?; } - let target_workspace = target_monitor.focused_workspace_mut() + let target_workspace = target_monitor + .focused_workspace_mut() .ok_or_else(|| anyhow!("there is no focused workspace on target monitor"))?; if let Some(window) = floating_window { target_workspace.floating_windows_mut().push(window); - Window::from(window.hwnd).move_to_area(¤t_area, target_monitor.work_area_size())?; + Window::from(window.hwnd) + .move_to_area(¤t_area, target_monitor.work_area_size())?; } else if let Some(container) = container { let container_hwnds = container .windows() @@ -1235,7 +1245,8 @@ impl WindowManager { if let Some(workspace) = target_monitor.focused_workspace() { if !*workspace.tile() { for hwnd in container_hwnds { - Window::from(hwnd).move_to_area(¤t_area, target_monitor.work_area_size())?; + Window::from(hwnd) + .move_to_area(¤t_area, target_monitor.work_area_size())?; } } } diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 18f1d5e1..91e54d77 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -598,10 +598,10 @@ impl Workspace { } pub fn is_empty(&self) -> bool { - self.containers().is_empty() - && self.maximized_window().is_none() - && self.monocle_container().is_none() - && self.floating_windows().is_empty() + self.containers().is_empty() + && self.maximized_window().is_none() + && self.monocle_container().is_none() + && self.floating_windows().is_empty() } pub fn contains_window(&self, hwnd: isize) -> bool {