mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-22 00:21:43 +01:00
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:
1 parent
63d3b4e33a
commit
b7ce8c03b5
6 files changed
+127
-142
No files matched your search
@@ -1,6 +1,7 @@
|
||||
export RUST_BACKTRACE := "full"
|
||||
|
||||
fmt:
|
||||
test -z "$(rg 'eyre!' --type rust)" || (echo "eyre! macro not allowed"; false)
|
||||
cargo +nightly fmt
|
||||
cargo +stable clippy
|
||||
prettier --write README.md
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![warn(clippy::all)]
|
||||
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use komorebi::DATA_DIR;
|
||||
use komorebi::ax_event_listener;
|
||||
use komorebi::process_command::listen_for_commands;
|
||||
@@ -102,7 +102,7 @@ fn main() -> eyre::Result<()> {
|
||||
let display_size = unsafe { CGDisplayBounds(CGMainDisplayID()) };
|
||||
tracing::info!("display size for main display is: {:?}", display_size);
|
||||
|
||||
let run_loop = CFRunLoop::current().ok_or(eyre!("couldn't get CFRunLoop::current"))?;
|
||||
let run_loop = CFRunLoop::current().ok_or_eyre("couldn't get CFRunLoop::current")?;
|
||||
let wm = Arc::new(Mutex::new(WindowManager::new(
|
||||
&run_loop,
|
||||
ax_event_listener::event_rx(),
|
||||
|
||||
+12
-12
@@ -12,7 +12,7 @@ use crate::workspace::Workspace;
|
||||
use crate::workspace::WorkspaceGlobals;
|
||||
use crate::workspace::WorkspaceLayer;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
@@ -69,7 +69,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(|| eyre!("there is no workspace"))?
|
||||
.ok_or_eyre("there is no workspace")?
|
||||
.update()?;
|
||||
|
||||
Ok(())
|
||||
@@ -144,14 +144,14 @@ impl Monitor {
|
||||
) -> eyre::Result<()> {
|
||||
let workspace = self
|
||||
.focused_workspace_mut()
|
||||
.ok_or_else(|| eyre!("there is no workspace"))?;
|
||||
.ok_or_eyre("there is no workspace")?;
|
||||
|
||||
// if workspace.maximized_window().is_some() {
|
||||
// return Err(eyre!("cannot move native maximized window to another monitor or workspace"));
|
||||
// eyre::bail!("cannot move native maximized window to another monitor or workspace");
|
||||
// }
|
||||
|
||||
let foreground_hwnd =
|
||||
MacosApi::foreground_window_id().ok_or(eyre!("no foreground window"))?;
|
||||
MacosApi::foreground_window_id().ok_or_eyre("no foreground window")?;
|
||||
let floating_window_index = workspace
|
||||
.floating_windows()
|
||||
.iter()
|
||||
@@ -175,7 +175,7 @@ impl Monitor {
|
||||
} else {
|
||||
let container = workspace
|
||||
.remove_focused_container()
|
||||
.ok_or_else(|| eyre!("there is no container"))?;
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
let workspaces = self.workspaces_mut();
|
||||
|
||||
@@ -229,11 +229,11 @@ impl Monitor {
|
||||
) -> eyre::Result<()> {
|
||||
let workspace = self
|
||||
.focused_workspace_mut()
|
||||
.ok_or_else(|| eyre!("there is no workspace"))?;
|
||||
.ok_or_eyre("there is no workspace")?;
|
||||
|
||||
let container = workspace
|
||||
.remove_focused_container()
|
||||
.ok_or_else(|| eyre!("there is no container"))?;
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
let workspaces = self.workspaces_mut();
|
||||
|
||||
@@ -280,10 +280,10 @@ impl Monitor {
|
||||
let workspace = if let Some(idx) = workspace_idx {
|
||||
self.workspaces_mut()
|
||||
.get_mut(idx)
|
||||
.ok_or_else(|| eyre!("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(|| eyre!("there is no workspace"))?
|
||||
.ok_or_eyre("there is no workspace")?
|
||||
};
|
||||
|
||||
match direction {
|
||||
@@ -392,10 +392,10 @@ impl Monitor {
|
||||
let workspace = if let Some(idx) = workspace_idx {
|
||||
self.workspaces_mut()
|
||||
.get_mut(idx)
|
||||
.ok_or_else(|| eyre!("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(|| eyre!("there is no workspace"))?
|
||||
.ok_or_eyre("there is no workspace")?
|
||||
};
|
||||
|
||||
workspace.add_container_to_back(container);
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::window_manager::WindowManager;
|
||||
use crate::workspace::Workspace;
|
||||
use crate::workspace::WorkspaceLayer;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use parking_lot::Mutex;
|
||||
use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
@@ -151,7 +151,7 @@ impl WindowManager {
|
||||
let monitor_idx = direction.next_idx(
|
||||
self.focused_monitor_idx(),
|
||||
NonZeroUsize::new(self.monitors().len())
|
||||
.ok_or_else(|| eyre!("there must be at least one monitor"))?,
|
||||
.ok_or_eyre("there must be at least one monitor")?,
|
||||
);
|
||||
|
||||
self.focus_monitor(monitor_idx)?;
|
||||
@@ -170,9 +170,7 @@ impl WindowManager {
|
||||
self.focus_monitor(monitor_idx)?;
|
||||
}
|
||||
|
||||
let focused_monitor = self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("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();
|
||||
@@ -180,7 +178,7 @@ impl WindowManager {
|
||||
let workspace_idx = direction.next_idx(
|
||||
focused_workspace_idx,
|
||||
NonZeroUsize::new(workspaces)
|
||||
.ok_or_else(|| eyre!("there must be at least one workspace"))?,
|
||||
.ok_or_eyre("there must be at least one workspace")?,
|
||||
);
|
||||
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
@@ -202,9 +200,7 @@ impl WindowManager {
|
||||
// }
|
||||
// }
|
||||
|
||||
let focused_monitor = self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("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();
|
||||
@@ -221,14 +217,14 @@ impl WindowManager {
|
||||
let mut workspace_idx = direction.next_idx(
|
||||
focused_workspace_idx,
|
||||
NonZeroUsize::new(workspaces)
|
||||
.ok_or_else(|| eyre!("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(|| eyre!("there must be at least one workspace"))?,
|
||||
.ok_or_eyre("there must be at least one workspace")?,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -263,7 +259,7 @@ impl WindowManager {
|
||||
|
||||
let idx = self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.focused_workspace_idx();
|
||||
|
||||
if let Some(monitor) = self.focused_monitor_mut()
|
||||
@@ -273,7 +269,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
self.focused_monitor_mut()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.last_focused_workspace = Option::from(idx);
|
||||
}
|
||||
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
||||
@@ -637,7 +633,7 @@ impl WindowManager {
|
||||
|
||||
let idx = self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.focused_workspace_idx();
|
||||
|
||||
if let Some(monitor) = self.focused_monitor_mut()
|
||||
@@ -647,7 +643,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
self.focused_monitor_mut()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.last_focused_workspace = Option::from(idx);
|
||||
}
|
||||
SocketMessage::SendContainerToLastWorkspace => {
|
||||
@@ -665,7 +661,7 @@ impl WindowManager {
|
||||
|
||||
let idx = self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.focused_workspace_idx();
|
||||
|
||||
if let Some(monitor) = self.focused_monitor_mut()
|
||||
@@ -674,13 +670,11 @@ impl WindowManager {
|
||||
self.move_container_to_workspace(last_focused_workspace, false, None)?;
|
||||
}
|
||||
self.focused_monitor_mut()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.last_focused_workspace = Option::from(idx);
|
||||
}
|
||||
SocketMessage::CycleMoveContainerToWorkspace(direction) => {
|
||||
let focused_monitor = self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("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();
|
||||
@@ -688,7 +682,7 @@ impl WindowManager {
|
||||
let workspace_idx = direction.next_idx(
|
||||
focused_workspace_idx,
|
||||
NonZeroUsize::new(workspaces)
|
||||
.ok_or_else(|| eyre!("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)?;
|
||||
@@ -704,16 +698,14 @@ impl WindowManager {
|
||||
let monitor_idx = direction.next_idx(
|
||||
self.focused_monitor_idx(),
|
||||
NonZeroUsize::new(self.monitors().len())
|
||||
.ok_or_else(|| eyre!("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);
|
||||
self.move_container_to_monitor(monitor_idx, None, true, direction)?;
|
||||
}
|
||||
SocketMessage::CycleSendContainerToWorkspace(direction) => {
|
||||
let focused_monitor = self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("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();
|
||||
@@ -721,7 +713,7 @@ impl WindowManager {
|
||||
let workspace_idx = direction.next_idx(
|
||||
focused_workspace_idx,
|
||||
NonZeroUsize::new(workspaces)
|
||||
.ok_or_else(|| eyre!("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)?;
|
||||
@@ -734,7 +726,7 @@ impl WindowManager {
|
||||
let monitor_idx = direction.next_idx(
|
||||
self.focused_monitor_idx(),
|
||||
NonZeroUsize::new(self.monitors().len())
|
||||
.ok_or_else(|| eyre!("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);
|
||||
@@ -792,7 +784,7 @@ impl WindowManager {
|
||||
let monitor_idx = direction.next_idx(
|
||||
self.focused_monitor_idx(),
|
||||
NonZeroUsize::new(self.monitors().len())
|
||||
.ok_or_else(|| eyre!("there must be at least one monitor"))?,
|
||||
.ok_or_eyre("there must be at least one monitor")?,
|
||||
);
|
||||
|
||||
self.move_workspace_to_monitor(monitor_idx)?;
|
||||
@@ -809,13 +801,13 @@ impl WindowManager {
|
||||
let offset = self.work_area_offset;
|
||||
let workspace = self
|
||||
.remove_focused_workspace()
|
||||
.ok_or_else(|| eyre!("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(|| eyre!("there is no monitor"))?;
|
||||
.ok_or_eyre("there is no monitor")?;
|
||||
|
||||
target_monitor.workspaces_mut().push_back(workspace);
|
||||
target_monitor.update_workspaces_globals(offset);
|
||||
|
||||
@@ -25,7 +25,7 @@ use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::workspace::Workspace;
|
||||
use crate::workspace::WorkspaceLayer;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use crossbeam_channel::Receiver;
|
||||
use objc2_core_foundation::CFRetained;
|
||||
use objc2_core_foundation::CFRunLoop;
|
||||
@@ -128,10 +128,10 @@ impl WindowManager {
|
||||
|
||||
if len > 1 {
|
||||
let focused_window_id =
|
||||
MacosApi::foreground_window_id().ok_or(eyre!("no foreground window"))?;
|
||||
MacosApi::foreground_window_id().ok_or_eyre("no foreground window")?;
|
||||
let focused_rect = Rect::from(MacosApi::window_rect(
|
||||
MacosApi::foreground_window()
|
||||
.ok_or(eyre!("no foreground window"))?
|
||||
.ok_or_eyre("no foreground window")?
|
||||
.as_ref(),
|
||||
)?);
|
||||
|
||||
@@ -311,7 +311,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(|| eyre!("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;
|
||||
@@ -422,7 +422,7 @@ impl WindowManager {
|
||||
let delta = self.resize_delta;
|
||||
|
||||
let focused_window_id =
|
||||
MacosApi::foreground_window_id().ok_or(eyre!("no foreground window"))?;
|
||||
MacosApi::foreground_window_id().ok_or_eyre("no foreground window")?;
|
||||
for window in focused_workspace.floating_windows().iter() {
|
||||
if window.id == focused_window_id {
|
||||
let mut rect = Rect::from(MacosApi::window_rect(&window.element)?);
|
||||
@@ -516,7 +516,7 @@ impl WindowManager {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
|
||||
self.focused_monitor_mut()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.update_focused_workspace(offset)?;
|
||||
|
||||
if follow_focus
|
||||
@@ -550,38 +550,38 @@ impl WindowManager {
|
||||
pub fn focused_workspace_idx(&self) -> eyre::Result<usize> {
|
||||
Ok(self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.focused_workspace_idx())
|
||||
}
|
||||
|
||||
pub fn focused_workspace(&self) -> eyre::Result<&Workspace> {
|
||||
self.focused_monitor()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.focused_workspace()
|
||||
.ok_or_else(|| eyre!("there is no workspace"))
|
||||
.ok_or_eyre("there is no workspace")
|
||||
}
|
||||
|
||||
pub fn focused_workspace_mut(&mut self) -> eyre::Result<&mut Workspace> {
|
||||
self.focused_monitor_mut()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.focused_workspace_mut()
|
||||
.ok_or_else(|| eyre!("there is no workspace"))
|
||||
.ok_or_eyre("there is no workspace")
|
||||
}
|
||||
|
||||
pub fn focused_workspace_idx_for_monitor_idx(&self, idx: usize) -> eyre::Result<usize> {
|
||||
Ok(self
|
||||
.monitors()
|
||||
.get(idx)
|
||||
.ok_or_else(|| eyre!("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) -> eyre::Result<&Workspace> {
|
||||
self.monitors()
|
||||
.get(idx)
|
||||
.ok_or_else(|| eyre!("there is no monitor at this index"))?
|
||||
.ok_or_eyre("there is no monitor at this index")?
|
||||
.focused_workspace()
|
||||
.ok_or_else(|| eyre!("there is no workspace"))
|
||||
.ok_or_eyre("there is no workspace")
|
||||
}
|
||||
|
||||
pub fn focused_workspace_for_monitor_idx_mut(
|
||||
@@ -590,15 +590,15 @@ impl WindowManager {
|
||||
) -> eyre::Result<&mut Workspace> {
|
||||
self.monitors_mut()
|
||||
.get_mut(idx)
|
||||
.ok_or_else(|| eyre!("there is no monitor at this index"))?
|
||||
.ok_or_eyre("there is no monitor at this index")?
|
||||
.focused_workspace_mut()
|
||||
.ok_or_else(|| eyre!("there is no workspace"))
|
||||
.ok_or_eyre("there is no workspace")
|
||||
}
|
||||
|
||||
pub fn focused_container(&self) -> eyre::Result<&Container> {
|
||||
self.focused_workspace()?
|
||||
.focused_container()
|
||||
.ok_or_else(|| eyre!("there is no container"))
|
||||
.ok_or_eyre("there is no container")
|
||||
}
|
||||
|
||||
pub fn focused_container_idx(&self) -> eyre::Result<usize> {
|
||||
@@ -608,32 +608,32 @@ impl WindowManager {
|
||||
pub fn focused_container_mut(&mut self) -> eyre::Result<&mut Container> {
|
||||
self.focused_workspace_mut()?
|
||||
.focused_container_mut()
|
||||
.ok_or_else(|| eyre!("there is no container"))
|
||||
.ok_or_eyre("there is no container")
|
||||
}
|
||||
|
||||
pub fn focused_window(&self) -> eyre::Result<&Window> {
|
||||
self.focused_container()?
|
||||
.focused_window()
|
||||
.ok_or_else(|| eyre!("there is no window"))
|
||||
.ok_or_eyre("there is no window")
|
||||
}
|
||||
|
||||
fn focused_window_mut(&mut self) -> eyre::Result<&mut Window> {
|
||||
self.focused_container_mut()?
|
||||
.focused_window_mut()
|
||||
.ok_or_else(|| eyre!("there is no window"))
|
||||
.ok_or_eyre("there is no window")
|
||||
}
|
||||
|
||||
pub fn focused_monitor_size(&self) -> eyre::Result<Rect> {
|
||||
Ok(self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.size)
|
||||
}
|
||||
|
||||
pub fn focused_monitor_work_area(&self) -> eyre::Result<Rect> {
|
||||
Ok(self
|
||||
.focused_monitor()
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.work_area_size)
|
||||
}
|
||||
|
||||
@@ -676,7 +676,7 @@ impl WindowManager {
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
let len = NonZeroUsize::new(workspace.containers_mut().len())
|
||||
.ok_or_else(|| eyre!("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
|
||||
@@ -691,7 +691,7 @@ impl WindowManager {
|
||||
if is_valid {
|
||||
let new_idx = workspace
|
||||
.new_idx_for_direction(direction)
|
||||
.ok_or_else(|| eyre!("this is not a valid direction from the current position"))?;
|
||||
.ok_or_eyre("this is not a valid direction from the current position")?;
|
||||
|
||||
let mut changed_focus = false;
|
||||
|
||||
@@ -744,7 +744,7 @@ impl WindowManager {
|
||||
tracing::info!("removing window");
|
||||
|
||||
if self.focused_container()?.windows().len() == 1 {
|
||||
Err(eyre!("a container must have at least one window"))?;
|
||||
eyre::bail!("a container must have at least one window");
|
||||
}
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -783,10 +783,10 @@ impl WindowManager {
|
||||
let container = self.focused_container_mut()?;
|
||||
|
||||
let len = NonZeroUsize::new(container.windows().len())
|
||||
.ok_or_else(|| eyre!("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 {
|
||||
return Err(eyre!("there is only one window in this container"));
|
||||
eyre::bail!("there is only one window in this container");
|
||||
}
|
||||
|
||||
let current_idx = container.focused_window_idx();
|
||||
@@ -808,7 +808,7 @@ impl WindowManager {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let monitor = self
|
||||
.focused_monitor_mut()
|
||||
.ok_or_else(|| eyre!("there is no workspace"))?;
|
||||
.ok_or_eyre("there is no workspace")?;
|
||||
|
||||
monitor.focus_workspace(idx)?;
|
||||
monitor.load_focused_workspace(mouse_follows_focus)?;
|
||||
@@ -828,7 +828,7 @@ impl WindowManager {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let monitor = self
|
||||
.focused_monitor_mut()
|
||||
.ok_or_else(|| eyre!("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)?;
|
||||
@@ -880,7 +880,7 @@ impl WindowManager {
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn toggle_float(&mut self, force_float: bool) -> eyre::Result<()> {
|
||||
let window_id = MacosApi::foreground_window_id().ok_or(eyre!("no foreground window"))?;
|
||||
let window_id = MacosApi::foreground_window_id().ok_or_eyre("no foreground window")?;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
if workspace.monocle_container.is_some() {
|
||||
@@ -922,7 +922,7 @@ impl WindowManager {
|
||||
let window = workspace
|
||||
.floating_windows_mut()
|
||||
.back_mut()
|
||||
.ok_or_else(|| eyre!("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())?;
|
||||
@@ -956,7 +956,7 @@ impl WindowManager {
|
||||
WorkspaceLayer::Floating => {
|
||||
let workspace = self.focused_workspace()?;
|
||||
let focused_window_id =
|
||||
MacosApi::foreground_window_id().ok_or(eyre!("no foreground window"))?;
|
||||
MacosApi::foreground_window_id().ok_or_eyre("no foreground window")?;
|
||||
|
||||
let border_offset = 0;
|
||||
let border_width = 0;
|
||||
@@ -1040,14 +1040,12 @@ impl WindowManager {
|
||||
Layout::Default(layout) => {
|
||||
tracing::info!("resizing window");
|
||||
let len = NonZeroUsize::new(workspace.containers().len())
|
||||
.ok_or_else(|| eyre!("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(|| {
|
||||
eyre!("there is no resize adjustment for this container")
|
||||
})?;
|
||||
.ok_or_eyre("there is no resize adjustment for this container")?;
|
||||
|
||||
if direction
|
||||
.destination(
|
||||
@@ -1096,7 +1094,7 @@ impl WindowManager {
|
||||
let resize = layout.resize(
|
||||
unaltered
|
||||
.get(focused_idx)
|
||||
.ok_or_else(|| eyre!("there is no last layout"))?,
|
||||
.ok_or_eyre("there is no last layout")?,
|
||||
focused_idx_resize,
|
||||
direction,
|
||||
sizing,
|
||||
@@ -1137,7 +1135,7 @@ impl WindowManager {
|
||||
|
||||
let workspace = monitor
|
||||
.focused_workspace_mut()
|
||||
.ok_or_else(|| eyre!("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 {
|
||||
@@ -1274,7 +1272,7 @@ impl WindowManager {
|
||||
if self.monitors().get(idx).is_some() {
|
||||
self.monitors.focus(idx);
|
||||
} else {
|
||||
return Err(eyre!("this is not a valid monitor index"));
|
||||
eyre::bail!("this is not a valid monitor index");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -1405,22 +1403,20 @@ impl WindowManager {
|
||||
|
||||
let monitor = self
|
||||
.focused_monitor_mut()
|
||||
.ok_or_else(|| eyre!("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(|| eyre!("there is no workspace"))?;
|
||||
.ok_or_eyre("there is no workspace")?;
|
||||
|
||||
if workspace.maximized_window.is_some() {
|
||||
return Err(eyre!(
|
||||
"cannot move native maximized window to another monitor or workspace"
|
||||
));
|
||||
eyre::bail!("cannot move native maximized window to another monitor or workspace");
|
||||
}
|
||||
|
||||
let foreground_window_id =
|
||||
MacosApi::foreground_window_id().ok_or(eyre!("no foreground window"))?;
|
||||
MacosApi::foreground_window_id().ok_or_eyre("no foreground window")?;
|
||||
let floating_window_index = workspace
|
||||
.floating_windows()
|
||||
.iter()
|
||||
@@ -1432,7 +1428,7 @@ impl WindowManager {
|
||||
Some(
|
||||
workspace
|
||||
.remove_focused_container()
|
||||
.ok_or_else(|| eyre!("there is no container"))?,
|
||||
.ok_or_eyre("there is no container")?,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
@@ -1442,7 +1438,7 @@ impl WindowManager {
|
||||
let target_monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?;
|
||||
.ok_or_eyre("there is no monitor")?;
|
||||
|
||||
let target_monitor_work_area_size = target_monitor.work_area_size;
|
||||
|
||||
@@ -1455,7 +1451,7 @@ impl WindowManager {
|
||||
}
|
||||
let target_workspace = target_monitor
|
||||
.focused_workspace_mut()
|
||||
.ok_or_else(|| eyre!("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() {
|
||||
@@ -1495,7 +1491,7 @@ impl WindowManager {
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
return Err(eyre!("failed to find a window to move"));
|
||||
eyre::bail!("failed to find a window to move");
|
||||
}
|
||||
|
||||
if should_load_workspace {
|
||||
@@ -1545,7 +1541,7 @@ impl WindowManager {
|
||||
let first_monitor = self
|
||||
.monitors()
|
||||
.get(first_idx)
|
||||
.ok_or_else(|| eyre!("There is no monitor"))?;
|
||||
.ok_or_eyre("There is no monitor")?;
|
||||
first_monitor.focused_workspace_idx()
|
||||
};
|
||||
|
||||
@@ -1553,7 +1549,7 @@ impl WindowManager {
|
||||
let second_monitor = self
|
||||
.monitors()
|
||||
.get(second_idx)
|
||||
.ok_or_else(|| eyre!("There is no monitor"))?;
|
||||
.ok_or_eyre("There is no monitor")?;
|
||||
second_monitor.focused_workspace_idx()
|
||||
};
|
||||
|
||||
@@ -1562,24 +1558,24 @@ impl WindowManager {
|
||||
let first_workspaces = self
|
||||
.monitors_mut()
|
||||
.get_mut(first_idx)
|
||||
.ok_or_else(|| eyre!("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(|| eyre!("There is no monitor"))?
|
||||
.ok_or_eyre("There is no monitor")?
|
||||
.remove_workspaces();
|
||||
|
||||
self.monitors_mut()
|
||||
.get_mut(first_idx)
|
||||
.ok_or_else(|| eyre!("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(|| eyre!("There is no monitor"))?
|
||||
.ok_or_eyre("There is no monitor")?
|
||||
.workspaces_mut()
|
||||
.extend(first_workspaces);
|
||||
|
||||
@@ -1605,7 +1601,7 @@ impl WindowManager {
|
||||
|
||||
self.monitors_mut()
|
||||
.get_mut(idx)
|
||||
.ok_or_else(|| eyre!("there is no monitor"))?
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.update_focused_workspace(offset)
|
||||
}
|
||||
|
||||
@@ -1635,7 +1631,7 @@ impl WindowManager {
|
||||
|
||||
let new_idx = workspace
|
||||
.new_idx_for_cycle_direction(direction)
|
||||
.ok_or_else(|| eyre!("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);
|
||||
|
||||
@@ -1658,9 +1654,7 @@ impl WindowManager {
|
||||
) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
if workspace.is_focused_window_monocle_or_maximized()? {
|
||||
return Err(eyre!(
|
||||
"ignoring command while active window is in monocle mode or maximized"
|
||||
));
|
||||
eyre::bail!("ignoring command while active window is in monocle mode or maximized");
|
||||
}
|
||||
|
||||
tracing::info!("moving container");
|
||||
@@ -1668,7 +1662,7 @@ impl WindowManager {
|
||||
let current_idx = workspace.focused_container_idx();
|
||||
let new_idx = workspace
|
||||
.new_idx_for_cycle_direction(direction)
|
||||
.ok_or_else(|| eyre!("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);
|
||||
@@ -1688,7 +1682,7 @@ impl WindowManager {
|
||||
|
||||
if len > 1 {
|
||||
let focused_window_id =
|
||||
MacosApi::foreground_window_id().ok_or(eyre!("no foreground window"))?;
|
||||
MacosApi::foreground_window_id().ok_or_eyre("no foreground window")?;
|
||||
for (idx, window) in focused_workspace.floating_windows().iter().enumerate() {
|
||||
if window.id == focused_window_id {
|
||||
match direction {
|
||||
@@ -1741,10 +1735,10 @@ impl WindowManager {
|
||||
};
|
||||
|
||||
let len = NonZeroUsize::new(container.windows().len())
|
||||
.ok_or_else(|| eyre!("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 {
|
||||
return Err(eyre!("there is only one window in this container"));
|
||||
eyre::bail!("there is only one window in this container");
|
||||
}
|
||||
|
||||
let current_idx = container.focused_window_idx();
|
||||
@@ -1775,14 +1769,14 @@ impl WindowManager {
|
||||
};
|
||||
|
||||
let len = NonZeroUsize::new(container.windows().len())
|
||||
.ok_or_else(|| eyre!("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 {
|
||||
return Err(eyre!("there is only one window in this container"));
|
||||
eyre::bail!("there is only one window in this container");
|
||||
}
|
||||
|
||||
if container.windows().get(idx).is_none() {
|
||||
return Err(eyre!("there is no window in this container at index {idx}"));
|
||||
eyre::bail!("there is no window in this container at index {idx}");
|
||||
}
|
||||
|
||||
container.focus_window(idx);
|
||||
|
||||
+29
-31
@@ -13,7 +13,7 @@ use crate::macos_api::MacosApi;
|
||||
use crate::ring::Ring;
|
||||
use crate::window::Window;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::fmt::Display;
|
||||
@@ -157,16 +157,16 @@ impl Workspace {
|
||||
pub fn focus_container_by_window(&mut self, window_id: u32) -> eyre::Result<()> {
|
||||
let container_idx = self
|
||||
.container_idx_for_window(window_id)
|
||||
.ok_or_else(|| eyre!("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(|| eyre!("there is no container"))?;
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
let window_idx = container
|
||||
.idx_for_window(window_id)
|
||||
.ok_or_else(|| eyre!("there is no window"))?;
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
let mut should_load = false;
|
||||
|
||||
@@ -249,7 +249,7 @@ impl Workspace {
|
||||
{
|
||||
let window = container
|
||||
.remove_window_by_idx(window_idx)
|
||||
.ok_or_else(|| eyre!("there is no window"))?;
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
if container.windows().is_empty() {
|
||||
self.monocle_container = None;
|
||||
@@ -265,22 +265,22 @@ impl Workspace {
|
||||
|
||||
let container_idx = self
|
||||
.container_idx_for_window(window_id)
|
||||
.ok_or_else(|| eyre!("there is no window"))?;
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
let container = self
|
||||
.containers_mut()
|
||||
.get_mut(container_idx)
|
||||
.ok_or_else(|| eyre!("there is no container"))?;
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
let window_idx = container
|
||||
.windows()
|
||||
.iter()
|
||||
.position(|window| window.id == window_id)
|
||||
.ok_or_else(|| eyre!("there is no window"))?;
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
let window = container
|
||||
.remove_window_by_idx(window_idx)
|
||||
.ok_or_else(|| eyre!("there is no window"))?;
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
if container.windows().is_empty() {
|
||||
self.remove_container_by_idx(container_idx);
|
||||
@@ -313,7 +313,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
pub fn is_focused_window_monocle_or_maximized(&self) -> eyre::Result<bool> {
|
||||
let window_id = MacosApi::foreground_window_id().ok_or(eyre!("no foreground window"))?;
|
||||
let window_id = MacosApi::foreground_window_id().ok_or_eyre("no foreground window")?;
|
||||
if let Some(window) = &self.maximized_window
|
||||
&& window_id == window.id
|
||||
{
|
||||
@@ -358,11 +358,11 @@ impl Workspace {
|
||||
|
||||
let container = self
|
||||
.focused_container_mut()
|
||||
.ok_or_else(|| eyre!("there is no container"))?;
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
let window = container
|
||||
.remove_focused_window()
|
||||
.ok_or_else(|| eyre!("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() {
|
||||
@@ -381,13 +381,13 @@ impl Workspace {
|
||||
let target_container = self
|
||||
.containers_mut()
|
||||
.get_mut(adjusted_target_container_index)
|
||||
.ok_or_else(|| eyre!("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(|| eyre!("there is no container"))?
|
||||
.ok_or_eyre("there is no container")?
|
||||
.load_focused_window()?;
|
||||
|
||||
Ok(())
|
||||
@@ -398,11 +398,11 @@ impl Workspace {
|
||||
|
||||
let container = self
|
||||
.focused_container_mut()
|
||||
.ok_or_else(|| eyre!("there is no container"))?;
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
let window = container
|
||||
.remove_focused_window()
|
||||
.ok_or_else(|| eyre!("there is no window"))?;
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
if container.windows().is_empty() {
|
||||
self.remove_container_by_idx(focused_container_idx);
|
||||
@@ -515,7 +515,7 @@ impl Workspace {
|
||||
let resize = self.resize_dimensions.remove(0);
|
||||
let container = self
|
||||
.remove_focused_container()
|
||||
.ok_or_else(|| eyre!("there is no container"))?;
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
let primary_idx = match self.layout {
|
||||
Layout::Default(_) => 0,
|
||||
@@ -555,7 +555,7 @@ impl Workspace {
|
||||
let container = self
|
||||
.containers_mut()
|
||||
.remove(focused_idx)
|
||||
.ok_or_else(|| eyre!("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
|
||||
@@ -567,7 +567,7 @@ impl Workspace {
|
||||
|
||||
self.monocle_container
|
||||
.as_mut()
|
||||
.ok_or_else(|| eyre!("there is no monocle container"))?
|
||||
.ok_or_eyre("there is no monocle container")?
|
||||
.load_focused_window()?;
|
||||
|
||||
Ok(())
|
||||
@@ -576,12 +576,12 @@ impl Workspace {
|
||||
pub fn reintegrate_monocle_container(&mut self) -> eyre::Result<()> {
|
||||
let restore_idx = self
|
||||
.monocle_container_restore_idx
|
||||
.ok_or_else(|| eyre!("there is no monocle restore index"))?;
|
||||
.ok_or_eyre("there is no monocle restore index")?;
|
||||
|
||||
let container = self
|
||||
.monocle_container
|
||||
.as_ref()
|
||||
.ok_or_else(|| eyre!("there is no monocle container"))?;
|
||||
.ok_or_eyre("there is no monocle container")?;
|
||||
|
||||
let container = container.clone();
|
||||
if restore_idx >= self.containers().len() {
|
||||
@@ -595,7 +595,7 @@ impl Workspace {
|
||||
self.containers_mut().insert(restore_idx, container);
|
||||
self.focus_container(restore_idx);
|
||||
self.focused_container_mut()
|
||||
.ok_or_else(|| eyre!("there is no container"))?
|
||||
.ok_or_eyre("there is no container")?
|
||||
.load_focused_window()?;
|
||||
|
||||
self.monocle_container = None;
|
||||
@@ -608,7 +608,7 @@ impl Workspace {
|
||||
let window = if let Some(monocle_container) = &mut self.monocle_container {
|
||||
let window = monocle_container
|
||||
.remove_focused_window()
|
||||
.ok_or_else(|| eyre!("there is no window"))?;
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
if monocle_container.windows().is_empty() {
|
||||
self.monocle_container = None;
|
||||
@@ -623,11 +623,11 @@ impl Workspace {
|
||||
|
||||
let container = self
|
||||
.focused_container_mut()
|
||||
.ok_or_else(|| eyre!("there is no container"))?;
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
let window = container
|
||||
.remove_focused_window()
|
||||
.ok_or_else(|| eyre!("there is no window"))?;
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
if container.windows().is_empty() {
|
||||
self.remove_container_by_idx(focused_idx);
|
||||
@@ -651,7 +651,7 @@ impl Workspace {
|
||||
let focused_idx = self.focused_container_idx();
|
||||
let window = self
|
||||
.remove_focused_floating_window()
|
||||
.ok_or_else(|| eyre!("there is no floating window"))?;
|
||||
.ok_or_eyre("there is no floating window")?;
|
||||
|
||||
let mut container = Container::default();
|
||||
container.add_window(&window)?;
|
||||
@@ -787,11 +787,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(|| {
|
||||
eyre!(
|
||||
"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,
|
||||
|
||||
Reference in new issue
Block a user