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),
_ => {}
}
last_state = match prefix {
LabelPrefix::Text | LabelPrefix::IconAndText => {
format!("BAT: {percentage:.0}%")

View File

@@ -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,

View File

@@ -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)

View File

@@ -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

View File

@@ -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) => {

View File

@@ -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);

View File

@@ -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

View File

@@ -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(&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 {
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(&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 {
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 {