chore(cargo): +nightly fmt

This commit is contained in:
LGUG2Z
2024-10-11 10:30:35 -07:00
parent 2d2cea31c0
commit 7943fccb1b
9 changed files with 85 additions and 49 deletions

View File

@@ -43,7 +43,7 @@ impl From<BatteryConfig> for Battery {
State::Discharging => state = Some(BatteryState::Discharging), State::Discharging => state = Some(BatteryState::Discharging),
_ => {} _ => {}
} }
last_state = match prefix { last_state = match prefix {
LabelPrefix::Text | LabelPrefix::IconAndText => { LabelPrefix::Text | LabelPrefix::IconAndText => {
format!("BAT: {percentage:.0}%") format!("BAT: {percentage:.0}%")

View File

@@ -112,7 +112,7 @@ impl BarWidget for Date {
if let LabelPrefix::Text | LabelPrefix::IconAndText = self.label_prefix { if let LabelPrefix::Text | LabelPrefix::IconAndText = self.label_prefix {
output.insert_str(0, "DATE: "); output.insert_str(0, "DATE: ");
} }
layout_job.append( layout_job.append(
&output, &output,
10.0, 10.0,

View File

@@ -62,7 +62,7 @@ impl Storage {
let total = disk.total_space(); let total = disk.total_space();
let available = disk.available_space(); let available = disk.available_space();
let used = total - available; let used = total - available;
disks.push(match self.label_prefix { disks.push(match self.label_prefix {
LabelPrefix::Text | LabelPrefix::IconAndText => { LabelPrefix::Text | LabelPrefix::IconAndText => {
format!("{} {}%", mount.to_string_lossy(), (used * 100) / total) format!("{} {}%", mount.to_string_lossy(), (used * 100) / total)

View File

@@ -345,9 +345,7 @@ pub enum FocusFollowsMouseImplementation {
Windows, Windows,
} }
#[derive( #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq,
)]
pub struct WindowManagementBehaviour { pub struct WindowManagementBehaviour {
/// The current WindowContainerBehaviour to be used /// The current WindowContainerBehaviour to be used
pub current_behaviour: WindowContainerBehaviour, pub current_behaviour: WindowContainerBehaviour,
@@ -358,7 +356,17 @@ pub struct WindowManagementBehaviour {
} }
#[derive( #[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 { pub enum WindowContainerBehaviour {
/// Create a new container for each new window /// Create a new container for each new window

View File

@@ -1348,30 +1348,39 @@ impl WindowManager {
SocketMessage::ToggleWindowContainerBehaviour => { SocketMessage::ToggleWindowContainerBehaviour => {
match self.window_management_behaviour.current_behaviour { match self.window_management_behaviour.current_behaviour {
WindowContainerBehaviour::Create => { WindowContainerBehaviour::Create => {
self.window_management_behaviour.current_behaviour = WindowContainerBehaviour::Append; self.window_management_behaviour.current_behaviour =
WindowContainerBehaviour::Append;
} }
WindowContainerBehaviour::Append => { WindowContainerBehaviour::Append => {
self.window_management_behaviour.current_behaviour = WindowContainerBehaviour::Create; self.window_management_behaviour.current_behaviour =
WindowContainerBehaviour::Create;
} }
} }
} }
SocketMessage::ToggleFloatOverride => { 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 => { SocketMessage::ToggleWorkspaceWindowContainerBehaviour => {
let current_global_behaviour = self.window_management_behaviour.current_behaviour; 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 { match behaviour {
WindowContainerBehaviour::Create => *behaviour = WindowContainerBehaviour::Append, WindowContainerBehaviour::Create => {
WindowContainerBehaviour::Append => *behaviour = WindowContainerBehaviour::Create, *behaviour = WindowContainerBehaviour::Append
}
WindowContainerBehaviour::Append => {
*behaviour = WindowContainerBehaviour::Create
}
} }
} else { } else {
self.focused_workspace_mut()?.set_window_container_behaviour( self.focused_workspace_mut()?
Some(match current_global_behaviour { .set_window_container_behaviour(Some(match current_global_behaviour {
WindowContainerBehaviour::Create => WindowContainerBehaviour::Append, WindowContainerBehaviour::Create => WindowContainerBehaviour::Append,
WindowContainerBehaviour::Append => WindowContainerBehaviour::Create, WindowContainerBehaviour::Append => WindowContainerBehaviour::Create,
}) }));
);
}; };
} }
SocketMessage::ToggleWorkspaceFloatOverride => { SocketMessage::ToggleWorkspaceFloatOverride => {
@@ -1379,7 +1388,8 @@ impl WindowManager {
if let Some(float_override) = self.focused_workspace_mut()?.float_override_mut() { if let Some(float_override) = self.focused_workspace_mut()?.float_override_mut() {
*float_override = !*float_override; *float_override = !*float_override;
} else { } 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) => { SocketMessage::WindowHidingBehaviour(behaviour) => {

View File

@@ -333,8 +333,8 @@ impl WindowManager {
} }
if proceed { if proceed {
let mut behaviour = let mut behaviour = self
self.window_management_behaviour(focused_monitor_idx, focused_workspace_idx); .window_management_behaviour(focused_monitor_idx, focused_workspace_idx);
let workspace = self.focused_workspace_mut()?; let workspace = self.focused_workspace_mut()?;
let workspace_contains_window = workspace.contains_window(window.hwnd); let workspace_contains_window = workspace.contains_window(window.hwnd);
let monocle_container = workspace.monocle_container().clone(); 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 { if behaviour.float_override {
workspace.floating_windows_mut().push(window); workspace.floating_windows_mut().push(window);

View File

@@ -527,7 +527,9 @@ impl From<&WindowManager> for StaticConfig {
single: Option::from(Colour::from(border_manager::FOCUSED.load(Ordering::SeqCst))), single: Option::from(Colour::from(border_manager::FOCUSED.load(Ordering::SeqCst))),
stack: Option::from(Colour::from(border_manager::STACK.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))), 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( unfocused: Option::from(Colour::from(
border_manager::UNFOCUSED.load(Ordering::SeqCst), border_manager::UNFOCUSED.load(Ordering::SeqCst),
)), )),
@@ -537,7 +539,9 @@ impl From<&WindowManager> for StaticConfig {
Self { Self {
invisible_borders: None, invisible_borders: None,
resize_delta: Option::from(value.resize_delta), 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), float_override: Option::from(value.window_management_behaviour.float_override),
cross_monitor_move_behaviour: Option::from(value.cross_monitor_move_behaviour), cross_monitor_move_behaviour: Option::from(value.cross_monitor_move_behaviour),
cross_boundary_behaviour: Option::from(value.cross_boundary_behaviour), cross_boundary_behaviour: Option::from(value.cross_boundary_behaviour),
@@ -1054,7 +1058,9 @@ impl StaticConfig {
virtual_desktop_id: current_virtual_desktop(), virtual_desktop_id: current_virtual_desktop(),
work_area_offset: value.global_work_area_offset, work_area_offset: value.global_work_area_offset,
window_management_behaviour: WindowManagementBehaviour { 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(), float_override: value.float_override.unwrap_or_default(),
}, },
cross_monitor_move_behaviour: value cross_monitor_move_behaviour: value

View File

@@ -321,19 +321,27 @@ impl WindowManager {
) -> WindowManagementBehaviour { ) -> WindowManagementBehaviour {
if let Some(monitor) = self.monitors().get(monitor_idx) { if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.workspaces().get(workspace_idx) { if let Some(workspace) = monitor.workspaces().get(workspace_idx) {
let current_behaviour = if let Some(behaviour) = workspace.window_container_behaviour() { let current_behaviour =
if workspace.containers().is_empty() && matches!(behaviour, WindowContainerBehaviour::Append) { 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 // You can't append to an empty workspace
WindowContainerBehaviour::Create WindowContainerBehaviour::Create
} else { } else {
*behaviour self.window_management_behaviour.current_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
};
let float_override = if let Some(float_override) = workspace.float_override() { let float_override = if let Some(float_override) = workspace.float_override() {
*float_override *float_override
@@ -343,7 +351,7 @@ impl WindowManager {
return WindowManagementBehaviour { return WindowManagementBehaviour {
current_behaviour, current_behaviour,
float_override float_override,
}; };
} }
} }
@@ -1190,20 +1198,20 @@ impl WindowManager {
bail!("cannot move native maximized window to another monitor or workspace"); bail!("cannot move native maximized window to another monitor or workspace");
} }
let foreground_hwnd = WindowsApi::foreground_window()?; let foreground_hwnd = WindowsApi::foreground_window()?;
let floating_window_index = workspace let floating_window_index = workspace
.floating_windows() .floating_windows()
.iter() .iter()
.position(|w| w.hwnd == foreground_hwnd); .position(|w| w.hwnd == foreground_hwnd);
let floating_window = floating_window_index.map(|idx| { let floating_window =
workspace.floating_windows_mut().remove(idx) floating_window_index.map(|idx| workspace.floating_windows_mut().remove(idx));
});
let container = if floating_window_index.is_none() { let container = if floating_window_index.is_none() {
Some(workspace Some(
.remove_focused_container() workspace
.ok_or_else(|| anyhow!("there is no container"))?) .remove_focused_container()
.ok_or_else(|| anyhow!("there is no container"))?,
)
} else { } else {
None None
}; };
@@ -1217,12 +1225,14 @@ impl WindowManager {
if let Some(workspace_idx) = workspace_idx { if let Some(workspace_idx) = workspace_idx {
target_monitor.focus_workspace(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"))?; .ok_or_else(|| anyhow!("there is no focused workspace on target monitor"))?;
if let Some(window) = floating_window { if let Some(window) = floating_window {
target_workspace.floating_windows_mut().push(window); target_workspace.floating_windows_mut().push(window);
Window::from(window.hwnd).move_to_area(&current_area, target_monitor.work_area_size())?; Window::from(window.hwnd)
.move_to_area(&current_area, target_monitor.work_area_size())?;
} else if let Some(container) = container { } else if let Some(container) = container {
let container_hwnds = container let container_hwnds = container
.windows() .windows()
@@ -1235,7 +1245,8 @@ impl WindowManager {
if let Some(workspace) = target_monitor.focused_workspace() { if let Some(workspace) = target_monitor.focused_workspace() {
if !*workspace.tile() { if !*workspace.tile() {
for hwnd in container_hwnds { for hwnd in container_hwnds {
Window::from(hwnd).move_to_area(&current_area, target_monitor.work_area_size())?; Window::from(hwnd)
.move_to_area(&current_area, target_monitor.work_area_size())?;
} }
} }
} }

View File

@@ -598,10 +598,10 @@ impl Workspace {
} }
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.containers().is_empty() self.containers().is_empty()
&& self.maximized_window().is_none() && self.maximized_window().is_none()
&& self.monocle_container().is_none() && self.monocle_container().is_none()
&& self.floating_windows().is_empty() && self.floating_windows().is_empty()
} }
pub fn contains_window(&self, hwnd: isize) -> bool { pub fn contains_window(&self, hwnd: isize) -> bool {