mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-08 05:55:09 +02: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:
@@ -5,7 +5,6 @@ use std::ops::Deref;
|
|||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use color_eyre::eyre::anyhow;
|
|
||||||
use color_eyre::eyre::bail;
|
use color_eyre::eyre::bail;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -41,7 +40,7 @@ impl CustomLayout {
|
|||||||
Some(extension) if extension == "json" => {
|
Some(extension) if extension == "json" => {
|
||||||
serde_json::from_reader(BufReader::new(File::open(path)?))?
|
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() {
|
if !layout.is_valid() {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use color_eyre::eyre::anyhow;
|
use color_eyre::eyre::bail;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossbeam_utils::Backoff;
|
use crossbeam_utils::Backoff;
|
||||||
use komorebi::animation::AnimationEngine;
|
use komorebi::animation::AnimationEngine;
|
||||||
@@ -210,9 +210,7 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if set_foreground_window_retries == 0 {
|
if set_foreground_window_retries == 0 {
|
||||||
return Err(anyhow!(
|
bail!("failed call to AllowSetForegroundWindow after 5 retries");
|
||||||
"failed call to AllowSetForegroundWindow after 5 retries"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ use std::collections::HashMap;
|
|||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
|
|
||||||
use color_eyre::eyre::anyhow;
|
|
||||||
use color_eyre::eyre::bail;
|
use color_eyre::eyre::bail;
|
||||||
|
use color_eyre::eyre::OptionExt;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use getset::CopyGetters;
|
use getset::CopyGetters;
|
||||||
use getset::Getters;
|
use getset::Getters;
|
||||||
@@ -290,10 +290,10 @@ impl Monitor {
|
|||||||
let workspace = if let Some(idx) = workspace_idx {
|
let workspace = if let Some(idx) = workspace_idx {
|
||||||
self.workspaces_mut()
|
self.workspaces_mut()
|
||||||
.get_mut(idx)
|
.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 {
|
} else {
|
||||||
self.focused_workspace_mut()
|
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);
|
workspace.add_container_to_back(container);
|
||||||
@@ -314,10 +314,10 @@ impl Monitor {
|
|||||||
let workspace = if let Some(idx) = workspace_idx {
|
let workspace = if let Some(idx) = workspace_idx {
|
||||||
self.workspaces_mut()
|
self.workspaces_mut()
|
||||||
.get_mut(idx)
|
.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 {
|
} else {
|
||||||
self.focused_workspace_mut()
|
self.focused_workspace_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))?
|
.ok_or_eyre("there is no workspace")?
|
||||||
};
|
};
|
||||||
|
|
||||||
match direction {
|
match direction {
|
||||||
@@ -415,7 +415,7 @@ impl Monitor {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let workspace = self
|
let workspace = self
|
||||||
.focused_workspace_mut()
|
.focused_workspace_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
.ok_or_eyre("there is no workspace")?;
|
||||||
|
|
||||||
if workspace.maximized_window().is_some() {
|
if workspace.maximized_window().is_some() {
|
||||||
bail!("cannot move native maximized window to another monitor or workspace");
|
bail!("cannot move native maximized window to another monitor or workspace");
|
||||||
@@ -445,7 +445,7 @@ impl Monitor {
|
|||||||
} else {
|
} else {
|
||||||
let container = workspace
|
let container = workspace
|
||||||
.remove_focused_container()
|
.remove_focused_container()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?;
|
.ok_or_eyre("there is no container")?;
|
||||||
|
|
||||||
let workspaces = self.workspaces_mut();
|
let workspaces = self.workspaces_mut();
|
||||||
|
|
||||||
@@ -510,7 +510,7 @@ impl Monitor {
|
|||||||
if name.is_some() {
|
if name.is_some() {
|
||||||
self.workspaces_mut()
|
self.workspaces_mut()
|
||||||
.get_mut(idx)
|
.get_mut(idx)
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))?
|
.ok_or_eyre("there is no workspace")?
|
||||||
.set_name(name);
|
.set_name(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -532,7 +532,7 @@ impl Monitor {
|
|||||||
let focused_workspace_idx = self.focused_workspace_idx();
|
let focused_workspace_idx = self.focused_workspace_idx();
|
||||||
self.update_workspace_globals(focused_workspace_idx, offset);
|
self.update_workspace_globals(focused_workspace_idx, offset);
|
||||||
self.focused_workspace_mut()
|
self.focused_workspace_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))?
|
.ok_or_eyre("there is no workspace")?
|
||||||
.update()?;
|
.update()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use color_eyre::eyre::anyhow;
|
|
||||||
use color_eyre::eyre::OptionExt;
|
use color_eyre::eyre::OptionExt;
|
||||||
|
use color_eyre::eyre::WrapErr;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use komorebi_themes::colour::Rgb;
|
use komorebi_themes::colour::Rgb;
|
||||||
use miow::pipe::connect;
|
use miow::pipe::connect;
|
||||||
@@ -618,7 +618,7 @@ impl WindowManager {
|
|||||||
for (i, monitor) in self.monitors().iter().enumerate() {
|
for (i, monitor) in self.monitors().iter().enumerate() {
|
||||||
for container in monitor
|
for container in monitor
|
||||||
.focused_workspace()
|
.focused_workspace()
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))?
|
.ok_or_eyre("there is no workspace")?
|
||||||
.containers()
|
.containers()
|
||||||
{
|
{
|
||||||
for window in container.windows() {
|
for window in container.windows() {
|
||||||
@@ -652,11 +652,11 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
.ok_or_eyre("there is no monitor")?;
|
||||||
|
|
||||||
monitor
|
monitor
|
||||||
.focused_workspace_mut()
|
.focused_workspace_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no focused workspace"))?
|
.ok_or_eyre("there is no focused workspace")?
|
||||||
.remove_window(hwnd)?;
|
.remove_window(hwnd)?;
|
||||||
|
|
||||||
monitor.update_focused_workspace(offset)?;
|
monitor.update_focused_workspace(offset)?;
|
||||||
@@ -665,9 +665,7 @@ impl WindowManager {
|
|||||||
SocketMessage::FocusedWorkspaceContainerPadding(adjustment) => {
|
SocketMessage::FocusedWorkspaceContainerPadding(adjustment) => {
|
||||||
let focused_monitor_idx = self.focused_monitor_idx();
|
let focused_monitor_idx = self.focused_monitor_idx();
|
||||||
|
|
||||||
let focused_monitor = self
|
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
|
||||||
.focused_monitor()
|
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
|
||||||
|
|
||||||
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
||||||
|
|
||||||
@@ -676,9 +674,7 @@ impl WindowManager {
|
|||||||
SocketMessage::FocusedWorkspacePadding(adjustment) => {
|
SocketMessage::FocusedWorkspacePadding(adjustment) => {
|
||||||
let focused_monitor_idx = self.focused_monitor_idx();
|
let focused_monitor_idx = self.focused_monitor_idx();
|
||||||
|
|
||||||
let focused_monitor = self
|
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
|
||||||
.focused_monitor()
|
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
|
||||||
|
|
||||||
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
||||||
|
|
||||||
@@ -708,7 +704,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let idx = self
|
let idx = self
|
||||||
.focused_monitor()
|
.focused_monitor()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.focused_workspace_idx();
|
.focused_workspace_idx();
|
||||||
|
|
||||||
if let Some(monitor) = self.focused_monitor_mut() {
|
if let Some(monitor) = self.focused_monitor_mut() {
|
||||||
@@ -718,7 +714,7 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.focused_monitor_mut()
|
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));
|
.set_last_focused_workspace(Option::from(idx));
|
||||||
}
|
}
|
||||||
SocketMessage::SendContainerToLastWorkspace => {
|
SocketMessage::SendContainerToLastWorkspace => {
|
||||||
@@ -739,7 +735,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let idx = self
|
let idx = self
|
||||||
.focused_monitor()
|
.focused_monitor()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.focused_workspace_idx();
|
.focused_workspace_idx();
|
||||||
|
|
||||||
if let Some(monitor) = self.focused_monitor_mut() {
|
if let Some(monitor) = self.focused_monitor_mut() {
|
||||||
@@ -748,16 +744,14 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.focused_monitor_mut()
|
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));
|
.set_last_focused_workspace(Option::from(idx));
|
||||||
}
|
}
|
||||||
SocketMessage::MoveContainerToWorkspaceNumber(workspace_idx) => {
|
SocketMessage::MoveContainerToWorkspaceNumber(workspace_idx) => {
|
||||||
self.move_container_to_workspace(workspace_idx, true, None)?;
|
self.move_container_to_workspace(workspace_idx, true, None)?;
|
||||||
}
|
}
|
||||||
SocketMessage::CycleMoveContainerToWorkspace(direction) => {
|
SocketMessage::CycleMoveContainerToWorkspace(direction) => {
|
||||||
let focused_monitor = self
|
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
|
||||||
.focused_monitor()
|
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
|
||||||
|
|
||||||
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
||||||
let workspaces = focused_monitor.workspaces().len();
|
let workspaces = focused_monitor.workspaces().len();
|
||||||
@@ -765,7 +759,7 @@ impl WindowManager {
|
|||||||
let workspace_idx = direction.next_idx(
|
let workspace_idx = direction.next_idx(
|
||||||
focused_workspace_idx,
|
focused_workspace_idx,
|
||||||
NonZeroUsize::new(workspaces)
|
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)?;
|
self.move_container_to_workspace(workspace_idx, true, None)?;
|
||||||
@@ -781,7 +775,7 @@ impl WindowManager {
|
|||||||
let monitor_idx = direction.next_idx(
|
let monitor_idx = direction.next_idx(
|
||||||
self.focused_monitor_idx(),
|
self.focused_monitor_idx(),
|
||||||
NonZeroUsize::new(self.monitors().len())
|
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);
|
let direction = self.direction_from_monitor_idx(monitor_idx);
|
||||||
@@ -791,9 +785,7 @@ impl WindowManager {
|
|||||||
self.move_container_to_workspace(workspace_idx, false, None)?;
|
self.move_container_to_workspace(workspace_idx, false, None)?;
|
||||||
}
|
}
|
||||||
SocketMessage::CycleSendContainerToWorkspace(direction) => {
|
SocketMessage::CycleSendContainerToWorkspace(direction) => {
|
||||||
let focused_monitor = self
|
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
|
||||||
.focused_monitor()
|
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
|
||||||
|
|
||||||
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
||||||
let workspaces = focused_monitor.workspaces().len();
|
let workspaces = focused_monitor.workspaces().len();
|
||||||
@@ -801,7 +793,7 @@ impl WindowManager {
|
|||||||
let workspace_idx = direction.next_idx(
|
let workspace_idx = direction.next_idx(
|
||||||
focused_workspace_idx,
|
focused_workspace_idx,
|
||||||
NonZeroUsize::new(workspaces)
|
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)?;
|
self.move_container_to_workspace(workspace_idx, false, None)?;
|
||||||
@@ -814,7 +806,7 @@ impl WindowManager {
|
|||||||
let monitor_idx = direction.next_idx(
|
let monitor_idx = direction.next_idx(
|
||||||
self.focused_monitor_idx(),
|
self.focused_monitor_idx(),
|
||||||
NonZeroUsize::new(self.monitors().len())
|
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);
|
let direction = self.direction_from_monitor_idx(monitor_idx);
|
||||||
@@ -872,7 +864,7 @@ impl WindowManager {
|
|||||||
let monitor_idx = direction.next_idx(
|
let monitor_idx = direction.next_idx(
|
||||||
self.focused_monitor_idx(),
|
self.focused_monitor_idx(),
|
||||||
NonZeroUsize::new(self.monitors().len())
|
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)?;
|
self.move_workspace_to_monitor(monitor_idx)?;
|
||||||
@@ -894,7 +886,7 @@ impl WindowManager {
|
|||||||
let monitor_idx = direction.next_idx(
|
let monitor_idx = direction.next_idx(
|
||||||
self.focused_monitor_idx(),
|
self.focused_monitor_idx(),
|
||||||
NonZeroUsize::new(self.monitors().len())
|
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)?;
|
self.focus_monitor(monitor_idx)?;
|
||||||
@@ -1056,9 +1048,7 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let focused_monitor = self
|
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
|
||||||
.focused_monitor()
|
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
|
||||||
|
|
||||||
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
||||||
let workspaces = focused_monitor.workspaces().len();
|
let workspaces = focused_monitor.workspaces().len();
|
||||||
@@ -1066,7 +1056,7 @@ impl WindowManager {
|
|||||||
let workspace_idx = direction.next_idx(
|
let workspace_idx = direction.next_idx(
|
||||||
focused_workspace_idx,
|
focused_workspace_idx,
|
||||||
NonZeroUsize::new(workspaces)
|
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)?;
|
self.focus_workspace(workspace_idx)?;
|
||||||
@@ -1087,9 +1077,7 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let focused_monitor = self
|
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
|
||||||
.focused_monitor()
|
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
|
||||||
|
|
||||||
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
let focused_workspace_idx = focused_monitor.focused_workspace_idx();
|
||||||
let workspaces = focused_monitor.workspaces().len();
|
let workspaces = focused_monitor.workspaces().len();
|
||||||
@@ -1106,14 +1094,14 @@ impl WindowManager {
|
|||||||
let mut workspace_idx = direction.next_idx(
|
let mut workspace_idx = direction.next_idx(
|
||||||
focused_workspace_idx,
|
focused_workspace_idx,
|
||||||
NonZeroUsize::new(workspaces)
|
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) {
|
while !empty_workspaces.contains(&workspace_idx) {
|
||||||
workspace_idx = direction.next_idx(
|
workspace_idx = direction.next_idx(
|
||||||
workspace_idx,
|
workspace_idx,
|
||||||
NonZeroUsize::new(workspaces)
|
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
|
let idx = self
|
||||||
.focused_monitor()
|
.focused_monitor()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.focused_workspace_idx();
|
.focused_workspace_idx();
|
||||||
|
|
||||||
if let Some(monitor) = self.focused_monitor_mut() {
|
if let Some(monitor) = self.focused_monitor_mut() {
|
||||||
@@ -1192,7 +1180,7 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.focused_monitor_mut()
|
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));
|
.set_last_focused_workspace(Option::from(idx));
|
||||||
}
|
}
|
||||||
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
||||||
@@ -1450,7 +1438,7 @@ impl WindowManager {
|
|||||||
StateQuery::FocusedMonitorIndex => self.focused_monitor_idx().to_string(),
|
StateQuery::FocusedMonitorIndex => self.focused_monitor_idx().to_string(),
|
||||||
StateQuery::FocusedWorkspaceIndex => self
|
StateQuery::FocusedWorkspaceIndex => self
|
||||||
.focused_monitor()
|
.focused_monitor()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.focused_workspace_idx()
|
.focused_workspace_idx()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
StateQuery::FocusedContainerIndex => self
|
StateQuery::FocusedContainerIndex => self
|
||||||
@@ -1461,9 +1449,8 @@ impl WindowManager {
|
|||||||
self.focused_container()?.focused_window_idx().to_string()
|
self.focused_container()?.focused_window_idx().to_string()
|
||||||
}
|
}
|
||||||
StateQuery::FocusedWorkspaceName => {
|
StateQuery::FocusedWorkspaceName => {
|
||||||
let focused_monitor = self
|
let focused_monitor =
|
||||||
.focused_monitor()
|
self.focused_monitor().ok_or_eyre("there is no monitor")?;
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
|
||||||
|
|
||||||
focused_monitor
|
focused_monitor
|
||||||
.focused_workspace_name()
|
.focused_workspace_name()
|
||||||
@@ -1471,9 +1458,8 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
StateQuery::Version => build::RUST_VERSION.to_string(),
|
StateQuery::Version => build::RUST_VERSION.to_string(),
|
||||||
StateQuery::FocusedWorkspaceLayout => {
|
StateQuery::FocusedWorkspaceLayout => {
|
||||||
let focused_monitor = self
|
let focused_monitor =
|
||||||
.focused_monitor()
|
self.focused_monitor().ok_or_eyre("there is no monitor")?;
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
|
||||||
|
|
||||||
focused_monitor.focused_workspace_layout().map_or_else(
|
focused_monitor.focused_workspace_layout().map_or_else(
|
||||||
|| "None".to_string(),
|
|| "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 quicksave_json = std::env::temp_dir().join("komorebi.quicksave.json");
|
||||||
|
|
||||||
let file = File::open(&quicksave_json)
|
let file = File::open(&quicksave_json).wrap_err(format!(
|
||||||
.map_err(|_| anyhow!("no quicksave found at {}", quicksave_json.display()))?;
|
"no quicksave found at {}",
|
||||||
|
quicksave_json.display()
|
||||||
|
))?;
|
||||||
|
|
||||||
let resize: Vec<Option<Rect>> = serde_json::from_reader(file)?;
|
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 workspace = self.focused_workspace_mut()?;
|
||||||
|
|
||||||
let file =
|
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)?;
|
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) => {
|
SocketMessage::AddSubscriberPipe(ref subscriber) => {
|
||||||
let mut pipes = SUBSCRIPTION_PIPES.lock();
|
let mut pipes = SUBSCRIPTION_PIPES.lock();
|
||||||
let pipe_path = format!(r"\\.\pipe\{subscriber}");
|
let pipe_path = format!(r"\\.\pipe\{subscriber}");
|
||||||
let pipe = connect(&pipe_path).map_err(|_| {
|
let pipe = connect(&pipe_path).wrap_err(
|
||||||
anyhow!("the named pipe '{}' has not yet been created; please create it before running this command", pipe_path)
|
format!("the named pipe '{}' has not yet been created; please create it before running this command", pipe_path)
|
||||||
})?;
|
)?;
|
||||||
|
|
||||||
pipes.insert(subscriber.clone(), pipe);
|
pipes.insert(subscriber.clone(), pipe);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use color_eyre::eyre::anyhow;
|
use color_eyre::eyre::OptionExt;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossbeam_utils::atomic::AtomicConsume;
|
use crossbeam_utils::atomic::AtomicConsume;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@@ -477,9 +477,7 @@ impl WindowManager {
|
|||||||
WindowContainerBehaviour::Append => {
|
WindowContainerBehaviour::Append => {
|
||||||
workspace
|
workspace
|
||||||
.focused_container_mut()
|
.focused_container_mut()
|
||||||
.ok_or_else(|| {
|
.ok_or_eyre("there is no focused container")?
|
||||||
anyhow!("there is no focused container")
|
|
||||||
})?
|
|
||||||
.add_window(window);
|
.add_window(window);
|
||||||
workspace.set_layer(WorkspaceLayer::Tiling);
|
workspace.set_layer(WorkspaceLayer::Tiling);
|
||||||
self.update_focused_workspace(true, false)?;
|
self.update_focused_workspace(true, false)?;
|
||||||
@@ -529,7 +527,7 @@ impl WindowManager {
|
|||||||
let monitor_idx = self.focused_monitor_idx();
|
let monitor_idx = self.focused_monitor_idx();
|
||||||
let workspace_idx = self
|
let workspace_idx = self
|
||||||
.focused_monitor()
|
.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();
|
.focused_workspace_idx();
|
||||||
|
|
||||||
WindowsApi::bring_window_to_top(window.hwnd)?;
|
WindowsApi::bring_window_to_top(window.hwnd)?;
|
||||||
@@ -559,7 +557,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let target_monitor_idx = self
|
let target_monitor_idx = self
|
||||||
.monitor_idx_from_current_pos()
|
.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_monitor_idx = self.focused_monitor_idx();
|
||||||
let focused_workspace_idx = self.focused_workspace_idx().unwrap_or_default();
|
let focused_workspace_idx = self.focused_workspace_idx().unwrap_or_default();
|
||||||
@@ -603,10 +601,10 @@ impl WindowManager {
|
|||||||
let origin_workspace = self
|
let origin_workspace = self
|
||||||
.monitors()
|
.monitors()
|
||||||
.get(origin_monitor_idx)
|
.get(origin_monitor_idx)
|
||||||
.ok_or_else(|| anyhow!("cannot get monitor idx"))?
|
.ok_or_eyre("cannot get monitor idx")?
|
||||||
.workspaces()
|
.workspaces()
|
||||||
.get(origin_workspace_idx)
|
.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);
|
let managed_window = origin_workspace.contains_window(window.hwnd);
|
||||||
|
|
||||||
@@ -646,17 +644,15 @@ impl WindowManager {
|
|||||||
let target_workspace_idx = self
|
let target_workspace_idx = self
|
||||||
.monitors()
|
.monitors()
|
||||||
.get(target_monitor_idx)
|
.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();
|
.focused_workspace_idx();
|
||||||
|
|
||||||
let target_container_idx = self
|
let target_container_idx = self
|
||||||
.monitors()
|
.monitors()
|
||||||
.get(target_monitor_idx)
|
.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()
|
.focused_workspace()
|
||||||
.ok_or_else(|| {
|
.ok_or_eyre("there is no focused workspace for this monitor")?
|
||||||
anyhow!("there is no focused workspace for this monitor")
|
|
||||||
})?
|
|
||||||
.container_idx_from_current_point()
|
.container_idx_from_current_point()
|
||||||
// Default to 0 in the case of an empty workspace
|
// Default to 0 in the case of an empty workspace
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
@@ -676,7 +672,7 @@ impl WindowManager {
|
|||||||
let origin_monitor = self
|
let origin_monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(origin_monitor_idx)
|
.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)?;
|
origin_monitor.focus_workspace(origin_workspace_idx)?;
|
||||||
self.update_focused_workspace(false, false)?;
|
self.update_focused_workspace(false, false)?;
|
||||||
|
|
||||||
@@ -684,7 +680,7 @@ impl WindowManager {
|
|||||||
let target_monitor = self
|
let target_monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(target_monitor_idx)
|
.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)?;
|
target_monitor.focus_workspace(target_workspace_idx)?;
|
||||||
self.update_focused_workspace(false, false)?;
|
self.update_focused_workspace(false, false)?;
|
||||||
|
|
||||||
|
|||||||
+122
-124
@@ -11,8 +11,8 @@ use std::path::PathBuf;
|
|||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use color_eyre::eyre::anyhow;
|
|
||||||
use color_eyre::eyre::bail;
|
use color_eyre::eyre::bail;
|
||||||
|
use color_eyre::eyre::OptionExt;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossbeam_channel::Receiver;
|
use crossbeam_channel::Receiver;
|
||||||
use hotwatch::notify::ErrorKind as NotifyErrorKind;
|
use hotwatch::notify::ErrorKind as NotifyErrorKind;
|
||||||
@@ -849,7 +849,7 @@ impl WindowManager {
|
|||||||
let focused_workspace_idx = self
|
let focused_workspace_idx = self
|
||||||
.monitors()
|
.monitors()
|
||||||
.get(focused_monitor_idx)
|
.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();
|
.focused_workspace_idx();
|
||||||
|
|
||||||
// scope mutex locks to avoid deadlock if should_update_focused_workspace evaluates to true
|
// scope mutex locks to avoid deadlock if should_update_focused_workspace evaluates to true
|
||||||
@@ -945,20 +945,20 @@ impl WindowManager {
|
|||||||
let target_area = *self
|
let target_area = *self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(op.target_monitor_idx)
|
.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();
|
.work_area_size();
|
||||||
|
|
||||||
let origin_monitor = self
|
let origin_monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(op.origin_monitor_idx)
|
.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_area = *origin_monitor.work_area_size();
|
||||||
|
|
||||||
let origin_workspace = origin_monitor
|
let origin_workspace = origin_monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(op.origin_workspace_idx)
|
.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);
|
let mut window = Window::from(op.hwnd);
|
||||||
|
|
||||||
@@ -982,7 +982,7 @@ impl WindowManager {
|
|||||||
let target_monitor = self
|
let target_monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(op.target_monitor_idx)
|
.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
|
// The very first time this fn is called, the workspace might not even exist yet
|
||||||
if target_monitor
|
if target_monitor
|
||||||
@@ -997,7 +997,7 @@ impl WindowManager {
|
|||||||
let target_workspace = target_monitor
|
let target_workspace = target_monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(op.target_workspace_idx)
|
.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 {
|
if op.floating {
|
||||||
target_workspace
|
target_workspace
|
||||||
@@ -1042,7 +1042,7 @@ impl WindowManager {
|
|||||||
let monitor_wp = monitor.wallpaper.clone();
|
let monitor_wp = monitor.wallpaper.clone();
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.focused_workspace_mut()
|
.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
|
// Reset any resize adjustments if we want to force a retile
|
||||||
if !preserve_resize_dimensions {
|
if !preserve_resize_dimensions {
|
||||||
@@ -1155,10 +1155,10 @@ impl WindowManager {
|
|||||||
let origin_workspace = self
|
let origin_workspace = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(origin_monitor_idx)
|
.get_mut(origin_monitor_idx)
|
||||||
.ok_or_else(|| anyhow!("cannot get monitor idx"))?
|
.ok_or_eyre("cannot get monitor idx")?
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(origin_workspace_idx)
|
.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
|
let origin_container_idx = origin_workspace
|
||||||
.container_for_window(w_hwnd)
|
.container_for_window(w_hwnd)
|
||||||
@@ -1191,9 +1191,9 @@ impl WindowManager {
|
|||||||
let target_workspace = self
|
let target_workspace = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(target_monitor_idx)
|
.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()
|
.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
|
target_workspace
|
||||||
.floating_windows_mut()
|
.floating_windows_mut()
|
||||||
@@ -1210,10 +1210,10 @@ impl WindowManager {
|
|||||||
let origin_workspace = self
|
let origin_workspace = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(origin_monitor_idx)
|
.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()
|
.workspaces_mut()
|
||||||
.get_mut(origin_workspace_idx)
|
.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;
|
let mut uncloack_amount = 0;
|
||||||
for container in origin_workspace.containers_mut() {
|
for container in origin_workspace.containers_mut() {
|
||||||
container.restore();
|
container.restore();
|
||||||
@@ -1248,13 +1248,13 @@ impl WindowManager {
|
|||||||
self.focus_monitor(origin_monitor_idx)?;
|
self.focus_monitor(origin_monitor_idx)?;
|
||||||
let origin_monitor = self
|
let origin_monitor = self
|
||||||
.focused_monitor_mut()
|
.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)?;
|
origin_monitor.focus_workspace(origin_workspace_idx)?;
|
||||||
self.unmaximize_window()?;
|
self.unmaximize_window()?;
|
||||||
self.focus_monitor(target_monitor_idx)?;
|
self.focus_monitor(target_monitor_idx)?;
|
||||||
let target_monitor = self
|
let target_monitor = self
|
||||||
.focused_monitor_mut()
|
.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)?;
|
target_monitor.focus_workspace(target_workspace_idx)?;
|
||||||
|
|
||||||
self.transfer_container(
|
self.transfer_container(
|
||||||
@@ -1282,20 +1282,20 @@ impl WindowManager {
|
|||||||
let origin_container = self
|
let origin_container = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(origin_monitor_idx)
|
.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()
|
.workspaces_mut()
|
||||||
.get_mut(origin_workspace_idx)
|
.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)
|
.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
|
let target_workspace = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(target_monitor_idx)
|
.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()
|
.workspaces_mut()
|
||||||
.get_mut(target_workspace_idx)
|
.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
|
target_workspace
|
||||||
.containers_mut()
|
.containers_mut()
|
||||||
@@ -1318,10 +1318,10 @@ impl WindowManager {
|
|||||||
let origin_container_is_valid = self
|
let origin_container_is_valid = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(origin_monitor_idx)
|
.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()
|
.workspaces_mut()
|
||||||
.get_mut(origin_workspace_idx)
|
.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()
|
.containers()
|
||||||
.get(origin_container_idx)
|
.get(origin_container_idx)
|
||||||
.is_some();
|
.is_some();
|
||||||
@@ -1329,10 +1329,10 @@ impl WindowManager {
|
|||||||
let target_container_is_valid = self
|
let target_container_is_valid = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(target_monitor_idx)
|
.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()
|
.workspaces_mut()
|
||||||
.get_mut(target_workspace_idx)
|
.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()
|
.containers()
|
||||||
.get(origin_container_idx)
|
.get(origin_container_idx)
|
||||||
.is_some();
|
.is_some();
|
||||||
@@ -1341,38 +1341,38 @@ impl WindowManager {
|
|||||||
let origin_container = self
|
let origin_container = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(origin_monitor_idx)
|
.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()
|
.workspaces_mut()
|
||||||
.get_mut(origin_workspace_idx)
|
.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)
|
.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
|
let target_container = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(target_monitor_idx)
|
.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()
|
.workspaces_mut()
|
||||||
.get_mut(target_workspace_idx)
|
.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);
|
.remove_container(target_container_idx);
|
||||||
|
|
||||||
self.monitors_mut()
|
self.monitors_mut()
|
||||||
.get_mut(target_monitor_idx)
|
.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()
|
.workspaces_mut()
|
||||||
.get_mut(target_workspace_idx)
|
.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()
|
.containers_mut()
|
||||||
.insert(target_container_idx, origin_container);
|
.insert(target_container_idx, origin_container);
|
||||||
|
|
||||||
if let Some(target_container) = target_container {
|
if let Some(target_container) = target_container {
|
||||||
self.monitors_mut()
|
self.monitors_mut()
|
||||||
.get_mut(origin_monitor_idx)
|
.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()
|
.workspaces_mut()
|
||||||
.get_mut(origin_workspace_idx)
|
.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()
|
.containers_mut()
|
||||||
.insert(origin_container_idx, target_container);
|
.insert(origin_container_idx, target_container);
|
||||||
}
|
}
|
||||||
@@ -1392,7 +1392,7 @@ impl WindowManager {
|
|||||||
let offset = self.work_area_offset;
|
let offset = self.work_area_offset;
|
||||||
|
|
||||||
self.focused_monitor_mut()
|
self.focused_monitor_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.update_focused_workspace(offset)?;
|
.update_focused_workspace(offset)?;
|
||||||
|
|
||||||
if follow_focus {
|
if follow_focus {
|
||||||
@@ -1556,14 +1556,12 @@ impl WindowManager {
|
|||||||
Layout::Default(layout) => {
|
Layout::Default(layout) => {
|
||||||
tracing::info!("resizing window");
|
tracing::info!("resizing window");
|
||||||
let len = NonZeroUsize::new(workspace.containers().len())
|
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 = workspace.focused_container_idx();
|
||||||
let focused_idx_resize = workspace
|
let focused_idx_resize = workspace
|
||||||
.resize_dimensions()
|
.resize_dimensions()
|
||||||
.get(focused_idx)
|
.get(focused_idx)
|
||||||
.ok_or_else(|| {
|
.ok_or_eyre("there is no resize adjustment for this container")?;
|
||||||
anyhow!("there is no resize adjustment for this container")
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if direction
|
if direction
|
||||||
.destination(
|
.destination(
|
||||||
@@ -1612,7 +1610,7 @@ impl WindowManager {
|
|||||||
let resize = layout.resize(
|
let resize = layout.resize(
|
||||||
unaltered
|
unaltered
|
||||||
.get(focused_idx)
|
.get(focused_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no last layout"))?,
|
.ok_or_eyre("there is no last layout")?,
|
||||||
focused_idx_resize,
|
focused_idx_resize,
|
||||||
direction,
|
direction,
|
||||||
sizing,
|
sizing,
|
||||||
@@ -1778,7 +1776,7 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
.ok_or_eyre("there is no monitor")?;
|
||||||
|
|
||||||
let hmonitor = monitor.id();
|
let hmonitor = monitor.id();
|
||||||
let monitor_wp = monitor.wallpaper.clone();
|
let monitor_wp = monitor.wallpaper.clone();
|
||||||
@@ -1786,7 +1784,7 @@ impl WindowManager {
|
|||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces()
|
.workspaces()
|
||||||
.get(workspace_idx)
|
.get(workspace_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
.ok_or_eyre("there is no workspace")?;
|
||||||
|
|
||||||
workspace.apply_wallpaper(hmonitor, &monitor_wp)
|
workspace.apply_wallpaper(hmonitor, &monitor_wp)
|
||||||
}
|
}
|
||||||
@@ -1796,7 +1794,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
self.monitors_mut()
|
self.monitors_mut()
|
||||||
.get_mut(idx)
|
.get_mut(idx)
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.update_focused_workspace(offset)
|
.update_focused_workspace(offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1812,7 +1810,7 @@ impl WindowManager {
|
|||||||
let first_monitor = self
|
let first_monitor = self
|
||||||
.monitors()
|
.monitors()
|
||||||
.get(first_idx)
|
.get(first_idx)
|
||||||
.ok_or_else(|| anyhow!("There is no monitor"))?;
|
.ok_or_eyre("There is no monitor")?;
|
||||||
first_monitor.focused_workspace_idx()
|
first_monitor.focused_workspace_idx()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1820,7 +1818,7 @@ impl WindowManager {
|
|||||||
let second_monitor = self
|
let second_monitor = self
|
||||||
.monitors()
|
.monitors()
|
||||||
.get(second_idx)
|
.get(second_idx)
|
||||||
.ok_or_else(|| anyhow!("There is no monitor"))?;
|
.ok_or_eyre("There is no monitor")?;
|
||||||
second_monitor.focused_workspace_idx()
|
second_monitor.focused_workspace_idx()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1829,24 +1827,24 @@ impl WindowManager {
|
|||||||
let first_workspaces = self
|
let first_workspaces = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(first_idx)
|
.get_mut(first_idx)
|
||||||
.ok_or_else(|| anyhow!("There is no monitor"))?
|
.ok_or_eyre("There is no monitor")?
|
||||||
.remove_workspaces();
|
.remove_workspaces();
|
||||||
|
|
||||||
let second_workspaces = self
|
let second_workspaces = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(second_idx)
|
.get_mut(second_idx)
|
||||||
.ok_or_else(|| anyhow!("There is no monitor"))?
|
.ok_or_eyre("There is no monitor")?
|
||||||
.remove_workspaces();
|
.remove_workspaces();
|
||||||
|
|
||||||
self.monitors_mut()
|
self.monitors_mut()
|
||||||
.get_mut(first_idx)
|
.get_mut(first_idx)
|
||||||
.ok_or_else(|| anyhow!("There is no monitor"))?
|
.ok_or_eyre("There is no monitor")?
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.extend(second_workspaces);
|
.extend(second_workspaces);
|
||||||
|
|
||||||
self.monitors_mut()
|
self.monitors_mut()
|
||||||
.get_mut(second_idx)
|
.get_mut(second_idx)
|
||||||
.ok_or_else(|| anyhow!("There is no monitor"))?
|
.ok_or_eyre("There is no monitor")?
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.extend(first_workspaces);
|
.extend(first_workspaces);
|
||||||
|
|
||||||
@@ -1904,13 +1902,13 @@ impl WindowManager {
|
|||||||
|
|
||||||
let monitor = self
|
let monitor = self
|
||||||
.focused_monitor_mut()
|
.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 current_area = *monitor.work_area_size();
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.focused_workspace_mut()
|
.focused_workspace_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
.ok_or_eyre("there is no workspace")?;
|
||||||
|
|
||||||
if workspace.maximized_window().is_some() {
|
if workspace.maximized_window().is_some() {
|
||||||
bail!("cannot move native maximized window to another monitor or workspace");
|
bail!("cannot move native maximized window to another monitor or workspace");
|
||||||
@@ -1928,7 +1926,7 @@ impl WindowManager {
|
|||||||
Some(
|
Some(
|
||||||
workspace
|
workspace
|
||||||
.remove_focused_container()
|
.remove_focused_container()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?,
|
.ok_or_eyre("there is no container")?,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -1938,7 +1936,7 @@ impl WindowManager {
|
|||||||
let target_monitor = self
|
let target_monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.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;
|
let mut should_load_workspace = false;
|
||||||
if let Some(workspace_idx) = workspace_idx {
|
if let Some(workspace_idx) = workspace_idx {
|
||||||
@@ -1949,7 +1947,7 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
let target_workspace = target_monitor
|
let target_workspace = target_monitor
|
||||||
.focused_workspace_mut()
|
.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() {
|
if target_workspace.monocle_container().is_some() {
|
||||||
for container in target_workspace.containers_mut() {
|
for container in target_workspace.containers_mut() {
|
||||||
@@ -2028,7 +2026,7 @@ impl WindowManager {
|
|||||||
let mouse_follows_focus = self.mouse_follows_focus;
|
let mouse_follows_focus = self.mouse_follows_focus;
|
||||||
let monitor = self
|
let monitor = self
|
||||||
.focused_monitor_mut()
|
.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.move_container_to_workspace(idx, follow, direction)?;
|
||||||
monitor.load_focused_workspace(mouse_follows_focus)?;
|
monitor.load_focused_workspace(mouse_follows_focus)?;
|
||||||
@@ -2059,13 +2057,13 @@ impl WindowManager {
|
|||||||
let offset = self.work_area_offset;
|
let offset = self.work_area_offset;
|
||||||
let workspace = self
|
let workspace = self
|
||||||
.remove_focused_workspace()
|
.remove_focused_workspace()
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
.ok_or_eyre("there is no workspace")?;
|
||||||
|
|
||||||
{
|
{
|
||||||
let target_monitor: &mut Monitor = self
|
let target_monitor: &mut Monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(idx)
|
.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.workspaces_mut().push_back(workspace);
|
||||||
target_monitor.update_workspaces_globals(offset);
|
target_monitor.update_workspaces_globals(offset);
|
||||||
@@ -2263,7 +2261,7 @@ impl WindowManager {
|
|||||||
// if there is no floating_window in that direction for this workspace
|
// if there is no floating_window in that direction for this workspace
|
||||||
let monitor_idx = self
|
let monitor_idx = self
|
||||||
.monitor_idx_in_direction(direction)
|
.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)?;
|
self.focus_monitor(monitor_idx)?;
|
||||||
let mouse_follows_focus = self.mouse_follows_focus;
|
let mouse_follows_focus = self.mouse_follows_focus;
|
||||||
@@ -2420,7 +2418,7 @@ impl WindowManager {
|
|||||||
None => {
|
None => {
|
||||||
let monitor_idx = self
|
let monitor_idx = self
|
||||||
.monitor_idx_in_direction(direction)
|
.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)?;
|
self.focus_monitor(monitor_idx)?;
|
||||||
let mouse_follows_focus = self.mouse_follows_focus;
|
let mouse_follows_focus = self.mouse_follows_focus;
|
||||||
@@ -2640,7 +2638,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let target_monitor_idx = self
|
let target_monitor_idx = self
|
||||||
.monitor_idx_in_direction(direction)
|
.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
|
// actually move the container to target monitor using the direction
|
||||||
@@ -2699,9 +2697,7 @@ impl WindowManager {
|
|||||||
.remove_container_by_idx(
|
.remove_container_by_idx(
|
||||||
target_workspace.focused_container_idx() + 1,
|
target_workspace.focused_container_idx() + 1,
|
||||||
)
|
)
|
||||||
.ok_or_else(|| {
|
.ok_or_eyre("could not remove container at given target index")?;
|
||||||
anyhow!("could not remove container at given target index")
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let origin_workspace =
|
let origin_workspace =
|
||||||
self.focused_workspace_for_monitor_idx_mut(origin_monitor_idx)?;
|
self.focused_workspace_for_monitor_idx_mut(origin_monitor_idx)?;
|
||||||
@@ -2720,17 +2716,17 @@ impl WindowManager {
|
|||||||
|
|
||||||
self.monitors_mut()
|
self.monitors_mut()
|
||||||
.get_mut(origin_monitor_idx)
|
.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)?;
|
.update_focused_workspace(offset)?;
|
||||||
|
|
||||||
let a = self
|
let a = self
|
||||||
.focused_monitor()
|
.focused_monitor()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor focused monitor"))?
|
.ok_or_eyre("there is no monitor focused monitor")?
|
||||||
.id();
|
.id();
|
||||||
let b = self
|
let b = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(origin_monitor_idx)
|
.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();
|
.id();
|
||||||
|
|
||||||
if !WindowsApi::monitors_have_same_dpi(a, b)? {
|
if !WindowsApi::monitors_have_same_dpi(a, b)? {
|
||||||
@@ -2819,7 +2815,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let new_idx = workspace
|
let new_idx = workspace
|
||||||
.new_idx_for_cycle_direction(direction)
|
.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);
|
workspace.focus_container(new_idx);
|
||||||
|
|
||||||
@@ -2848,7 +2844,7 @@ impl WindowManager {
|
|||||||
let current_idx = workspace.focused_container_idx();
|
let current_idx = workspace.focused_container_idx();
|
||||||
let new_idx = workspace
|
let new_idx = workspace
|
||||||
.new_idx_for_cycle_direction(direction)
|
.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.swap_containers(current_idx, new_idx);
|
||||||
workspace.focus_container(new_idx);
|
workspace.focus_container(new_idx);
|
||||||
@@ -2869,7 +2865,7 @@ impl WindowManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let len = NonZeroUsize::new(container.windows().len())
|
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 {
|
if len.get() == 1 {
|
||||||
bail!("there is only one window in this container");
|
bail!("there is only one window in this container");
|
||||||
@@ -2905,7 +2901,7 @@ impl WindowManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let len = NonZeroUsize::new(container.windows().len())
|
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 {
|
if len.get() == 1 {
|
||||||
bail!("there is only one window in this container");
|
bail!("there is only one window in this container");
|
||||||
@@ -2938,7 +2934,7 @@ impl WindowManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let len = NonZeroUsize::new(container.windows().len())
|
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 {
|
if len.get() == 1 && idx != 0 {
|
||||||
bail!("there is only one window in this container");
|
bail!("there is only one window in this container");
|
||||||
@@ -3033,7 +3029,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let workspace = self.focused_workspace_mut()?;
|
let workspace = self.focused_workspace_mut()?;
|
||||||
let len = NonZeroUsize::new(workspace.containers_mut().len())
|
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 current_container_idx = workspace.focused_container_idx();
|
||||||
|
|
||||||
let is_valid = direction
|
let is_valid = direction
|
||||||
@@ -3046,9 +3042,9 @@ impl WindowManager {
|
|||||||
.is_some();
|
.is_some();
|
||||||
|
|
||||||
if is_valid {
|
if is_valid {
|
||||||
let new_idx = workspace.new_idx_for_direction(direction).ok_or_else(|| {
|
let new_idx = workspace
|
||||||
anyhow!("this is not a valid direction from the current position")
|
.new_idx_for_direction(direction)
|
||||||
})?;
|
.ok_or_eyre("this is not a valid direction from the current position")?;
|
||||||
|
|
||||||
let mut changed_focus = false;
|
let mut changed_focus = false;
|
||||||
|
|
||||||
@@ -3213,7 +3209,7 @@ impl WindowManager {
|
|||||||
let window = workspace
|
let window = workspace
|
||||||
.floating_windows_mut()
|
.floating_windows_mut()
|
||||||
.back_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() {
|
if toggle_float_placement.should_center() {
|
||||||
window.center(&work_area, toggle_float_placement.should_resize())?;
|
window.center(&work_area, toggle_float_placement.should_resize())?;
|
||||||
@@ -3371,10 +3367,11 @@ impl WindowManager {
|
|||||||
match workspace.layout() {
|
match workspace.layout() {
|
||||||
Layout::Default(_) => {}
|
Layout::Default(_) => {}
|
||||||
Layout::Custom(layout) => {
|
Layout::Custom(layout) => {
|
||||||
let primary_idx =
|
let primary_idx = layout.first_container_idx(
|
||||||
layout.first_container_idx(layout.primary_idx().ok_or_else(|| {
|
layout
|
||||||
anyhow!("this custom layout does not have a primary column")
|
.primary_idx()
|
||||||
})?);
|
.ok_or_eyre("this custom layout does not have a primary column")?,
|
||||||
|
);
|
||||||
|
|
||||||
if !workspace.containers().is_empty() && primary_idx < workspace.containers().len()
|
if !workspace.containers().is_empty() && primary_idx < workspace.containers().len()
|
||||||
{
|
{
|
||||||
@@ -3422,10 +3419,11 @@ impl WindowManager {
|
|||||||
|
|
||||||
match workspace.layout() {
|
match workspace.layout() {
|
||||||
Layout::Default(_) => {
|
Layout::Default(_) => {
|
||||||
let primary_idx =
|
let primary_idx = layout.first_container_idx(
|
||||||
layout.first_container_idx(layout.primary_idx().ok_or_else(|| {
|
layout
|
||||||
anyhow!("this custom layout does not have a primary column")
|
.primary_idx()
|
||||||
})?);
|
.ok_or_eyre("this custom layout does not have a primary column")?,
|
||||||
|
);
|
||||||
|
|
||||||
if !workspace.containers().is_empty() && primary_idx < workspace.containers().len()
|
if !workspace.containers().is_empty() && primary_idx < workspace.containers().len()
|
||||||
{
|
{
|
||||||
@@ -3448,7 +3446,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let padding = workspace
|
let padding = workspace
|
||||||
.workspace_padding()
|
.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)));
|
workspace.set_workspace_padding(Option::from(sizing.adjust_by(padding, adjustment)));
|
||||||
|
|
||||||
@@ -3463,7 +3461,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let padding = workspace
|
let padding = workspace
|
||||||
.container_padding()
|
.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)));
|
workspace.set_container_padding(Option::from(sizing.adjust_by(padding, adjustment)));
|
||||||
|
|
||||||
@@ -3480,12 +3478,12 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
.ok_or_eyre("there is no monitor")?;
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.get_mut(workspace_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
.ok_or_eyre("there is no monitor")?;
|
||||||
|
|
||||||
workspace.set_tile(tile);
|
workspace.set_tile(tile);
|
||||||
|
|
||||||
@@ -3507,14 +3505,14 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.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 focused_workspace_idx = monitor.focused_workspace_idx();
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.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();
|
let rules: &mut Vec<(usize, Layout)> = workspace.layout_rules_mut();
|
||||||
rules.retain(|pair| pair.0 != at_container_count);
|
rules.retain(|pair| pair.0 != at_container_count);
|
||||||
@@ -3548,14 +3546,14 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.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 focused_workspace_idx = monitor.focused_workspace_idx();
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.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)?;
|
let layout = CustomLayout::from_path(path)?;
|
||||||
|
|
||||||
@@ -3586,14 +3584,14 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.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 focused_workspace_idx = monitor.focused_workspace_idx();
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.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();
|
let rules: &mut Vec<(usize, Layout)> = workspace.layout_rules_mut();
|
||||||
rules.clear();
|
rules.clear();
|
||||||
@@ -3621,14 +3619,14 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.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 focused_workspace_idx = monitor.focused_workspace_idx();
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.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));
|
workspace.set_layout(Layout::Default(layout));
|
||||||
|
|
||||||
@@ -3658,14 +3656,14 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.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 focused_workspace_idx = monitor.focused_workspace_idx();
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.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(Layout::Custom(layout));
|
||||||
workspace.set_layout_flip(None);
|
workspace.set_layout_flip(None);
|
||||||
@@ -3690,7 +3688,7 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.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);
|
monitor.ensure_workspace_count(workspace_count);
|
||||||
|
|
||||||
@@ -3708,7 +3706,7 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.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());
|
monitor.ensure_workspace_count(names.len());
|
||||||
|
|
||||||
@@ -3733,12 +3731,12 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
.ok_or_eyre("there is no monitor")?;
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.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));
|
workspace.set_workspace_padding(Option::from(size));
|
||||||
|
|
||||||
@@ -3757,12 +3755,12 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
.ok_or_eyre("there is no monitor")?;
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.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()));
|
workspace.set_name(Option::from(name.clone()));
|
||||||
monitor.workspace_names_mut().insert(workspace_idx, name);
|
monitor.workspace_names_mut().insert(workspace_idx, name);
|
||||||
@@ -3782,12 +3780,12 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
.ok_or_eyre("there is no monitor")?;
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.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));
|
workspace.set_container_padding(Option::from(size));
|
||||||
|
|
||||||
@@ -3797,14 +3795,14 @@ impl WindowManager {
|
|||||||
pub fn focused_monitor_size(&self) -> Result<Rect> {
|
pub fn focused_monitor_size(&self) -> Result<Rect> {
|
||||||
Ok(*self
|
Ok(*self
|
||||||
.focused_monitor()
|
.focused_monitor()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.size())
|
.size())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focused_monitor_work_area(&self) -> Result<Rect> {
|
pub fn focused_monitor_work_area(&self) -> Result<Rect> {
|
||||||
Ok(*self
|
Ok(*self
|
||||||
.focused_monitor()
|
.focused_monitor()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.work_area_size())
|
.work_area_size())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3870,46 +3868,46 @@ impl WindowManager {
|
|||||||
pub fn focused_workspace_idx(&self) -> Result<usize> {
|
pub fn focused_workspace_idx(&self) -> Result<usize> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.focused_monitor()
|
.focused_monitor()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.focused_workspace_idx())
|
.focused_workspace_idx())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focused_workspace(&self) -> Result<&Workspace> {
|
pub fn focused_workspace(&self) -> Result<&Workspace> {
|
||||||
self.focused_monitor()
|
self.focused_monitor()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.focused_workspace()
|
.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> {
|
pub fn focused_workspace_mut(&mut self) -> Result<&mut Workspace> {
|
||||||
self.focused_monitor_mut()
|
self.focused_monitor_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no monitor"))?
|
.ok_or_eyre("there is no monitor")?
|
||||||
.focused_workspace_mut()
|
.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> {
|
pub fn focused_workspace_idx_for_monitor_idx(&self, idx: usize) -> Result<usize> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.monitors()
|
.monitors()
|
||||||
.get(idx)
|
.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())
|
.focused_workspace_idx())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focused_workspace_for_monitor_idx(&self, idx: usize) -> Result<&Workspace> {
|
pub fn focused_workspace_for_monitor_idx(&self, idx: usize) -> Result<&Workspace> {
|
||||||
self.monitors()
|
self.monitors()
|
||||||
.get(idx)
|
.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()
|
.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> {
|
pub fn focused_workspace_for_monitor_idx_mut(&mut self, idx: usize) -> Result<&mut Workspace> {
|
||||||
self.monitors_mut()
|
self.monitors_mut()
|
||||||
.get_mut(idx)
|
.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()
|
.focused_workspace_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))
|
.ok_or_eyre("there is no workspace")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
@@ -3919,7 +3917,7 @@ impl WindowManager {
|
|||||||
let mouse_follows_focus = self.mouse_follows_focus;
|
let mouse_follows_focus = self.mouse_follows_focus;
|
||||||
let monitor = self
|
let monitor = self
|
||||||
.focused_monitor_mut()
|
.focused_monitor_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
.ok_or_eyre("there is no workspace")?;
|
||||||
|
|
||||||
monitor.focus_workspace(idx)?;
|
monitor.focus_workspace(idx)?;
|
||||||
monitor.load_focused_workspace(mouse_follows_focus)?;
|
monitor.load_focused_workspace(mouse_follows_focus)?;
|
||||||
@@ -3951,7 +3949,7 @@ impl WindowManager {
|
|||||||
let mouse_follows_focus = self.mouse_follows_focus;
|
let mouse_follows_focus = self.mouse_follows_focus;
|
||||||
let monitor = self
|
let monitor = self
|
||||||
.focused_monitor_mut()
|
.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.focus_workspace(monitor.new_workspace_idx())?;
|
||||||
monitor.load_focused_workspace(mouse_follows_focus)?;
|
monitor.load_focused_workspace(mouse_follows_focus)?;
|
||||||
@@ -3962,7 +3960,7 @@ impl WindowManager {
|
|||||||
pub fn focused_container(&self) -> Result<&Container> {
|
pub fn focused_container(&self) -> Result<&Container> {
|
||||||
self.focused_workspace()?
|
self.focused_workspace()?
|
||||||
.focused_container()
|
.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> {
|
pub fn focused_container_idx(&self) -> Result<usize> {
|
||||||
@@ -3972,19 +3970,19 @@ impl WindowManager {
|
|||||||
pub fn focused_container_mut(&mut self) -> Result<&mut Container> {
|
pub fn focused_container_mut(&mut self) -> Result<&mut Container> {
|
||||||
self.focused_workspace_mut()?
|
self.focused_workspace_mut()?
|
||||||
.focused_container_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> {
|
pub fn focused_window(&self) -> Result<&Window> {
|
||||||
self.focused_container()?
|
self.focused_container()?
|
||||||
.focused_window()
|
.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> {
|
fn focused_window_mut(&mut self) -> Result<&mut Window> {
|
||||||
self.focused_container_mut()?
|
self.focused_container_mut()?
|
||||||
.focused_window_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
|
/// Updates the list of `known_hwnds` and their monitor/workspace index pair
|
||||||
|
|||||||
+11
-10
@@ -1,6 +1,6 @@
|
|||||||
use color_eyre::eyre::anyhow;
|
|
||||||
use color_eyre::eyre::bail;
|
use color_eyre::eyre::bail;
|
||||||
use color_eyre::eyre::Error;
|
use color_eyre::eyre::Error;
|
||||||
|
use color_eyre::eyre::OptionExt;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use core::ffi::c_void;
|
use core::ffi::c_void;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -663,10 +663,11 @@ impl WindowsApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn close_window(hwnd: isize) -> Result<()> {
|
pub fn close_window(hwnd: isize) -> Result<()> {
|
||||||
match Self::post_message(HWND(as_ptr!(hwnd)), WM_CLOSE, WPARAM(0), LPARAM(0)) {
|
if Self::post_message(HWND(as_ptr!(hwnd)), WM_CLOSE, WPARAM(0), LPARAM(0)).is_err() {
|
||||||
Ok(()) => Ok(()),
|
bail!("could not close window");
|
||||||
Err(_) => Err(anyhow!("could not close window")),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hide_window(hwnd: isize) {
|
pub fn hide_window(hwnd: isize) {
|
||||||
@@ -753,7 +754,7 @@ impl WindowsApi {
|
|||||||
next_hwnd = Self::next_window(next_hwnd)?;
|
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> {
|
pub fn window_rect(hwnd: isize) -> Result<Rect> {
|
||||||
@@ -857,12 +858,12 @@ impl WindowsApi {
|
|||||||
let mut session_id = 0;
|
let mut session_id = 0;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if ProcessIdToSessionId(process_id, &mut session_id).is_ok() {
|
if ProcessIdToSessionId(process_id, &mut session_id).is_err() {
|
||||||
Ok(session_id)
|
bail!("could not determine current session id")
|
||||||
} else {
|
|
||||||
Err(anyhow!("could not determine current session id"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(session_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
@@ -991,7 +992,7 @@ impl WindowsApi {
|
|||||||
Ok(Self::exe_path(handle)?
|
Ok(Self::exe_path(handle)?
|
||||||
.split('\\')
|
.split('\\')
|
||||||
.next_back()
|
.next_back()
|
||||||
.ok_or_else(|| anyhow!("there is no last element"))?
|
.ok_or_eyre("there is no last element")?
|
||||||
.to_string())
|
.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+35
-37
@@ -37,7 +37,7 @@ use crate::INITIAL_CONFIGURATION_LOADED;
|
|||||||
use crate::NO_TITLEBAR;
|
use crate::NO_TITLEBAR;
|
||||||
use crate::REGEX_IDENTIFIERS;
|
use crate::REGEX_IDENTIFIERS;
|
||||||
use crate::REMOVE_TITLEBARS;
|
use crate::REMOVE_TITLEBARS;
|
||||||
use color_eyre::eyre::anyhow;
|
use color_eyre::eyre::OptionExt;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use getset::CopyGetters;
|
use getset::CopyGetters;
|
||||||
use getset::Getters;
|
use getset::Getters;
|
||||||
@@ -579,11 +579,9 @@ impl Workspace {
|
|||||||
} else if !self.containers().is_empty() {
|
} else if !self.containers().is_empty() {
|
||||||
let mut layouts = self.layout().as_boxed_arrangement().calculate(
|
let mut layouts = self.layout().as_boxed_arrangement().calculate(
|
||||||
&adjusted_work_area,
|
&adjusted_work_area,
|
||||||
NonZeroUsize::new(self.containers().len()).ok_or_else(|| {
|
NonZeroUsize::new(self.containers().len()).ok_or_eyre(
|
||||||
anyhow!(
|
"there must be at least one container to calculate a workspace layout",
|
||||||
"there must be at least one container to calculate a workspace layout"
|
)?,
|
||||||
)
|
|
||||||
})?,
|
|
||||||
Some(container_padding),
|
Some(container_padding),
|
||||||
self.layout_flip(),
|
self.layout_flip(),
|
||||||
self.resize_dimensions(),
|
self.resize_dimensions(),
|
||||||
@@ -677,16 +675,16 @@ impl Workspace {
|
|||||||
pub fn focus_container_by_window(&mut self, hwnd: isize) -> Result<()> {
|
pub fn focus_container_by_window(&mut self, hwnd: isize) -> Result<()> {
|
||||||
let container_idx = self
|
let container_idx = self
|
||||||
.container_idx_for_window(hwnd)
|
.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
|
let container = self
|
||||||
.containers_mut()
|
.containers_mut()
|
||||||
.get_mut(container_idx)
|
.get_mut(container_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?;
|
.ok_or_eyre("there is no container")?;
|
||||||
|
|
||||||
let window_idx = container
|
let window_idx = container
|
||||||
.idx_for_window(hwnd)
|
.idx_for_window(hwnd)
|
||||||
.ok_or_else(|| anyhow!("there is no window"))?;
|
.ok_or_eyre("there is no window")?;
|
||||||
|
|
||||||
let mut should_load = false;
|
let mut should_load = false;
|
||||||
|
|
||||||
@@ -866,14 +864,14 @@ impl Workspace {
|
|||||||
let resize = self.resize_dimensions_mut().remove(0);
|
let resize = self.resize_dimensions_mut().remove(0);
|
||||||
let container = self
|
let container = self
|
||||||
.remove_focused_container()
|
.remove_focused_container()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?;
|
.ok_or_eyre("there is no container")?;
|
||||||
|
|
||||||
let primary_idx = match self.layout() {
|
let primary_idx = match self.layout() {
|
||||||
Layout::Default(_) => 0,
|
Layout::Default(_) => 0,
|
||||||
Layout::Custom(layout) => layout.first_container_idx(
|
Layout::Custom(layout) => layout.first_container_idx(
|
||||||
layout
|
layout
|
||||||
.primary_idx()
|
.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
|
container
|
||||||
.remove_window_by_idx(window_idx)
|
.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() {
|
if container.windows().is_empty() {
|
||||||
self.set_monocle_container(None);
|
self.set_monocle_container(None);
|
||||||
@@ -977,22 +975,22 @@ impl Workspace {
|
|||||||
|
|
||||||
let container_idx = self
|
let container_idx = self
|
||||||
.container_idx_for_window(hwnd)
|
.container_idx_for_window(hwnd)
|
||||||
.ok_or_else(|| anyhow!("there is no window"))?;
|
.ok_or_eyre("there is no window")?;
|
||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.containers_mut()
|
.containers_mut()
|
||||||
.get_mut(container_idx)
|
.get_mut(container_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?;
|
.ok_or_eyre("there is no container")?;
|
||||||
|
|
||||||
let window_idx = container
|
let window_idx = container
|
||||||
.windows()
|
.windows()
|
||||||
.iter()
|
.iter()
|
||||||
.position(|window| window.hwnd == hwnd)
|
.position(|window| window.hwnd == hwnd)
|
||||||
.ok_or_else(|| anyhow!("there is no window"))?;
|
.ok_or_eyre("there is no window")?;
|
||||||
|
|
||||||
container
|
container
|
||||||
.remove_window_by_idx(window_idx)
|
.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() {
|
if container.windows().is_empty() {
|
||||||
self.remove_container_by_idx(container_idx);
|
self.remove_container_by_idx(container_idx);
|
||||||
@@ -1046,11 +1044,11 @@ impl Workspace {
|
|||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.focused_container_mut()
|
.focused_container_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?;
|
.ok_or_eyre("there is no container")?;
|
||||||
|
|
||||||
let window = container
|
let window = container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.ok_or_else(|| anyhow!("there is no window"))?;
|
.ok_or_eyre("there is no window")?;
|
||||||
|
|
||||||
// This is a little messy
|
// This is a little messy
|
||||||
let adjusted_target_container_index = if container.windows().is_empty() {
|
let adjusted_target_container_index = if container.windows().is_empty() {
|
||||||
@@ -1069,13 +1067,13 @@ impl Workspace {
|
|||||||
let target_container = self
|
let target_container = self
|
||||||
.containers_mut()
|
.containers_mut()
|
||||||
.get_mut(adjusted_target_container_index)
|
.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);
|
target_container.add_window(window);
|
||||||
|
|
||||||
self.focus_container(adjusted_target_container_index);
|
self.focus_container(adjusted_target_container_index);
|
||||||
self.focused_container_mut()
|
self.focused_container_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?
|
.ok_or_eyre("there is no container")?
|
||||||
.load_focused_window();
|
.load_focused_window();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1086,11 +1084,11 @@ impl Workspace {
|
|||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.focused_container_mut()
|
.focused_container_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?;
|
.ok_or_eyre("there is no container")?;
|
||||||
|
|
||||||
let window = container
|
let window = container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.ok_or_else(|| anyhow!("there is no window"))?;
|
.ok_or_eyre("there is no window")?;
|
||||||
|
|
||||||
if container.windows().is_empty() {
|
if container.windows().is_empty() {
|
||||||
self.remove_container_by_idx(focused_container_idx);
|
self.remove_container_by_idx(focused_container_idx);
|
||||||
@@ -1109,7 +1107,7 @@ impl Workspace {
|
|||||||
let focused_idx = self.focused_container_idx();
|
let focused_idx = self.focused_container_idx();
|
||||||
let window = self
|
let window = self
|
||||||
.remove_focused_floating_window()
|
.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();
|
let mut container = Container::default();
|
||||||
container.add_window(window);
|
container.add_window(window);
|
||||||
@@ -1141,7 +1139,7 @@ impl Workspace {
|
|||||||
} else if let Some(monocle_container) = self.monocle_container_mut() {
|
} else if let Some(monocle_container) = self.monocle_container_mut() {
|
||||||
let window = monocle_container
|
let window = monocle_container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.ok_or_else(|| anyhow!("there is no window"))?;
|
.ok_or_eyre("there is no window")?;
|
||||||
|
|
||||||
if monocle_container.windows().is_empty() {
|
if monocle_container.windows().is_empty() {
|
||||||
self.set_monocle_container(None);
|
self.set_monocle_container(None);
|
||||||
@@ -1156,11 +1154,11 @@ impl Workspace {
|
|||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.focused_container_mut()
|
.focused_container_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?;
|
.ok_or_eyre("there is no container")?;
|
||||||
|
|
||||||
let window = container
|
let window = container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.ok_or_else(|| anyhow!("there is no window"))?;
|
.ok_or_eyre("there is no window")?;
|
||||||
|
|
||||||
if container.windows().is_empty() {
|
if container.windows().is_empty() {
|
||||||
self.remove_container_by_idx(focused_idx);
|
self.remove_container_by_idx(focused_idx);
|
||||||
@@ -1467,7 +1465,7 @@ impl Workspace {
|
|||||||
let container = self
|
let container = self
|
||||||
.containers_mut()
|
.containers_mut()
|
||||||
.remove(focused_idx)
|
.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
|
// 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
|
// 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()
|
self.monocle_container_mut()
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no monocle container"))?
|
.ok_or_eyre("there is no monocle container")?
|
||||||
.load_focused_window();
|
.load_focused_window();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1488,12 +1486,12 @@ impl Workspace {
|
|||||||
pub fn reintegrate_monocle_container(&mut self) -> Result<()> {
|
pub fn reintegrate_monocle_container(&mut self) -> Result<()> {
|
||||||
let restore_idx = self
|
let restore_idx = self
|
||||||
.monocle_container_restore_idx()
|
.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
|
let container = self
|
||||||
.monocle_container_mut()
|
.monocle_container_mut()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or_else(|| anyhow!("there is no monocle container"))?;
|
.ok_or_eyre("there is no monocle container")?;
|
||||||
|
|
||||||
let container = container.clone();
|
let container = container.clone();
|
||||||
if restore_idx >= self.containers().len() {
|
if restore_idx >= self.containers().len() {
|
||||||
@@ -1507,7 +1505,7 @@ impl Workspace {
|
|||||||
self.containers_mut().insert(restore_idx, container);
|
self.containers_mut().insert(restore_idx, container);
|
||||||
self.focus_container(restore_idx);
|
self.focus_container(restore_idx);
|
||||||
self.focused_container_mut()
|
self.focused_container_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?
|
.ok_or_eyre("there is no container")?
|
||||||
.load_focused_window();
|
.load_focused_window();
|
||||||
|
|
||||||
self.set_monocle_container(None);
|
self.set_monocle_container(None);
|
||||||
@@ -1535,7 +1533,7 @@ impl Workspace {
|
|||||||
if let Some(monocle_container) = self.monocle_container_mut() {
|
if let Some(monocle_container) = self.monocle_container_mut() {
|
||||||
let window = monocle_container
|
let window = monocle_container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.ok_or_else(|| anyhow!("there is no window"))?;
|
.ok_or_eyre("there is no window")?;
|
||||||
|
|
||||||
if monocle_container.windows().is_empty() {
|
if monocle_container.windows().is_empty() {
|
||||||
self.set_monocle_container(None);
|
self.set_monocle_container(None);
|
||||||
@@ -1555,11 +1553,11 @@ impl Workspace {
|
|||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.focused_container_mut()
|
.focused_container_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?;
|
.ok_or_eyre("there is no container")?;
|
||||||
|
|
||||||
let window = container
|
let window = container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.ok_or_else(|| anyhow!("there is no window"))?;
|
.ok_or_eyre("there is no window")?;
|
||||||
|
|
||||||
if container.windows().is_empty() {
|
if container.windows().is_empty() {
|
||||||
// we shouldn't use remove_container_by_idx here because it doesn't make sense for
|
// 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<()> {
|
pub fn reintegrate_maximized_window(&mut self) -> Result<()> {
|
||||||
let restore_idx = self
|
let restore_idx = self
|
||||||
.maximized_window_restore_idx()
|
.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
|
let window = self
|
||||||
.maximized_window()
|
.maximized_window()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or_else(|| anyhow!("there is no monocle container"))?;
|
.ok_or_eyre("there is no monocle container")?;
|
||||||
|
|
||||||
let window = *window;
|
let window = *window;
|
||||||
if !self.containers().is_empty() && restore_idx > self.containers().len().saturating_sub(1)
|
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.focus_container(restore_idx);
|
||||||
|
|
||||||
self.focused_container_mut()
|
self.focused_container_mut()
|
||||||
.ok_or_else(|| anyhow!("there is no container"))?
|
.ok_or_eyre("there is no container")?
|
||||||
.load_focused_window();
|
.load_focused_window();
|
||||||
|
|
||||||
self.set_maximized_window(None);
|
self.set_maximized_window(None);
|
||||||
|
|||||||
+20
-19
@@ -20,8 +20,8 @@ use std::time::Duration;
|
|||||||
use clap::CommandFactory;
|
use clap::CommandFactory;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use color_eyre::eyre::anyhow;
|
|
||||||
use color_eyre::eyre::bail;
|
use color_eyre::eyre::bail;
|
||||||
|
use color_eyre::eyre::OptionExt;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use dirs::data_local_dir;
|
use dirs::data_local_dir;
|
||||||
use fs_tail::TailedFile;
|
use fs_tail::TailedFile;
|
||||||
@@ -2181,25 +2181,26 @@ fn main() -> Result<()> {
|
|||||||
let mut buf: PathBuf;
|
let mut buf: PathBuf;
|
||||||
|
|
||||||
// The komorebi.ps1 shim will only exist in the Path if installed by Scoop
|
// 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 exec =
|
||||||
let stdout = String::from_utf8(output.stdout)?;
|
if let Ok(output) = Command::new("where.exe").arg("komorebi.ps1").output() {
|
||||||
match stdout.trim() {
|
let stdout = String::from_utf8(output.stdout)?;
|
||||||
"" => None,
|
match stdout.trim() {
|
||||||
// It's possible that a komorebi.ps1 config will be in %USERPROFILE% - ignore this
|
"" => None,
|
||||||
stdout if !stdout.contains("scoop") => None,
|
// It's possible that a komorebi.ps1 config will be in %USERPROFILE% - ignore this
|
||||||
stdout => {
|
stdout if !stdout.contains("scoop") => None,
|
||||||
buf = PathBuf::from(stdout);
|
stdout => {
|
||||||
buf.pop(); // %USERPROFILE%\scoop\shims
|
buf = PathBuf::from(stdout);
|
||||||
buf.pop(); // %USERPROFILE%\scoop
|
buf.pop(); // %USERPROFILE%\scoop\shims
|
||||||
buf.push("apps\\komorebi\\current\\komorebi.exe"); //%USERPROFILE%\scoop\komorebi\current\komorebi.exe
|
buf.pop(); // %USERPROFILE%\scoop
|
||||||
Some(buf.to_str().ok_or_else(|| {
|
buf.push("apps\\komorebi\\current\\komorebi.exe"); //%USERPROFILE%\scoop\komorebi\current\komorebi.exe
|
||||||
anyhow!("cannot create a string from the scoop komorebi path")
|
Some(buf.to_str().ok_or_eyre(
|
||||||
})?)
|
"cannot create a string from the scoop komorebi path",
|
||||||
|
)?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
None
|
||||||
None
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let mut flags = vec![];
|
let mut flags = vec![];
|
||||||
if let Some(config) = &arg.config {
|
if let Some(config) = &arg.config {
|
||||||
|
|||||||
Reference in New Issue
Block a user