refactor(rust): standardize on ok_or_eyre and bail!

This commit standardizes the codebase to disallow usage of the raw eyre!
macro for creating errors, instead using ok_or_eyre() when constructing
ad-hoc errors from Result and Option types, and otherwise using the
bail! macro in response to failed boolean conditions.
This commit is contained in:
LGUG2Z
2025-09-20 12:55:20 -07:00
parent e07b464b0d
commit bcfb058bc3
9 changed files with 249 additions and 270 deletions

View File

@@ -5,7 +5,6 @@ use std::ops::Deref;
use std::ops::DerefMut;
use std::path::Path;
use color_eyre::eyre::anyhow;
use color_eyre::eyre::bail;
use color_eyre::Result;
use serde::Deserialize;
@@ -41,7 +40,7 @@ impl CustomLayout {
Some(extension) if extension == "json" => {
serde_json::from_reader(BufReader::new(File::open(path)?))?
}
_ => return Err(anyhow!("custom layouts must be json or yaml files")),
_ => bail!("custom layouts must be json or yaml files"),
};
if !layout.is_valid() {

View File

@@ -17,7 +17,7 @@ use std::time::Duration;
use clap::Parser;
use clap::ValueEnum;
use color_eyre::eyre::anyhow;
use color_eyre::eyre::bail;
use color_eyre::Result;
use crossbeam_utils::Backoff;
use komorebi::animation::AnimationEngine;
@@ -210,9 +210,7 @@ fn main() -> Result<()> {
}
if set_foreground_window_retries == 0 {
return Err(anyhow!(
"failed call to AllowSetForegroundWindow after 5 retries"
));
bail!("failed call to AllowSetForegroundWindow after 5 retries");
}
}

View File

@@ -2,8 +2,8 @@ use std::collections::HashMap;
use std::collections::VecDeque;
use std::sync::atomic::Ordering;
use color_eyre::eyre::anyhow;
use color_eyre::eyre::bail;
use color_eyre::eyre::OptionExt;
use color_eyre::Result;
use getset::CopyGetters;
use getset::Getters;
@@ -290,10 +290,10 @@ impl Monitor {
let workspace = if let Some(idx) = workspace_idx {
self.workspaces_mut()
.get_mut(idx)
.ok_or_else(|| anyhow!("there is no workspace at index {}", idx))?
.ok_or_eyre(format!("there is no workspace at index {idx}"))?
} else {
self.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?
.ok_or_eyre("there is no workspace")?
};
workspace.add_container_to_back(container);
@@ -314,10 +314,10 @@ impl Monitor {
let workspace = if let Some(idx) = workspace_idx {
self.workspaces_mut()
.get_mut(idx)
.ok_or_else(|| anyhow!("there is no workspace at index {}", idx))?
.ok_or_eyre(format!("there is no workspace at index {idx}"))?
} else {
self.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?
.ok_or_eyre("there is no workspace")?
};
match direction {
@@ -415,7 +415,7 @@ impl Monitor {
) -> Result<()> {
let workspace = self
.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?;
.ok_or_eyre("there is no workspace")?;
if workspace.maximized_window().is_some() {
bail!("cannot move native maximized window to another monitor or workspace");
@@ -445,7 +445,7 @@ impl Monitor {
} else {
let container = workspace
.remove_focused_container()
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
let workspaces = self.workspaces_mut();
@@ -510,7 +510,7 @@ impl Monitor {
if name.is_some() {
self.workspaces_mut()
.get_mut(idx)
.ok_or_else(|| anyhow!("there is no workspace"))?
.ok_or_eyre("there is no workspace")?
.set_name(name);
}
}
@@ -532,7 +532,7 @@ impl Monitor {
let focused_workspace_idx = self.focused_workspace_idx();
self.update_workspace_globals(focused_workspace_idx, offset);
self.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?
.ok_or_eyre("there is no workspace")?
.update()?;
Ok(())

View File

@@ -1,5 +1,5 @@
use color_eyre::eyre::anyhow;
use color_eyre::eyre::OptionExt;
use color_eyre::eyre::WrapErr;
use color_eyre::Result;
use komorebi_themes::colour::Rgb;
use miow::pipe::connect;
@@ -618,7 +618,7 @@ impl WindowManager {
for (i, monitor) in self.monitors().iter().enumerate() {
for container in monitor
.focused_workspace()
.ok_or_else(|| anyhow!("there is no workspace"))?
.ok_or_eyre("there is no workspace")?
.containers()
{
for window in container.windows() {
@@ -652,11 +652,11 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
monitor
.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no focused workspace"))?
.ok_or_eyre("there is no focused workspace")?
.remove_window(hwnd)?;
monitor.update_focused_workspace(offset)?;
@@ -665,9 +665,7 @@ impl WindowManager {
SocketMessage::FocusedWorkspaceContainerPadding(adjustment) => {
let focused_monitor_idx = self.focused_monitor_idx();
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?;
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
@@ -676,9 +674,7 @@ impl WindowManager {
SocketMessage::FocusedWorkspacePadding(adjustment) => {
let focused_monitor_idx = self.focused_monitor_idx();
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?;
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
@@ -708,7 +704,7 @@ impl WindowManager {
let idx = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut() {
@@ -718,7 +714,7 @@ impl WindowManager {
}
self.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.set_last_focused_workspace(Option::from(idx));
}
SocketMessage::SendContainerToLastWorkspace => {
@@ -739,7 +735,7 @@ impl WindowManager {
let idx = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut() {
@@ -748,16 +744,14 @@ impl WindowManager {
}
}
self.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.set_last_focused_workspace(Option::from(idx));
}
SocketMessage::MoveContainerToWorkspaceNumber(workspace_idx) => {
self.move_container_to_workspace(workspace_idx, true, None)?;
}
SocketMessage::CycleMoveContainerToWorkspace(direction) => {
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?;
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
let workspaces = focused_monitor.workspaces().len();
@@ -765,7 +759,7 @@ impl WindowManager {
let workspace_idx = direction.next_idx(
focused_workspace_idx,
NonZeroUsize::new(workspaces)
.ok_or_else(|| anyhow!("there must be at least one workspace"))?,
.ok_or_eyre("there must be at least one workspace")?,
);
self.move_container_to_workspace(workspace_idx, true, None)?;
@@ -781,7 +775,7 @@ impl WindowManager {
let monitor_idx = direction.next_idx(
self.focused_monitor_idx(),
NonZeroUsize::new(self.monitors().len())
.ok_or_else(|| anyhow!("there must be at least one monitor"))?,
.ok_or_eyre("there must be at least one monitor")?,
);
let direction = self.direction_from_monitor_idx(monitor_idx);
@@ -791,9 +785,7 @@ impl WindowManager {
self.move_container_to_workspace(workspace_idx, false, None)?;
}
SocketMessage::CycleSendContainerToWorkspace(direction) => {
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?;
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
let workspaces = focused_monitor.workspaces().len();
@@ -801,7 +793,7 @@ impl WindowManager {
let workspace_idx = direction.next_idx(
focused_workspace_idx,
NonZeroUsize::new(workspaces)
.ok_or_else(|| anyhow!("there must be at least one workspace"))?,
.ok_or_eyre("there must be at least one workspace")?,
);
self.move_container_to_workspace(workspace_idx, false, None)?;
@@ -814,7 +806,7 @@ impl WindowManager {
let monitor_idx = direction.next_idx(
self.focused_monitor_idx(),
NonZeroUsize::new(self.monitors().len())
.ok_or_else(|| anyhow!("there must be at least one monitor"))?,
.ok_or_eyre("there must be at least one monitor")?,
);
let direction = self.direction_from_monitor_idx(monitor_idx);
@@ -872,7 +864,7 @@ impl WindowManager {
let monitor_idx = direction.next_idx(
self.focused_monitor_idx(),
NonZeroUsize::new(self.monitors().len())
.ok_or_else(|| anyhow!("there must be at least one monitor"))?,
.ok_or_eyre("there must be at least one monitor")?,
);
self.move_workspace_to_monitor(monitor_idx)?;
@@ -894,7 +886,7 @@ impl WindowManager {
let monitor_idx = direction.next_idx(
self.focused_monitor_idx(),
NonZeroUsize::new(self.monitors().len())
.ok_or_else(|| anyhow!("there must be at least one monitor"))?,
.ok_or_eyre("there must be at least one monitor")?,
);
self.focus_monitor(monitor_idx)?;
@@ -1056,9 +1048,7 @@ impl WindowManager {
}
}
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?;
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
let workspaces = focused_monitor.workspaces().len();
@@ -1066,7 +1056,7 @@ impl WindowManager {
let workspace_idx = direction.next_idx(
focused_workspace_idx,
NonZeroUsize::new(workspaces)
.ok_or_else(|| anyhow!("there must be at least one workspace"))?,
.ok_or_eyre("there must be at least one workspace")?,
);
self.focus_workspace(workspace_idx)?;
@@ -1087,9 +1077,7 @@ impl WindowManager {
}
}
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?;
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
let workspaces = focused_monitor.workspaces().len();
@@ -1106,14 +1094,14 @@ impl WindowManager {
let mut workspace_idx = direction.next_idx(
focused_workspace_idx,
NonZeroUsize::new(workspaces)
.ok_or_else(|| anyhow!("there must be at least one workspace"))?,
.ok_or_eyre("there must be at least one workspace")?,
);
while !empty_workspaces.contains(&workspace_idx) {
workspace_idx = direction.next_idx(
workspace_idx,
NonZeroUsize::new(workspaces)
.ok_or_else(|| anyhow!("there must be at least one workspace"))?,
.ok_or_eyre("there must be at least one workspace")?,
);
}
@@ -1182,7 +1170,7 @@ impl WindowManager {
let idx = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut() {
@@ -1192,7 +1180,7 @@ impl WindowManager {
}
self.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.set_last_focused_workspace(Option::from(idx));
}
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
@@ -1450,7 +1438,7 @@ impl WindowManager {
StateQuery::FocusedMonitorIndex => self.focused_monitor_idx().to_string(),
StateQuery::FocusedWorkspaceIndex => self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.focused_workspace_idx()
.to_string(),
StateQuery::FocusedContainerIndex => self
@@ -1461,9 +1449,8 @@ impl WindowManager {
self.focused_container()?.focused_window_idx().to_string()
}
StateQuery::FocusedWorkspaceName => {
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?;
let focused_monitor =
self.focused_monitor().ok_or_eyre("there is no monitor")?;
focused_monitor
.focused_workspace_name()
@@ -1471,9 +1458,8 @@ impl WindowManager {
}
StateQuery::Version => build::RUST_VERSION.to_string(),
StateQuery::FocusedWorkspaceLayout => {
let focused_monitor = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?;
let focused_monitor =
self.focused_monitor().ok_or_eyre("there is no monitor")?;
focused_monitor.focused_workspace_layout().map_or_else(
|| "None".to_string(),
@@ -1921,8 +1907,10 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let quicksave_json = std::env::temp_dir().join("komorebi.quicksave.json");
let file = File::open(&quicksave_json)
.map_err(|_| anyhow!("no quicksave found at {}", quicksave_json.display()))?;
let file = File::open(&quicksave_json).wrap_err(format!(
"no quicksave found at {}",
quicksave_json.display()
))?;
let resize: Vec<Option<Rect>> = serde_json::from_reader(file)?;
@@ -1945,7 +1933,7 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let workspace = self.focused_workspace_mut()?;
let file =
File::open(path).map_err(|_| anyhow!("no file found at {}", path.display()))?;
File::open(path).wrap_err(format!("no file found at {}", path.display()))?;
let resize: Vec<Option<Rect>> = serde_json::from_reader(file)?;
@@ -1972,9 +1960,9 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
SocketMessage::AddSubscriberPipe(ref subscriber) => {
let mut pipes = SUBSCRIPTION_PIPES.lock();
let pipe_path = format!(r"\\.\pipe\{subscriber}");
let pipe = connect(&pipe_path).map_err(|_| {
anyhow!("the named pipe '{}' has not yet been created; please create it before running this command", pipe_path)
})?;
let pipe = connect(&pipe_path).wrap_err(
format!("the named pipe '{}' has not yet been created; please create it before running this command", pipe_path)
)?;
pipes.insert(subscriber.clone(), pipe);
}

View File

@@ -1,7 +1,7 @@
use std::sync::atomic::Ordering;
use std::sync::Arc;
use color_eyre::eyre::anyhow;
use color_eyre::eyre::OptionExt;
use color_eyre::Result;
use crossbeam_utils::atomic::AtomicConsume;
use parking_lot::Mutex;
@@ -477,9 +477,7 @@ impl WindowManager {
WindowContainerBehaviour::Append => {
workspace
.focused_container_mut()
.ok_or_else(|| {
anyhow!("there is no focused container")
})?
.ok_or_eyre("there is no focused container")?
.add_window(window);
workspace.set_layer(WorkspaceLayer::Tiling);
self.update_focused_workspace(true, false)?;
@@ -529,7 +527,7 @@ impl WindowManager {
let monitor_idx = self.focused_monitor_idx();
let workspace_idx = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor with this idx"))?
.ok_or_eyre("there is no monitor with this idx")?
.focused_workspace_idx();
WindowsApi::bring_window_to_top(window.hwnd)?;
@@ -559,7 +557,7 @@ impl WindowManager {
let target_monitor_idx = self
.monitor_idx_from_current_pos()
.ok_or_else(|| anyhow!("cannot get monitor idx from current position"))?;
.ok_or_eyre("cannot get monitor idx from current position")?;
let focused_monitor_idx = self.focused_monitor_idx();
let focused_workspace_idx = self.focused_workspace_idx().unwrap_or_default();
@@ -603,10 +601,10 @@ impl WindowManager {
let origin_workspace = self
.monitors()
.get(origin_monitor_idx)
.ok_or_else(|| anyhow!("cannot get monitor idx"))?
.ok_or_eyre("cannot get monitor idx")?
.workspaces()
.get(origin_workspace_idx)
.ok_or_else(|| anyhow!("cannot get workspace idx"))?;
.ok_or_eyre("cannot get workspace idx")?;
let managed_window = origin_workspace.contains_window(window.hwnd);
@@ -646,17 +644,15 @@ impl WindowManager {
let target_workspace_idx = self
.monitors()
.get(target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this idx"))?
.ok_or_eyre("there is no monitor at this idx")?
.focused_workspace_idx();
let target_container_idx = self
.monitors()
.get(target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this idx"))?
.ok_or_eyre("there is no monitor at this idx")?
.focused_workspace()
.ok_or_else(|| {
anyhow!("there is no focused workspace for this monitor")
})?
.ok_or_eyre("there is no focused workspace for this monitor")?
.container_idx_from_current_point()
// Default to 0 in the case of an empty workspace
.unwrap_or(0);
@@ -676,7 +672,7 @@ impl WindowManager {
let origin_monitor = self
.monitors_mut()
.get_mut(origin_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this idx"))?;
.ok_or_eyre("there is no monitor at this idx")?;
origin_monitor.focus_workspace(origin_workspace_idx)?;
self.update_focused_workspace(false, false)?;
@@ -684,7 +680,7 @@ impl WindowManager {
let target_monitor = self
.monitors_mut()
.get_mut(target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this idx"))?;
.ok_or_eyre("there is no monitor at this idx")?;
target_monitor.focus_workspace(target_workspace_idx)?;
self.update_focused_workspace(false, false)?;

View File

@@ -11,8 +11,8 @@ use std::path::PathBuf;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use color_eyre::eyre::anyhow;
use color_eyre::eyre::bail;
use color_eyre::eyre::OptionExt;
use color_eyre::Result;
use crossbeam_channel::Receiver;
use hotwatch::notify::ErrorKind as NotifyErrorKind;
@@ -849,7 +849,7 @@ impl WindowManager {
let focused_workspace_idx = self
.monitors()
.get(focused_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor with that index"))?
.ok_or_eyre("there is no monitor with that index")?
.focused_workspace_idx();
// scope mutex locks to avoid deadlock if should_update_focused_workspace evaluates to true
@@ -945,20 +945,20 @@ impl WindowManager {
let target_area = *self
.monitors_mut()
.get_mut(op.target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor with that index"))?
.ok_or_eyre("there is no monitor with that index")?
.work_area_size();
let origin_monitor = self
.monitors_mut()
.get_mut(op.origin_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor with that index"))?;
.ok_or_eyre("there is no monitor with that index")?;
let origin_area = *origin_monitor.work_area_size();
let origin_workspace = origin_monitor
.workspaces_mut()
.get_mut(op.origin_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace with that index"))?;
.ok_or_eyre("there is no workspace with that index")?;
let mut window = Window::from(op.hwnd);
@@ -982,7 +982,7 @@ impl WindowManager {
let target_monitor = self
.monitors_mut()
.get_mut(op.target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor with that index"))?;
.ok_or_eyre("there is no monitor with that index")?;
// The very first time this fn is called, the workspace might not even exist yet
if target_monitor
@@ -997,7 +997,7 @@ impl WindowManager {
let target_workspace = target_monitor
.workspaces_mut()
.get_mut(op.target_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace with that index"))?;
.ok_or_eyre("there is no workspace with that index")?;
if op.floating {
target_workspace
@@ -1042,7 +1042,7 @@ impl WindowManager {
let monitor_wp = monitor.wallpaper.clone();
let workspace = monitor
.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?;
.ok_or_eyre("there is no workspace")?;
// Reset any resize adjustments if we want to force a retile
if !preserve_resize_dimensions {
@@ -1155,10 +1155,10 @@ impl WindowManager {
let origin_workspace = self
.monitors_mut()
.get_mut(origin_monitor_idx)
.ok_or_else(|| anyhow!("cannot get monitor idx"))?
.ok_or_eyre("cannot get monitor idx")?
.workspaces_mut()
.get_mut(origin_workspace_idx)
.ok_or_else(|| anyhow!("cannot get workspace idx"))?;
.ok_or_eyre("cannot get workspace idx")?;
let origin_container_idx = origin_workspace
.container_for_window(w_hwnd)
@@ -1191,9 +1191,9 @@ impl WindowManager {
let target_workspace = self
.monitors_mut()
.get_mut(target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this idx"))?
.ok_or_eyre("there is no monitor at this idx")?
.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no focused workspace for this monitor"))?;
.ok_or_eyre("there is no focused workspace for this monitor")?;
target_workspace
.floating_windows_mut()
@@ -1210,10 +1210,10 @@ impl WindowManager {
let origin_workspace = self
.monitors_mut()
.get_mut(origin_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this idx"))?
.ok_or_eyre("there is no monitor at this idx")?
.workspaces_mut()
.get_mut(origin_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace for this monitor"))?;
.ok_or_eyre("there is no workspace for this monitor")?;
let mut uncloack_amount = 0;
for container in origin_workspace.containers_mut() {
container.restore();
@@ -1248,13 +1248,13 @@ impl WindowManager {
self.focus_monitor(origin_monitor_idx)?;
let origin_monitor = self
.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no origin monitor"))?;
.ok_or_eyre("there is no origin monitor")?;
origin_monitor.focus_workspace(origin_workspace_idx)?;
self.unmaximize_window()?;
self.focus_monitor(target_monitor_idx)?;
let target_monitor = self
.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no target monitor"))?;
.ok_or_eyre("there is no target monitor")?;
target_monitor.focus_workspace(target_workspace_idx)?;
self.transfer_container(
@@ -1282,20 +1282,20 @@ impl WindowManager {
let origin_container = self
.monitors_mut()
.get_mut(origin_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.workspaces_mut()
.get_mut(origin_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace at this index"))?
.ok_or_eyre("there is no workspace at this index")?
.remove_container(origin_container_idx)
.ok_or_else(|| anyhow!("there is no container at this index"))?;
.ok_or_eyre("there is no container at this index")?;
let target_workspace = self
.monitors_mut()
.get_mut(target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.workspaces_mut()
.get_mut(target_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace at this index"))?;
.ok_or_eyre("there is no workspace at this index")?;
target_workspace
.containers_mut()
@@ -1318,10 +1318,10 @@ impl WindowManager {
let origin_container_is_valid = self
.monitors_mut()
.get_mut(origin_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.workspaces_mut()
.get_mut(origin_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace at this index"))?
.ok_or_eyre("there is no workspace at this index")?
.containers()
.get(origin_container_idx)
.is_some();
@@ -1329,10 +1329,10 @@ impl WindowManager {
let target_container_is_valid = self
.monitors_mut()
.get_mut(target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.workspaces_mut()
.get_mut(target_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace at this index"))?
.ok_or_eyre("there is no workspace at this index")?
.containers()
.get(origin_container_idx)
.is_some();
@@ -1341,38 +1341,38 @@ impl WindowManager {
let origin_container = self
.monitors_mut()
.get_mut(origin_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.workspaces_mut()
.get_mut(origin_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace at this index"))?
.ok_or_eyre("there is no workspace at this index")?
.remove_container(origin_container_idx)
.ok_or_else(|| anyhow!("there is no container at this index"))?;
.ok_or_eyre("there is no container at this index")?;
let target_container = self
.monitors_mut()
.get_mut(target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.workspaces_mut()
.get_mut(target_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace at this index"))?
.ok_or_eyre("there is no workspace at this index")?
.remove_container(target_container_idx);
self.monitors_mut()
.get_mut(target_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.workspaces_mut()
.get_mut(target_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace at this index"))?
.ok_or_eyre("there is no workspace at this index")?
.containers_mut()
.insert(target_container_idx, origin_container);
if let Some(target_container) = target_container {
self.monitors_mut()
.get_mut(origin_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.workspaces_mut()
.get_mut(origin_workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace at this index"))?
.ok_or_eyre("there is no workspace at this index")?
.containers_mut()
.insert(origin_container_idx, target_container);
}
@@ -1392,7 +1392,7 @@ impl WindowManager {
let offset = self.work_area_offset;
self.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.update_focused_workspace(offset)?;
if follow_focus {
@@ -1556,14 +1556,12 @@ impl WindowManager {
Layout::Default(layout) => {
tracing::info!("resizing window");
let len = NonZeroUsize::new(workspace.containers().len())
.ok_or_else(|| anyhow!("there must be at least one container"))?;
.ok_or_eyre("there must be at least one container")?;
let focused_idx = workspace.focused_container_idx();
let focused_idx_resize = workspace
.resize_dimensions()
.get(focused_idx)
.ok_or_else(|| {
anyhow!("there is no resize adjustment for this container")
})?;
.ok_or_eyre("there is no resize adjustment for this container")?;
if direction
.destination(
@@ -1612,7 +1610,7 @@ impl WindowManager {
let resize = layout.resize(
unaltered
.get(focused_idx)
.ok_or_else(|| anyhow!("there is no last layout"))?,
.ok_or_eyre("there is no last layout")?,
focused_idx_resize,
direction,
sizing,
@@ -1778,7 +1776,7 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let hmonitor = monitor.id();
let monitor_wp = monitor.wallpaper.clone();
@@ -1786,7 +1784,7 @@ impl WindowManager {
let workspace = monitor
.workspaces()
.get(workspace_idx)
.ok_or_else(|| anyhow!("there is no workspace"))?;
.ok_or_eyre("there is no workspace")?;
workspace.apply_wallpaper(hmonitor, &monitor_wp)
}
@@ -1796,7 +1794,7 @@ impl WindowManager {
self.monitors_mut()
.get_mut(idx)
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.update_focused_workspace(offset)
}
@@ -1812,7 +1810,7 @@ impl WindowManager {
let first_monitor = self
.monitors()
.get(first_idx)
.ok_or_else(|| anyhow!("There is no monitor"))?;
.ok_or_eyre("There is no monitor")?;
first_monitor.focused_workspace_idx()
};
@@ -1820,7 +1818,7 @@ impl WindowManager {
let second_monitor = self
.monitors()
.get(second_idx)
.ok_or_else(|| anyhow!("There is no monitor"))?;
.ok_or_eyre("There is no monitor")?;
second_monitor.focused_workspace_idx()
};
@@ -1829,24 +1827,24 @@ impl WindowManager {
let first_workspaces = self
.monitors_mut()
.get_mut(first_idx)
.ok_or_else(|| anyhow!("There is no monitor"))?
.ok_or_eyre("There is no monitor")?
.remove_workspaces();
let second_workspaces = self
.monitors_mut()
.get_mut(second_idx)
.ok_or_else(|| anyhow!("There is no monitor"))?
.ok_or_eyre("There is no monitor")?
.remove_workspaces();
self.monitors_mut()
.get_mut(first_idx)
.ok_or_else(|| anyhow!("There is no monitor"))?
.ok_or_eyre("There is no monitor")?
.workspaces_mut()
.extend(second_workspaces);
self.monitors_mut()
.get_mut(second_idx)
.ok_or_else(|| anyhow!("There is no monitor"))?
.ok_or_eyre("There is no monitor")?
.workspaces_mut()
.extend(first_workspaces);
@@ -1904,13 +1902,13 @@ impl WindowManager {
let monitor = self
.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let current_area = *monitor.work_area_size();
let workspace = monitor
.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?;
.ok_or_eyre("there is no workspace")?;
if workspace.maximized_window().is_some() {
bail!("cannot move native maximized window to another monitor or workspace");
@@ -1928,7 +1926,7 @@ impl WindowManager {
Some(
workspace
.remove_focused_container()
.ok_or_else(|| anyhow!("there is no container"))?,
.ok_or_eyre("there is no container")?,
)
} else {
None
@@ -1938,7 +1936,7 @@ impl WindowManager {
let target_monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let mut should_load_workspace = false;
if let Some(workspace_idx) = workspace_idx {
@@ -1949,7 +1947,7 @@ impl WindowManager {
}
let target_workspace = target_monitor
.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no focused workspace on target monitor"))?;
.ok_or_eyre("there is no focused workspace on target monitor")?;
if target_workspace.monocle_container().is_some() {
for container in target_workspace.containers_mut() {
@@ -2028,7 +2026,7 @@ impl WindowManager {
let mouse_follows_focus = self.mouse_follows_focus;
let monitor = self
.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
monitor.move_container_to_workspace(idx, follow, direction)?;
monitor.load_focused_workspace(mouse_follows_focus)?;
@@ -2059,13 +2057,13 @@ impl WindowManager {
let offset = self.work_area_offset;
let workspace = self
.remove_focused_workspace()
.ok_or_else(|| anyhow!("there is no workspace"))?;
.ok_or_eyre("there is no workspace")?;
{
let target_monitor: &mut Monitor = self
.monitors_mut()
.get_mut(idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
target_monitor.workspaces_mut().push_back(workspace);
target_monitor.update_workspaces_globals(offset);
@@ -2263,7 +2261,7 @@ impl WindowManager {
// if there is no floating_window in that direction for this workspace
let monitor_idx = self
.monitor_idx_in_direction(direction)
.ok_or_else(|| anyhow!("there is no container or monitor in this direction"))?;
.ok_or_eyre("there is no container or monitor in this direction")?;
self.focus_monitor(monitor_idx)?;
let mouse_follows_focus = self.mouse_follows_focus;
@@ -2420,7 +2418,7 @@ impl WindowManager {
None => {
let monitor_idx = self
.monitor_idx_in_direction(direction)
.ok_or_else(|| anyhow!("there is no container or monitor in this direction"))?;
.ok_or_eyre("there is no container or monitor in this direction")?;
self.focus_monitor(monitor_idx)?;
let mouse_follows_focus = self.mouse_follows_focus;
@@ -2640,7 +2638,7 @@ impl WindowManager {
let target_monitor_idx = self
.monitor_idx_in_direction(direction)
.ok_or_else(|| anyhow!("there is no container or monitor in this direction"))?;
.ok_or_eyre("there is no container or monitor in this direction")?;
{
// actually move the container to target monitor using the direction
@@ -2699,9 +2697,7 @@ impl WindowManager {
.remove_container_by_idx(
target_workspace.focused_container_idx() + 1,
)
.ok_or_else(|| {
anyhow!("could not remove container at given target index")
})?;
.ok_or_eyre("could not remove container at given target index")?;
let origin_workspace =
self.focused_workspace_for_monitor_idx_mut(origin_monitor_idx)?;
@@ -2720,17 +2716,17 @@ impl WindowManager {
self.monitors_mut()
.get_mut(origin_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.update_focused_workspace(offset)?;
let a = self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor focused monitor"))?
.ok_or_eyre("there is no monitor focused monitor")?
.id();
let b = self
.monitors_mut()
.get_mut(origin_monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.id();
if !WindowsApi::monitors_have_same_dpi(a, b)? {
@@ -2819,7 +2815,7 @@ impl WindowManager {
let new_idx = workspace
.new_idx_for_cycle_direction(direction)
.ok_or_else(|| anyhow!("this is not a valid direction from the current position"))?;
.ok_or_eyre("this is not a valid direction from the current position")?;
workspace.focus_container(new_idx);
@@ -2848,7 +2844,7 @@ impl WindowManager {
let current_idx = workspace.focused_container_idx();
let new_idx = workspace
.new_idx_for_cycle_direction(direction)
.ok_or_else(|| anyhow!("this is not a valid direction from the current position"))?;
.ok_or_eyre("this is not a valid direction from the current position")?;
workspace.swap_containers(current_idx, new_idx);
workspace.focus_container(new_idx);
@@ -2869,7 +2865,7 @@ impl WindowManager {
};
let len = NonZeroUsize::new(container.windows().len())
.ok_or_else(|| anyhow!("there must be at least one window in a container"))?;
.ok_or_eyre("there must be at least one window in a container")?;
if len.get() == 1 {
bail!("there is only one window in this container");
@@ -2905,7 +2901,7 @@ impl WindowManager {
};
let len = NonZeroUsize::new(container.windows().len())
.ok_or_else(|| anyhow!("there must be at least one window in a container"))?;
.ok_or_eyre("there must be at least one window in a container")?;
if len.get() == 1 {
bail!("there is only one window in this container");
@@ -2938,7 +2934,7 @@ impl WindowManager {
};
let len = NonZeroUsize::new(container.windows().len())
.ok_or_else(|| anyhow!("there must be at least one window in a container"))?;
.ok_or_eyre("there must be at least one window in a container")?;
if len.get() == 1 && idx != 0 {
bail!("there is only one window in this container");
@@ -3033,7 +3029,7 @@ impl WindowManager {
let workspace = self.focused_workspace_mut()?;
let len = NonZeroUsize::new(workspace.containers_mut().len())
.ok_or_else(|| anyhow!("there must be at least one container"))?;
.ok_or_eyre("there must be at least one container")?;
let current_container_idx = workspace.focused_container_idx();
let is_valid = direction
@@ -3046,9 +3042,9 @@ impl WindowManager {
.is_some();
if is_valid {
let new_idx = workspace.new_idx_for_direction(direction).ok_or_else(|| {
anyhow!("this is not a valid direction from the current position")
})?;
let new_idx = workspace
.new_idx_for_direction(direction)
.ok_or_eyre("this is not a valid direction from the current position")?;
let mut changed_focus = false;
@@ -3213,7 +3209,7 @@ impl WindowManager {
let window = workspace
.floating_windows_mut()
.back_mut()
.ok_or_else(|| anyhow!("there is no floating window"))?;
.ok_or_eyre("there is no floating window")?;
if toggle_float_placement.should_center() {
window.center(&work_area, toggle_float_placement.should_resize())?;
@@ -3371,10 +3367,11 @@ impl WindowManager {
match workspace.layout() {
Layout::Default(_) => {}
Layout::Custom(layout) => {
let primary_idx =
layout.first_container_idx(layout.primary_idx().ok_or_else(|| {
anyhow!("this custom layout does not have a primary column")
})?);
let primary_idx = layout.first_container_idx(
layout
.primary_idx()
.ok_or_eyre("this custom layout does not have a primary column")?,
);
if !workspace.containers().is_empty() && primary_idx < workspace.containers().len()
{
@@ -3422,10 +3419,11 @@ impl WindowManager {
match workspace.layout() {
Layout::Default(_) => {
let primary_idx =
layout.first_container_idx(layout.primary_idx().ok_or_else(|| {
anyhow!("this custom layout does not have a primary column")
})?);
let primary_idx = layout.first_container_idx(
layout
.primary_idx()
.ok_or_eyre("this custom layout does not have a primary column")?,
);
if !workspace.containers().is_empty() && primary_idx < workspace.containers().len()
{
@@ -3448,7 +3446,7 @@ impl WindowManager {
let padding = workspace
.workspace_padding()
.ok_or_else(|| anyhow!("there is no workspace padding"))?;
.ok_or_eyre("there is no workspace padding")?;
workspace.set_workspace_padding(Option::from(sizing.adjust_by(padding, adjustment)));
@@ -3463,7 +3461,7 @@ impl WindowManager {
let padding = workspace
.container_padding()
.ok_or_else(|| anyhow!("there is no container padding"))?;
.ok_or_eyre("there is no container padding")?;
workspace.set_container_padding(Option::from(sizing.adjust_by(padding, adjustment)));
@@ -3480,12 +3478,12 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
workspace.set_tile(tile);
@@ -3507,14 +3505,14 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = monitor.focused_workspace_idx();
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let rules: &mut Vec<(usize, Layout)> = workspace.layout_rules_mut();
rules.retain(|pair| pair.0 != at_container_count);
@@ -3548,14 +3546,14 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = monitor.focused_workspace_idx();
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let layout = CustomLayout::from_path(path)?;
@@ -3586,14 +3584,14 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = monitor.focused_workspace_idx();
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let rules: &mut Vec<(usize, Layout)> = workspace.layout_rules_mut();
rules.clear();
@@ -3621,14 +3619,14 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = monitor.focused_workspace_idx();
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
workspace.set_layout(Layout::Default(layout));
@@ -3658,14 +3656,14 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let focused_workspace_idx = monitor.focused_workspace_idx();
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
workspace.set_layout(Layout::Custom(layout));
workspace.set_layout_flip(None);
@@ -3690,7 +3688,7 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
monitor.ensure_workspace_count(workspace_count);
@@ -3708,7 +3706,7 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
monitor.ensure_workspace_count(names.len());
@@ -3733,12 +3731,12 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
workspace.set_workspace_padding(Option::from(size));
@@ -3757,12 +3755,12 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
workspace.set_name(Option::from(name.clone()));
monitor.workspace_names_mut().insert(workspace_idx, name);
@@ -3782,12 +3780,12 @@ impl WindowManager {
let monitor = self
.monitors_mut()
.get_mut(monitor_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
let workspace = monitor
.workspaces_mut()
.get_mut(workspace_idx)
.ok_or_else(|| anyhow!("there is no monitor"))?;
.ok_or_eyre("there is no monitor")?;
workspace.set_container_padding(Option::from(size));
@@ -3797,14 +3795,14 @@ impl WindowManager {
pub fn focused_monitor_size(&self) -> Result<Rect> {
Ok(*self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.size())
}
pub fn focused_monitor_work_area(&self) -> Result<Rect> {
Ok(*self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.work_area_size())
}
@@ -3870,46 +3868,46 @@ impl WindowManager {
pub fn focused_workspace_idx(&self) -> Result<usize> {
Ok(self
.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.focused_workspace_idx())
}
pub fn focused_workspace(&self) -> Result<&Workspace> {
self.focused_monitor()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.focused_workspace()
.ok_or_else(|| anyhow!("there is no workspace"))
.ok_or_eyre("there is no workspace")
}
pub fn focused_workspace_mut(&mut self) -> Result<&mut Workspace> {
self.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no monitor"))?
.ok_or_eyre("there is no monitor")?
.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))
.ok_or_eyre("there is no workspace")
}
pub fn focused_workspace_idx_for_monitor_idx(&self, idx: usize) -> Result<usize> {
Ok(self
.monitors()
.get(idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.focused_workspace_idx())
}
pub fn focused_workspace_for_monitor_idx(&self, idx: usize) -> Result<&Workspace> {
self.monitors()
.get(idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.focused_workspace()
.ok_or_else(|| anyhow!("there is no workspace"))
.ok_or_eyre("there is no workspace")
}
pub fn focused_workspace_for_monitor_idx_mut(&mut self, idx: usize) -> Result<&mut Workspace> {
self.monitors_mut()
.get_mut(idx)
.ok_or_else(|| anyhow!("there is no monitor at this index"))?
.ok_or_eyre("there is no monitor at this index")?
.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))
.ok_or_eyre("there is no workspace")
}
#[tracing::instrument(skip(self))]
@@ -3919,7 +3917,7 @@ impl WindowManager {
let mouse_follows_focus = self.mouse_follows_focus;
let monitor = self
.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?;
.ok_or_eyre("there is no workspace")?;
monitor.focus_workspace(idx)?;
monitor.load_focused_workspace(mouse_follows_focus)?;
@@ -3951,7 +3949,7 @@ impl WindowManager {
let mouse_follows_focus = self.mouse_follows_focus;
let monitor = self
.focused_monitor_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?;
.ok_or_eyre("there is no workspace")?;
monitor.focus_workspace(monitor.new_workspace_idx())?;
monitor.load_focused_workspace(mouse_follows_focus)?;
@@ -3962,7 +3960,7 @@ impl WindowManager {
pub fn focused_container(&self) -> Result<&Container> {
self.focused_workspace()?
.focused_container()
.ok_or_else(|| anyhow!("there is no container"))
.ok_or_eyre("there is no container")
}
pub fn focused_container_idx(&self) -> Result<usize> {
@@ -3972,19 +3970,19 @@ impl WindowManager {
pub fn focused_container_mut(&mut self) -> Result<&mut Container> {
self.focused_workspace_mut()?
.focused_container_mut()
.ok_or_else(|| anyhow!("there is no container"))
.ok_or_eyre("there is no container")
}
pub fn focused_window(&self) -> Result<&Window> {
self.focused_container()?
.focused_window()
.ok_or_else(|| anyhow!("there is no window"))
.ok_or_eyre("there is no window")
}
fn focused_window_mut(&mut self) -> Result<&mut Window> {
self.focused_container_mut()?
.focused_window_mut()
.ok_or_else(|| anyhow!("there is no window"))
.ok_or_eyre("there is no window")
}
/// Updates the list of `known_hwnds` and their monitor/workspace index pair

View File

@@ -1,6 +1,6 @@
use color_eyre::eyre::anyhow;
use color_eyre::eyre::bail;
use color_eyre::eyre::Error;
use color_eyre::eyre::OptionExt;
use color_eyre::Result;
use core::ffi::c_void;
use std::collections::HashMap;
@@ -663,10 +663,11 @@ impl WindowsApi {
}
pub fn close_window(hwnd: isize) -> Result<()> {
match Self::post_message(HWND(as_ptr!(hwnd)), WM_CLOSE, WPARAM(0), LPARAM(0)) {
Ok(()) => Ok(()),
Err(_) => Err(anyhow!("could not close window")),
if Self::post_message(HWND(as_ptr!(hwnd)), WM_CLOSE, WPARAM(0), LPARAM(0)).is_err() {
bail!("could not close window");
}
Ok(())
}
pub fn hide_window(hwnd: isize) {
@@ -753,7 +754,7 @@ impl WindowsApi {
next_hwnd = Self::next_window(next_hwnd)?;
}
Err(anyhow!("could not find next window"))
bail!("could not find next window")
}
pub fn window_rect(hwnd: isize) -> Result<Rect> {
@@ -857,12 +858,12 @@ impl WindowsApi {
let mut session_id = 0;
unsafe {
if ProcessIdToSessionId(process_id, &mut session_id).is_ok() {
Ok(session_id)
} else {
Err(anyhow!("could not determine current session id"))
if ProcessIdToSessionId(process_id, &mut session_id).is_err() {
bail!("could not determine current session id")
}
}
Ok(session_id)
}
#[cfg(target_pointer_width = "64")]
@@ -991,7 +992,7 @@ impl WindowsApi {
Ok(Self::exe_path(handle)?
.split('\\')
.next_back()
.ok_or_else(|| anyhow!("there is no last element"))?
.ok_or_eyre("there is no last element")?
.to_string())
}

View File

@@ -37,7 +37,7 @@ use crate::INITIAL_CONFIGURATION_LOADED;
use crate::NO_TITLEBAR;
use crate::REGEX_IDENTIFIERS;
use crate::REMOVE_TITLEBARS;
use color_eyre::eyre::anyhow;
use color_eyre::eyre::OptionExt;
use color_eyre::Result;
use getset::CopyGetters;
use getset::Getters;
@@ -579,11 +579,9 @@ impl Workspace {
} else if !self.containers().is_empty() {
let mut layouts = self.layout().as_boxed_arrangement().calculate(
&adjusted_work_area,
NonZeroUsize::new(self.containers().len()).ok_or_else(|| {
anyhow!(
"there must be at least one container to calculate a workspace layout"
)
})?,
NonZeroUsize::new(self.containers().len()).ok_or_eyre(
"there must be at least one container to calculate a workspace layout",
)?,
Some(container_padding),
self.layout_flip(),
self.resize_dimensions(),
@@ -677,16 +675,16 @@ impl Workspace {
pub fn focus_container_by_window(&mut self, hwnd: isize) -> Result<()> {
let container_idx = self
.container_idx_for_window(hwnd)
.ok_or_else(|| anyhow!("there is no container/window"))?;
.ok_or_eyre("there is no container/window")?;
let container = self
.containers_mut()
.get_mut(container_idx)
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
let window_idx = container
.idx_for_window(hwnd)
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
let mut should_load = false;
@@ -866,14 +864,14 @@ impl Workspace {
let resize = self.resize_dimensions_mut().remove(0);
let container = self
.remove_focused_container()
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
let primary_idx = match self.layout() {
Layout::Default(_) => 0,
Layout::Custom(layout) => layout.first_container_idx(
layout
.primary_idx()
.ok_or_else(|| anyhow!("this custom layout does not have a primary column"))?,
.ok_or_eyre("this custom layout does not have a primary column")?,
),
};
@@ -951,7 +949,7 @@ impl Workspace {
{
container
.remove_window_by_idx(window_idx)
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
if container.windows().is_empty() {
self.set_monocle_container(None);
@@ -977,22 +975,22 @@ impl Workspace {
let container_idx = self
.container_idx_for_window(hwnd)
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
let container = self
.containers_mut()
.get_mut(container_idx)
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
let window_idx = container
.windows()
.iter()
.position(|window| window.hwnd == hwnd)
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
container
.remove_window_by_idx(window_idx)
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
if container.windows().is_empty() {
self.remove_container_by_idx(container_idx);
@@ -1046,11 +1044,11 @@ impl Workspace {
let container = self
.focused_container_mut()
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
let window = container
.remove_focused_window()
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
// This is a little messy
let adjusted_target_container_index = if container.windows().is_empty() {
@@ -1069,13 +1067,13 @@ impl Workspace {
let target_container = self
.containers_mut()
.get_mut(adjusted_target_container_index)
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
target_container.add_window(window);
self.focus_container(adjusted_target_container_index);
self.focused_container_mut()
.ok_or_else(|| anyhow!("there is no container"))?
.ok_or_eyre("there is no container")?
.load_focused_window();
Ok(())
@@ -1086,11 +1084,11 @@ impl Workspace {
let container = self
.focused_container_mut()
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
let window = container
.remove_focused_window()
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
if container.windows().is_empty() {
self.remove_container_by_idx(focused_container_idx);
@@ -1109,7 +1107,7 @@ impl Workspace {
let focused_idx = self.focused_container_idx();
let window = self
.remove_focused_floating_window()
.ok_or_else(|| anyhow!("there is no floating window"))?;
.ok_or_eyre("there is no floating window")?;
let mut container = Container::default();
container.add_window(window);
@@ -1141,7 +1139,7 @@ impl Workspace {
} else if let Some(monocle_container) = self.monocle_container_mut() {
let window = monocle_container
.remove_focused_window()
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
if monocle_container.windows().is_empty() {
self.set_monocle_container(None);
@@ -1156,11 +1154,11 @@ impl Workspace {
let container = self
.focused_container_mut()
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
let window = container
.remove_focused_window()
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
if container.windows().is_empty() {
self.remove_container_by_idx(focused_idx);
@@ -1467,7 +1465,7 @@ impl Workspace {
let container = self
.containers_mut()
.remove(focused_idx)
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
// We don't remove any resize adjustments for a monocle, because when this container is
// inevitably reintegrated, it would be weird if it doesn't go back to the dimensions
@@ -1479,7 +1477,7 @@ impl Workspace {
self.monocle_container_mut()
.as_mut()
.ok_or_else(|| anyhow!("there is no monocle container"))?
.ok_or_eyre("there is no monocle container")?
.load_focused_window();
Ok(())
@@ -1488,12 +1486,12 @@ impl Workspace {
pub fn reintegrate_monocle_container(&mut self) -> Result<()> {
let restore_idx = self
.monocle_container_restore_idx()
.ok_or_else(|| anyhow!("there is no monocle restore index"))?;
.ok_or_eyre("there is no monocle restore index")?;
let container = self
.monocle_container_mut()
.as_ref()
.ok_or_else(|| anyhow!("there is no monocle container"))?;
.ok_or_eyre("there is no monocle container")?;
let container = container.clone();
if restore_idx >= self.containers().len() {
@@ -1507,7 +1505,7 @@ impl Workspace {
self.containers_mut().insert(restore_idx, container);
self.focus_container(restore_idx);
self.focused_container_mut()
.ok_or_else(|| anyhow!("there is no container"))?
.ok_or_eyre("there is no container")?
.load_focused_window();
self.set_monocle_container(None);
@@ -1535,7 +1533,7 @@ impl Workspace {
if let Some(monocle_container) = self.monocle_container_mut() {
let window = monocle_container
.remove_focused_window()
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
if monocle_container.windows().is_empty() {
self.set_monocle_container(None);
@@ -1555,11 +1553,11 @@ impl Workspace {
let container = self
.focused_container_mut()
.ok_or_else(|| anyhow!("there is no container"))?;
.ok_or_eyre("there is no container")?;
let window = container
.remove_focused_window()
.ok_or_else(|| anyhow!("there is no window"))?;
.ok_or_eyre("there is no window")?;
if container.windows().is_empty() {
// we shouldn't use remove_container_by_idx here because it doesn't make sense for
@@ -1588,12 +1586,12 @@ impl Workspace {
pub fn reintegrate_maximized_window(&mut self) -> Result<()> {
let restore_idx = self
.maximized_window_restore_idx()
.ok_or_else(|| anyhow!("there is no monocle restore index"))?;
.ok_or_eyre("there is no monocle restore index")?;
let window = self
.maximized_window()
.as_ref()
.ok_or_else(|| anyhow!("there is no monocle container"))?;
.ok_or_eyre("there is no monocle container")?;
let window = *window;
if !self.containers().is_empty() && restore_idx > self.containers().len().saturating_sub(1)
@@ -1612,7 +1610,7 @@ impl Workspace {
self.focus_container(restore_idx);
self.focused_container_mut()
.ok_or_else(|| anyhow!("there is no container"))?
.ok_or_eyre("there is no container")?
.load_focused_window();
self.set_maximized_window(None);

View File

@@ -20,8 +20,8 @@ use std::time::Duration;
use clap::CommandFactory;
use clap::Parser;
use clap::ValueEnum;
use color_eyre::eyre::anyhow;
use color_eyre::eyre::bail;
use color_eyre::eyre::OptionExt;
use color_eyre::Result;
use dirs::data_local_dir;
use fs_tail::TailedFile;
@@ -2181,25 +2181,26 @@ fn main() -> Result<()> {
let mut buf: PathBuf;
// The komorebi.ps1 shim will only exist in the Path if installed by Scoop
let exec = if let Ok(output) = Command::new("where.exe").arg("komorebi.ps1").output() {
let stdout = String::from_utf8(output.stdout)?;
match stdout.trim() {
"" => None,
// It's possible that a komorebi.ps1 config will be in %USERPROFILE% - ignore this
stdout if !stdout.contains("scoop") => None,
stdout => {
buf = PathBuf::from(stdout);
buf.pop(); // %USERPROFILE%\scoop\shims
buf.pop(); // %USERPROFILE%\scoop
buf.push("apps\\komorebi\\current\\komorebi.exe"); //%USERPROFILE%\scoop\komorebi\current\komorebi.exe
Some(buf.to_str().ok_or_else(|| {
anyhow!("cannot create a string from the scoop komorebi path")
})?)
let exec =
if let Ok(output) = Command::new("where.exe").arg("komorebi.ps1").output() {
let stdout = String::from_utf8(output.stdout)?;
match stdout.trim() {
"" => None,
// It's possible that a komorebi.ps1 config will be in %USERPROFILE% - ignore this
stdout if !stdout.contains("scoop") => None,
stdout => {
buf = PathBuf::from(stdout);
buf.pop(); // %USERPROFILE%\scoop\shims
buf.pop(); // %USERPROFILE%\scoop
buf.push("apps\\komorebi\\current\\komorebi.exe"); //%USERPROFILE%\scoop\komorebi\current\komorebi.exe
Some(buf.to_str().ok_or_eyre(
"cannot create a string from the scoop komorebi path",
)?)
}
}
}
} else {
None
};
} else {
None
};
let mut flags = vec![];
if let Some(config) = &arg.config {