Skip to content

Commit

Permalink
chore(cargo): +nightly fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
LGUG2Z committed Oct 13, 2024
1 parent 2d2cea3 commit 7943fcc
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 49 deletions.
2 changes: 1 addition & 1 deletion komorebi-bar/src/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}%")
Expand Down
2 changes: 1 addition & 1 deletion komorebi-bar/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion komorebi-bar/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions komorebi/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
32 changes: 21 additions & 11 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,38 +1348,48 @@ 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 => {
let current_global_override = self.window_management_behaviour.float_override;
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) => {
Expand Down
7 changes: 4 additions & 3 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)),
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down
53 changes: 32 additions & 21 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -343,7 +351,7 @@ impl WindowManager {

return WindowManagementBehaviour {
current_behaviour,
float_override
float_override,
};
}
}
Expand Down Expand Up @@ -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
};
Expand All @@ -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()
Expand All @@ -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())?;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7943fcc

Please sign in to comment.