mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-09 14:42:44 +02:00
refactor(eyre): handle options with combinators
This commit removes the unnecessary eyre dependency and instead uses the relevant imports from color-eyre. Additionally, after reading the eyre readme a little more closely, I have switched out .compat() for the ok_or() combinator function as suggested here: https://github.com/yaahc/eyre#compatibility-with-anyhow.
This commit is contained in:
Generated
+2
-3
@@ -514,7 +514,6 @@ dependencies = [
|
|||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
"ctrlc",
|
"ctrlc",
|
||||||
"dirs",
|
"dirs",
|
||||||
"eyre",
|
|
||||||
"getset",
|
"getset",
|
||||||
"hotwatch",
|
"hotwatch",
|
||||||
"komorebi-core",
|
"komorebi-core",
|
||||||
@@ -1177,9 +1176,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sysinfo"
|
name = "sysinfo"
|
||||||
version = "0.20.0"
|
version = "0.20.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0af066e6272f2175c1783cfc2ebf3e2d8dfe2c182b00677fdeccbf8291af83fb"
|
checksum = "4786f320388e6031aa78c68455553f4e3425deeeb40565fecba3d101c1faf21f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"core-foundation-sys",
|
"core-foundation-sys",
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ crossbeam-channel = "0.5"
|
|||||||
crossbeam-utils = "0.8"
|
crossbeam-utils = "0.8"
|
||||||
ctrlc = "3"
|
ctrlc = "3"
|
||||||
dirs = "3"
|
dirs = "3"
|
||||||
eyre = "0.6"
|
|
||||||
getset = "0.1"
|
getset = "0.1"
|
||||||
hotwatch = "0.4"
|
hotwatch = "0.4"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use std::thread;
|
|||||||
#[cfg(feature = "deadlock_detection")]
|
#[cfg(feature = "deadlock_detection")]
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use color_eyre::eyre::ContextCompat;
|
use color_eyre::eyre::anyhow;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossbeam_channel::Receiver;
|
use crossbeam_channel::Receiver;
|
||||||
use crossbeam_channel::Sender;
|
use crossbeam_channel::Sender;
|
||||||
@@ -82,7 +82,7 @@ fn setup() -> Result<(WorkerGuard, WorkerGuard)> {
|
|||||||
std::env::set_var("RUST_LOG", "info");
|
std::env::set_var("RUST_LOG", "info");
|
||||||
}
|
}
|
||||||
|
|
||||||
let home = dirs::home_dir().context("there is no home directory")?;
|
let home = dirs::home_dir().ok_or_else(|| anyhow!("there is no home directory"))?;
|
||||||
let appender = tracing_appender::rolling::never(home, "komorebi.log");
|
let appender = tracing_appender::rolling::never(home, "komorebi.log");
|
||||||
let color_appender = tracing_appender::rolling::never(std::env::temp_dir(), "komorebi.log");
|
let color_appender = tracing_appender::rolling::never(std::env::temp_dir(), "komorebi.log");
|
||||||
let (non_blocking, guard) = tracing_appender::non_blocking(appender);
|
let (non_blocking, guard) = tracing_appender::non_blocking(appender);
|
||||||
@@ -133,7 +133,7 @@ fn setup() -> Result<(WorkerGuard, WorkerGuard)> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_configuration() -> Result<()> {
|
pub fn load_configuration() -> Result<()> {
|
||||||
let home = dirs::home_dir().context("there is no home directory")?;
|
let home = dirs::home_dir().ok_or_else(|| anyhow!("there is no home directory"))?;
|
||||||
|
|
||||||
let mut config_v1 = home.clone();
|
let mut config_v1 = home.clone();
|
||||||
config_v1.push("komorebi.ahk");
|
config_v1.push("komorebi.ahk");
|
||||||
@@ -147,7 +147,7 @@ pub fn load_configuration() -> Result<()> {
|
|||||||
config_v1
|
config_v1
|
||||||
.as_os_str()
|
.as_os_str()
|
||||||
.to_str()
|
.to_str()
|
||||||
.context("cannot convert path to string")?
|
.ok_or_else(|| anyhow!("cannot convert path to string"))?
|
||||||
);
|
);
|
||||||
|
|
||||||
Command::new("autohotkey.exe")
|
Command::new("autohotkey.exe")
|
||||||
@@ -159,7 +159,7 @@ pub fn load_configuration() -> Result<()> {
|
|||||||
config_v2
|
config_v2
|
||||||
.as_os_str()
|
.as_os_str()
|
||||||
.to_str()
|
.to_str()
|
||||||
.context("cannot convert path to string")?
|
.ok_or_else(|| anyhow!("cannot convert path to string"))?
|
||||||
);
|
);
|
||||||
|
|
||||||
Command::new("AutoHotkey64.exe")
|
Command::new("AutoHotkey64.exe")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use color_eyre::eyre::ContextCompat;
|
use color_eyre::eyre::anyhow;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use getset::CopyGetters;
|
use getset::CopyGetters;
|
||||||
use getset::Getters;
|
use getset::Getters;
|
||||||
@@ -56,7 +56,7 @@ impl Monitor {
|
|||||||
pub fn add_container(&mut self, container: Container) -> Result<()> {
|
pub fn add_container(&mut self, container: Container) -> Result<()> {
|
||||||
let workspace = self
|
let workspace = self
|
||||||
.focused_workspace_mut()
|
.focused_workspace_mut()
|
||||||
.context("there is no workspace")?;
|
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
||||||
|
|
||||||
workspace.add_container(container);
|
workspace.add_container(container);
|
||||||
|
|
||||||
@@ -78,17 +78,17 @@ impl Monitor {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let workspace = self
|
let workspace = self
|
||||||
.focused_workspace_mut()
|
.focused_workspace_mut()
|
||||||
.context("there is no workspace")?;
|
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
||||||
|
|
||||||
if workspace.maximized_window().is_some() {
|
if workspace.maximized_window().is_some() {
|
||||||
return Err(eyre::anyhow!(
|
return Err(anyhow!(
|
||||||
"cannot move native maximized window to another monitor or workspace"
|
"cannot move native maximized window to another monitor or workspace"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = workspace
|
let container = workspace
|
||||||
.remove_focused_container()
|
.remove_focused_container()
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("there is no container"))?;
|
||||||
|
|
||||||
let workspaces = self.workspaces_mut();
|
let workspaces = self.workspaces_mut();
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ impl Monitor {
|
|||||||
if name.is_some() {
|
if name.is_some() {
|
||||||
self.workspaces_mut()
|
self.workspaces_mut()
|
||||||
.get_mut(idx)
|
.get_mut(idx)
|
||||||
.context("there is no workspace")?
|
.ok_or_else(|| anyhow!("there is no workspace"))?
|
||||||
.set_name(name);
|
.set_name(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ impl Monitor {
|
|||||||
let work_area = *self.work_area_size();
|
let work_area = *self.work_area_size();
|
||||||
|
|
||||||
self.focused_workspace_mut()
|
self.focused_workspace_mut()
|
||||||
.context("there is no workspace")?
|
.ok_or_else(|| anyhow!("there is no workspace"))?
|
||||||
.update(&work_area)?;
|
.update(&work_area)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::str::FromStr;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use color_eyre::eyre::ContextCompat;
|
use color_eyre::eyre::anyhow;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use uds_windows::UnixStream;
|
use uds_windows::UnixStream;
|
||||||
@@ -122,7 +122,7 @@ impl WindowManager {
|
|||||||
let work_area = *monitor.work_area_size();
|
let work_area = *monitor.work_area_size();
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.focused_workspace_mut()
|
.focused_workspace_mut()
|
||||||
.context("there is no workspace")?;
|
.ok_or_else(|| anyhow!("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
|
||||||
for resize in workspace.resize_dimensions_mut() {
|
for resize in workspace.resize_dimensions_mut() {
|
||||||
@@ -161,7 +161,8 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
SocketMessage::State => {
|
SocketMessage::State => {
|
||||||
let state = serde_json::to_string_pretty(&window_manager::State::from(self))?;
|
let state = serde_json::to_string_pretty(&window_manager::State::from(self))?;
|
||||||
let mut socket = dirs::home_dir().context("there is no home directory")?;
|
let mut socket =
|
||||||
|
dirs::home_dir().ok_or_else(|| anyhow!("there is no home directory"))?;
|
||||||
socket.push("komorebic.sock");
|
socket.push("komorebic.sock");
|
||||||
let socket = socket.as_path();
|
let socket = socket.as_path();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::fs::OpenOptions;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use color_eyre::eyre::ContextCompat;
|
use color_eyre::eyre::anyhow;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossbeam_channel::select;
|
use crossbeam_channel::select;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@@ -57,7 +57,7 @@ impl WindowManager {
|
|||||||
| WindowManagerEvent::MoveResizeEnd(_, window) => {
|
| WindowManagerEvent::MoveResizeEnd(_, window) => {
|
||||||
let monitor_idx = self
|
let monitor_idx = self
|
||||||
.monitor_idx_from_window(*window)
|
.monitor_idx_from_window(*window)
|
||||||
.context("there is no monitor associated with this window, it may have already been destroyed")?;
|
.ok_or_else(|| anyhow!("there is no monitor associated with this window, it may have already been destroyed"))?;
|
||||||
|
|
||||||
self.focus_monitor(monitor_idx)?;
|
self.focus_monitor(monitor_idx)?;
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ impl WindowManager {
|
|||||||
if self.focused_monitor_idx() != known_monitor_idx
|
if self.focused_monitor_idx() != known_monitor_idx
|
||||||
|| self
|
|| self
|
||||||
.focused_monitor()
|
.focused_monitor()
|
||||||
.context("there is no monitor")?
|
.ok_or_else(|| anyhow!("there is no monitor"))?
|
||||||
.focused_workspace_idx()
|
.focused_workspace_idx()
|
||||||
!= known_workspace_idx
|
!= known_workspace_idx
|
||||||
{
|
{
|
||||||
@@ -210,7 +210,7 @@ impl WindowManager {
|
|||||||
let old_position = *workspace
|
let old_position = *workspace
|
||||||
.latest_layout()
|
.latest_layout()
|
||||||
.get(focused_idx)
|
.get(focused_idx)
|
||||||
.context("there is no latest layout")?;
|
.ok_or_else(|| anyhow!("there is no latest layout"))?;
|
||||||
let mut new_position = WindowsApi::window_rect(window.hwnd())?;
|
let mut new_position = WindowsApi::window_rect(window.hwnd())?;
|
||||||
|
|
||||||
// See Window.set_position() in window.rs for comments
|
// See Window.set_position() in window.rs for comments
|
||||||
@@ -305,7 +305,8 @@ impl WindowManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut hwnd_json = dirs::home_dir().context("there is no home directory")?;
|
let mut hwnd_json =
|
||||||
|
dirs::home_dir().ok_or_else(|| anyhow!("there is no home directory"))?;
|
||||||
hwnd_json.push("komorebi.hwnd.json");
|
hwnd_json.push("komorebi.hwnd.json");
|
||||||
let file = OpenOptions::new()
|
let file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::convert::TryFrom;
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::fmt::Formatter;
|
use std::fmt::Formatter;
|
||||||
|
|
||||||
use color_eyre::eyre::ContextCompat;
|
use color_eyre::eyre::anyhow;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use serde::ser::SerializeStruct;
|
use serde::ser::SerializeStruct;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -187,12 +187,12 @@ impl Window {
|
|||||||
|
|
||||||
pub fn style(self) -> Result<GwlStyle> {
|
pub fn style(self) -> Result<GwlStyle> {
|
||||||
let bits = u32::try_from(WindowsApi::gwl_style(self.hwnd())?)?;
|
let bits = u32::try_from(WindowsApi::gwl_style(self.hwnd())?)?;
|
||||||
GwlStyle::from_bits(bits).context("there is no gwl style")
|
GwlStyle::from_bits(bits).ok_or_else(|| anyhow!("there is no gwl style"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ex_style(self) -> Result<GwlExStyle> {
|
pub fn ex_style(self) -> Result<GwlExStyle> {
|
||||||
let bits = u32::try_from(WindowsApi::gwl_ex_style(self.hwnd())?)?;
|
let bits = u32::try_from(WindowsApi::gwl_ex_style(self.hwnd())?)?;
|
||||||
GwlExStyle::from_bits(bits).context("there is no gwl style")
|
GwlExStyle::from_bits(bits).ok_or_else(|| anyhow!("there is no gwl style"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn title(self) -> Result<String> {
|
pub fn title(self) -> Result<String> {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use std::path::PathBuf;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
use color_eyre::eyre::anyhow;
|
||||||
use color_eyre::eyre::ContextCompat;
|
use color_eyre::eyre::ContextCompat;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossbeam_channel::Receiver;
|
use crossbeam_channel::Receiver;
|
||||||
@@ -102,7 +103,7 @@ impl EnforceWorkspaceRuleOp {
|
|||||||
impl WindowManager {
|
impl WindowManager {
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub fn new(incoming: Arc<Mutex<Receiver<WindowManagerEvent>>>) -> Result<Self> {
|
pub fn new(incoming: Arc<Mutex<Receiver<WindowManagerEvent>>>) -> Result<Self> {
|
||||||
let home = dirs::home_dir().context("there is no home directory")?;
|
let home = dirs::home_dir().ok_or_else(|| anyhow!("there is no home directory"))?;
|
||||||
let mut socket = home;
|
let mut socket = home;
|
||||||
socket.push("komorebi.sock");
|
socket.push("komorebi.sock");
|
||||||
let socket = socket.as_path();
|
let socket = socket.as_path();
|
||||||
@@ -148,7 +149,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn watch_configuration(&mut self, enable: bool) -> Result<()> {
|
pub fn watch_configuration(&mut self, enable: bool) -> Result<()> {
|
||||||
let home = dirs::home_dir().context("there is no home directory")?;
|
let home = dirs::home_dir().ok_or_else(|| anyhow!("there is no home directory"))?;
|
||||||
|
|
||||||
let mut config_v1 = home.clone();
|
let mut config_v1 = home.clone();
|
||||||
config_v1.push("komorebi.ahk");
|
config_v1.push("komorebi.ahk");
|
||||||
@@ -173,7 +174,7 @@ impl WindowManager {
|
|||||||
config
|
config
|
||||||
.as_os_str()
|
.as_os_str()
|
||||||
.to_str()
|
.to_str()
|
||||||
.context("cannot convert path to string")?
|
.ok_or_else(|| anyhow!("cannot convert path to string"))?
|
||||||
);
|
);
|
||||||
// Always make absolutely sure that there isn't an already existing watch, because
|
// Always make absolutely sure that there isn't an already existing watch, because
|
||||||
// hotwatch allows multiple watches to be registered for the same path
|
// hotwatch allows multiple watches to be registered for the same path
|
||||||
@@ -204,7 +205,7 @@ impl WindowManager {
|
|||||||
config
|
config
|
||||||
.as_os_str()
|
.as_os_str()
|
||||||
.to_str()
|
.to_str()
|
||||||
.context("cannot convert path to string")?
|
.ok_or_else(|| anyhow!("cannot convert path to string"))?
|
||||||
);
|
);
|
||||||
|
|
||||||
self.hotwatch.unwatch(config)?;
|
self.hotwatch.unwatch(config)?;
|
||||||
@@ -222,7 +223,7 @@ impl WindowManager {
|
|||||||
let focused_workspace_idx = self
|
let focused_workspace_idx = self
|
||||||
.monitors()
|
.monitors()
|
||||||
.get(focused_monitor_idx)
|
.get(focused_monitor_idx)
|
||||||
.context("there is no monitor with that index")?
|
.ok_or_else(|| anyhow!("there is no monitor with that index"))?
|
||||||
.focused_workspace_idx();
|
.focused_workspace_idx();
|
||||||
|
|
||||||
let workspace_rules = WORKSPACE_RULES.lock();
|
let workspace_rules = WORKSPACE_RULES.lock();
|
||||||
@@ -283,10 +284,10 @@ impl WindowManager {
|
|||||||
let origin_workspace = self
|
let origin_workspace = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(op.origin_monitor_idx)
|
.get_mut(op.origin_monitor_idx)
|
||||||
.context("there is no monitor with that index")?
|
.ok_or_else(|| anyhow!("there is no monitor with that index"))?
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(op.origin_workspace_idx)
|
.get_mut(op.origin_workspace_idx)
|
||||||
.context("there is no workspace with that index")?;
|
.ok_or_else(|| anyhow!("there is no workspace with that index"))?;
|
||||||
|
|
||||||
// Hide the window we are about to remove if it is on the currently focused workspace
|
// Hide the window we are about to remove if it is on the currently focused workspace
|
||||||
if op.is_origin(focused_monitor_idx, focused_workspace_idx) {
|
if op.is_origin(focused_monitor_idx, focused_workspace_idx) {
|
||||||
@@ -303,7 +304,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)
|
||||||
.context("there is no monitor with that index")?;
|
.ok_or_else(|| anyhow!("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
|
||||||
@@ -318,7 +319,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)
|
||||||
.context("there is no workspace with that index")?;
|
.ok_or_else(|| anyhow!("there is no workspace with that index"))?;
|
||||||
|
|
||||||
target_workspace.new_container_for_window(Window { hwnd: op.hwnd });
|
target_workspace.new_container_for_window(Window { hwnd: op.hwnd });
|
||||||
}
|
}
|
||||||
@@ -364,7 +365,7 @@ impl WindowManager {
|
|||||||
tracing::info!("updating");
|
tracing::info!("updating");
|
||||||
|
|
||||||
self.focused_monitor_mut()
|
self.focused_monitor_mut()
|
||||||
.context("there is no monitor")?
|
.ok_or_else(|| anyhow!("there is no monitor"))?
|
||||||
.update_focused_workspace()?;
|
.update_focused_workspace()?;
|
||||||
|
|
||||||
if mouse_follows_focus {
|
if mouse_follows_focus {
|
||||||
@@ -385,7 +386,7 @@ impl WindowManager {
|
|||||||
// attach to the thread of the desktop window always seems to result in "Access is
|
// attach to the thread of the desktop window always seems to result in "Access is
|
||||||
// denied (os error 5)"
|
// denied (os error 5)"
|
||||||
WindowsApi::set_foreground_window(desktop_window.hwnd())
|
WindowsApi::set_foreground_window(desktop_window.hwnd())
|
||||||
.map_err(|error| eyre::anyhow!("{} {}:{}", error, file!(), line!()))?;
|
.map_err(|error| anyhow!("{} {}:{}", error, file!(), line!()))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,7 +409,7 @@ impl WindowManager {
|
|||||||
let focused_idx_resize = workspace
|
let focused_idx_resize = workspace
|
||||||
.resize_dimensions()
|
.resize_dimensions()
|
||||||
.get(focused_idx)
|
.get(focused_idx)
|
||||||
.context("there is no resize adjustment for this container")?;
|
.ok_or_else(|| anyhow!("there is no resize adjustment for this container"))?;
|
||||||
|
|
||||||
if direction.is_valid(
|
if direction.is_valid(
|
||||||
workspace.layout(),
|
workspace.layout(),
|
||||||
@@ -453,7 +454,7 @@ impl WindowManager {
|
|||||||
let resize = workspace.layout().resize(
|
let resize = workspace.layout().resize(
|
||||||
unaltered
|
unaltered
|
||||||
.get(focused_idx)
|
.get(focused_idx)
|
||||||
.context("there is no last layout")?,
|
.ok_or_else(|| anyhow!("there is no last layout"))?,
|
||||||
focused_idx_resize,
|
focused_idx_resize,
|
||||||
direction,
|
direction,
|
||||||
sizing,
|
sizing,
|
||||||
@@ -487,25 +488,27 @@ impl WindowManager {
|
|||||||
pub fn move_container_to_monitor(&mut self, idx: usize, follow: bool) -> Result<()> {
|
pub fn move_container_to_monitor(&mut self, idx: usize, follow: bool) -> Result<()> {
|
||||||
tracing::info!("moving container");
|
tracing::info!("moving container");
|
||||||
|
|
||||||
let monitor = self.focused_monitor_mut().context("there is no monitor")?;
|
let monitor = self
|
||||||
|
.focused_monitor_mut()
|
||||||
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.focused_workspace_mut()
|
.focused_workspace_mut()
|
||||||
.context("there is no workspace")?;
|
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
||||||
|
|
||||||
if workspace.maximized_window().is_some() {
|
if workspace.maximized_window().is_some() {
|
||||||
return Err(eyre::anyhow!(
|
return Err(anyhow!(
|
||||||
"cannot move native maximized window to another monitor or workspace"
|
"cannot move native maximized window to another monitor or workspace"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = workspace
|
let container = workspace
|
||||||
.remove_focused_container()
|
.remove_focused_container()
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("there is no container"))?;
|
||||||
|
|
||||||
let target_monitor = self
|
let target_monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(idx)
|
.get_mut(idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
target_monitor.add_container(container)?;
|
target_monitor.add_container(container)?;
|
||||||
target_monitor.load_focused_workspace()?;
|
target_monitor.load_focused_workspace()?;
|
||||||
@@ -521,7 +524,9 @@ impl WindowManager {
|
|||||||
pub fn move_container_to_workspace(&mut self, idx: usize, follow: bool) -> Result<()> {
|
pub fn move_container_to_workspace(&mut self, idx: usize, follow: bool) -> Result<()> {
|
||||||
tracing::info!("moving container");
|
tracing::info!("moving container");
|
||||||
|
|
||||||
let monitor = self.focused_monitor_mut().context("there is no monitor")?;
|
let monitor = self
|
||||||
|
.focused_monitor_mut()
|
||||||
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
monitor.move_container_to_workspace(idx, follow)?;
|
monitor.move_container_to_workspace(idx, follow)?;
|
||||||
monitor.load_focused_workspace()?;
|
monitor.load_focused_workspace()?;
|
||||||
self.update_focused_workspace(true)
|
self.update_focused_workspace(true)
|
||||||
@@ -534,7 +539,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let new_idx = workspace
|
let new_idx = workspace
|
||||||
.new_idx_for_direction(direction)
|
.new_idx_for_direction(direction)
|
||||||
.context("this is not a valid direction from the current position")?;
|
.ok_or_else(|| anyhow!("this is not a valid direction from the current position"))?;
|
||||||
|
|
||||||
workspace.focus_container(new_idx);
|
workspace.focus_container(new_idx);
|
||||||
self.focused_window_mut()?.focus()?;
|
self.focused_window_mut()?.focus()?;
|
||||||
@@ -551,7 +556,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_direction(direction)
|
.new_idx_for_direction(direction)
|
||||||
.context("this is not a valid direction from the current position")?;
|
.ok_or_else(|| anyhow!("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);
|
||||||
@@ -565,7 +570,7 @@ impl WindowManager {
|
|||||||
let container = self.focused_container_mut()?;
|
let container = self.focused_container_mut()?;
|
||||||
|
|
||||||
if container.windows().len() == 1 {
|
if container.windows().len() == 1 {
|
||||||
return Err(eyre::anyhow!("there is only one window in this container"));
|
return Err(anyhow!("there is only one window in this container"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let current_idx = container.focused_window_idx();
|
let current_idx = container.focused_window_idx();
|
||||||
@@ -592,9 +597,9 @@ impl WindowManager {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if is_valid {
|
if is_valid {
|
||||||
let new_idx = workspace
|
let new_idx = workspace.new_idx_for_direction(direction).ok_or_else(|| {
|
||||||
.new_idx_for_direction(direction)
|
anyhow!("this is not a valid direction from the current position")
|
||||||
.context("this is not a valid direction from the current position")?;
|
})?;
|
||||||
|
|
||||||
let adjusted_new_index = if new_idx > current_container_idx {
|
let adjusted_new_index = if new_idx > current_container_idx {
|
||||||
new_idx - 1
|
new_idx - 1
|
||||||
@@ -623,7 +628,7 @@ impl WindowManager {
|
|||||||
tracing::info!("removing window");
|
tracing::info!("removing window");
|
||||||
|
|
||||||
if self.focused_container()?.windows().len() == 1 {
|
if self.focused_container()?.windows().len() == 1 {
|
||||||
return Err(eyre::anyhow!("a container must have at least one window"));
|
return Err(anyhow!("a container must have at least one window"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let workspace = self.focused_workspace_mut()?;
|
let workspace = self.focused_workspace_mut()?;
|
||||||
@@ -673,7 +678,7 @@ impl WindowManager {
|
|||||||
let window = workspace
|
let window = workspace
|
||||||
.floating_windows_mut()
|
.floating_windows_mut()
|
||||||
.last_mut()
|
.last_mut()
|
||||||
.context("there is no floating window")?;
|
.ok_or_else(|| anyhow!("there is no floating window"))?;
|
||||||
|
|
||||||
window.center(&work_area)?;
|
window.center(&work_area)?;
|
||||||
window.focus()?;
|
window.focus()?;
|
||||||
@@ -805,7 +810,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let padding = workspace
|
let padding = workspace
|
||||||
.workspace_padding()
|
.workspace_padding()
|
||||||
.context("there is no workspace padding")?;
|
.ok_or_else(|| anyhow!("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)));
|
||||||
|
|
||||||
@@ -820,7 +825,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let padding = workspace
|
let padding = workspace
|
||||||
.container_padding()
|
.container_padding()
|
||||||
.context("there is no container padding")?;
|
.ok_or_else(|| anyhow!("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)));
|
||||||
|
|
||||||
@@ -837,12 +842,12 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.get_mut(workspace_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
workspace.set_tile(tile);
|
workspace.set_tile(tile);
|
||||||
|
|
||||||
@@ -863,7 +868,7 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
let work_area = *monitor.work_area_size();
|
let work_area = *monitor.work_area_size();
|
||||||
let focused_workspace_idx = monitor.focused_workspace_idx();
|
let focused_workspace_idx = monitor.focused_workspace_idx();
|
||||||
@@ -871,7 +876,7 @@ impl WindowManager {
|
|||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.get_mut(workspace_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
workspace.set_layout(layout);
|
workspace.set_layout(layout);
|
||||||
|
|
||||||
@@ -895,7 +900,7 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
monitor.ensure_workspace_count(workspace_count);
|
monitor.ensure_workspace_count(workspace_count);
|
||||||
|
|
||||||
@@ -914,12 +919,12 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.get_mut(workspace_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
workspace.set_workspace_padding(Option::from(size));
|
workspace.set_workspace_padding(Option::from(size));
|
||||||
|
|
||||||
@@ -938,12 +943,12 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.get_mut(workspace_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("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);
|
||||||
@@ -963,12 +968,12 @@ impl WindowManager {
|
|||||||
let monitor = self
|
let monitor = self
|
||||||
.monitors_mut()
|
.monitors_mut()
|
||||||
.get_mut(monitor_idx)
|
.get_mut(monitor_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
let workspace = monitor
|
let workspace = monitor
|
||||||
.workspaces_mut()
|
.workspaces_mut()
|
||||||
.get_mut(workspace_idx)
|
.get_mut(workspace_idx)
|
||||||
.context("there is no monitor")?;
|
.ok_or_else(|| anyhow!("there is no monitor"))?;
|
||||||
|
|
||||||
workspace.set_container_padding(Option::from(size));
|
workspace.set_container_padding(Option::from(size));
|
||||||
|
|
||||||
@@ -978,7 +983,7 @@ impl WindowManager {
|
|||||||
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()
|
||||||
.context("there is no monitor")?
|
.ok_or_else(|| anyhow!("there is no monitor"))?
|
||||||
.work_area_size())
|
.work_area_size())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -989,7 +994,7 @@ impl WindowManager {
|
|||||||
if self.monitors().get(idx).is_some() {
|
if self.monitors().get(idx).is_some() {
|
||||||
self.monitors.focus(idx);
|
self.monitors.focus(idx);
|
||||||
} else {
|
} else {
|
||||||
return Err(eyre::anyhow!("this is not a valid monitor index"));
|
return Err(anyhow!("this is not a valid monitor index"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1009,16 +1014,16 @@ impl WindowManager {
|
|||||||
|
|
||||||
pub fn focused_workspace(&self) -> Result<&Workspace> {
|
pub fn focused_workspace(&self) -> Result<&Workspace> {
|
||||||
self.focused_monitor()
|
self.focused_monitor()
|
||||||
.context("there is no monitor")?
|
.ok_or_else(|| anyhow!("there is no monitor"))?
|
||||||
.focused_workspace()
|
.focused_workspace()
|
||||||
.context("there is no workspace")
|
.ok_or_else(|| anyhow!("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()
|
||||||
.context("there is no monitor")?
|
.ok_or_else(|| anyhow!("there is no monitor"))?
|
||||||
.focused_workspace_mut()
|
.focused_workspace_mut()
|
||||||
.context("there is no workspace")
|
.ok_or_else(|| anyhow!("there is no workspace"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
@@ -1027,7 +1032,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let monitor = self
|
let monitor = self
|
||||||
.focused_monitor_mut()
|
.focused_monitor_mut()
|
||||||
.context("there is no workspace")?;
|
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
||||||
|
|
||||||
monitor.focus_workspace(idx)?;
|
monitor.focus_workspace(idx)?;
|
||||||
monitor.load_focused_workspace()?;
|
monitor.load_focused_workspace()?;
|
||||||
@@ -1041,7 +1046,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
let monitor = self
|
let monitor = self
|
||||||
.focused_monitor_mut()
|
.focused_monitor_mut()
|
||||||
.context("there is no workspace")?;
|
.ok_or_else(|| anyhow!("there is no workspace"))?;
|
||||||
|
|
||||||
monitor.focus_workspace(monitor.new_workspace_idx())?;
|
monitor.focus_workspace(monitor.new_workspace_idx())?;
|
||||||
monitor.load_focused_workspace()?;
|
monitor.load_focused_workspace()?;
|
||||||
@@ -1052,18 +1057,18 @@ 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()
|
||||||
.context("there is no container")
|
.ok_or_else(|| anyhow!("there is no container"))
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
.context("there is no container")
|
.ok_or_else(|| anyhow!("there is no container"))
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
.context("there is no window")
|
.ok_or_else(|| anyhow!("there is no window"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ use std::convert::TryFrom;
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
|
|
||||||
use color_eyre::eyre::ContextCompat;
|
use color_eyre::eyre::anyhow;
|
||||||
|
use color_eyre::eyre::Error;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use eyre::Error;
|
|
||||||
|
|
||||||
use bindings::Windows::Win32::Foundation::BOOL;
|
use bindings::Windows::Win32::Foundation::BOOL;
|
||||||
use bindings::Windows::Win32::Foundation::HANDLE;
|
use bindings::Windows::Win32::Foundation::HANDLE;
|
||||||
@@ -314,7 +314,7 @@ impl WindowsApi {
|
|||||||
next_hwnd = Self::next_window(HWND(next_hwnd))?;
|
next_hwnd = Self::next_window(HWND(next_hwnd))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(eyre::anyhow!("could not find next window"))
|
Err(anyhow!("could not find next window"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn window_rect(hwnd: HWND) -> Result<Rect> {
|
pub fn window_rect(hwnd: HWND) -> Result<Rect> {
|
||||||
@@ -463,7 +463,7 @@ impl WindowsApi {
|
|||||||
Ok(Self::exe_path(handle)?
|
Ok(Self::exe_path(handle)?
|
||||||
.split('\\')
|
.split('\\')
|
||||||
.last()
|
.last()
|
||||||
.context("there is no last element")?
|
.ok_or_else(|| anyhow!("there is no last element"))?
|
||||||
.to_string())
|
.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+29
-28
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
|
|
||||||
|
use color_eyre::eyre::anyhow;
|
||||||
use color_eyre::eyre::ContextCompat;
|
use color_eyre::eyre::ContextCompat;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use getset::CopyGetters;
|
use getset::CopyGetters;
|
||||||
@@ -229,16 +230,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)
|
||||||
.context("there is no container/window")?;
|
.ok_or_else(|| anyhow!("there is no container/window"))?;
|
||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.containers_mut()
|
.containers_mut()
|
||||||
.get_mut(container_idx)
|
.get_mut(container_idx)
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("there is no container"))?;
|
||||||
|
|
||||||
let window_idx = container
|
let window_idx = container
|
||||||
.idx_for_window(hwnd)
|
.idx_for_window(hwnd)
|
||||||
.context("there is no window")?;
|
.ok_or_else(|| anyhow!("there is no window"))?;
|
||||||
|
|
||||||
container.focus_window(window_idx);
|
container.focus_window(window_idx);
|
||||||
self.focus_container(container_idx);
|
self.focus_container(container_idx);
|
||||||
@@ -293,7 +294,7 @@ impl Workspace {
|
|||||||
pub fn promote_container(&mut self) -> Result<()> {
|
pub fn promote_container(&mut self) -> Result<()> {
|
||||||
let container = self
|
let container = self
|
||||||
.remove_focused_container()
|
.remove_focused_container()
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("there is no container"))?;
|
||||||
self.containers_mut().push_front(container);
|
self.containers_mut().push_front(container);
|
||||||
self.resize_dimensions_mut().insert(0, None);
|
self.resize_dimensions_mut().insert(0, None);
|
||||||
self.focus_container(0);
|
self.focus_container(0);
|
||||||
@@ -330,27 +331,27 @@ impl Workspace {
|
|||||||
|
|
||||||
let container_idx = self
|
let container_idx = self
|
||||||
.container_idx_for_window(hwnd)
|
.container_idx_for_window(hwnd)
|
||||||
.context("there is no window")?;
|
.ok_or_else(|| anyhow!("there is no window"))?;
|
||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.containers_mut()
|
.containers_mut()
|
||||||
.get_mut(container_idx)
|
.get_mut(container_idx)
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("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)
|
||||||
.context("there is no window")?;
|
.ok_or_else(|| anyhow!("there is no window"))?;
|
||||||
|
|
||||||
container
|
container
|
||||||
.remove_window_by_idx(window_idx)
|
.remove_window_by_idx(window_idx)
|
||||||
.context("there is no window")?;
|
.ok_or_else(|| anyhow!("there is no window"))?;
|
||||||
|
|
||||||
if container.windows().is_empty() {
|
if container.windows().is_empty() {
|
||||||
self.containers_mut()
|
self.containers_mut()
|
||||||
.remove(container_idx)
|
.remove(container_idx)
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("there is no container"))?;
|
||||||
|
|
||||||
// Whenever a container is empty, we need to remove any resize dimensions for it too
|
// Whenever a container is empty, we need to remove any resize dimensions for it too
|
||||||
if self.resize_dimensions().get(container_idx).is_some() {
|
if self.resize_dimensions().get(container_idx).is_some() {
|
||||||
@@ -393,11 +394,11 @@ impl Workspace {
|
|||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.focused_container_mut()
|
.focused_container_mut()
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("there is no container"))?;
|
||||||
|
|
||||||
let window = container
|
let window = container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.context("there is no window")?;
|
.ok_or_else(|| anyhow!("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() {
|
||||||
@@ -417,13 +418,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)
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("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()
|
||||||
.context("there is no container")?
|
.ok_or_else(|| anyhow!("there is no container"))?
|
||||||
.load_focused_window();
|
.load_focused_window();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -434,11 +435,11 @@ impl Workspace {
|
|||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.focused_container_mut()
|
.focused_container_mut()
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("there is no container"))?;
|
||||||
|
|
||||||
let window = container
|
let window = container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.context("there is no window")?;
|
.ok_or_else(|| anyhow!("there is no window"))?;
|
||||||
|
|
||||||
if container.windows().is_empty() {
|
if container.windows().is_empty() {
|
||||||
self.containers_mut().remove(focused_container_idx);
|
self.containers_mut().remove(focused_container_idx);
|
||||||
@@ -458,7 +459,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()
|
||||||
.context("there is no floating window")?;
|
.ok_or_else(|| anyhow!("there is no floating window"))?;
|
||||||
|
|
||||||
let mut container = Container::default();
|
let mut container = Container::default();
|
||||||
container.add_window(window);
|
container.add_window(window);
|
||||||
@@ -498,11 +499,11 @@ impl Workspace {
|
|||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.focused_container_mut()
|
.focused_container_mut()
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("there is no container"))?;
|
||||||
|
|
||||||
let window = container
|
let window = container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.context("there is no window")?;
|
.ok_or_else(|| anyhow!("there is no window"))?;
|
||||||
|
|
||||||
if container.windows().is_empty() {
|
if container.windows().is_empty() {
|
||||||
self.containers_mut().remove(focused_idx);
|
self.containers_mut().remove(focused_idx);
|
||||||
@@ -547,7 +548,7 @@ impl Workspace {
|
|||||||
let container = self
|
let container = self
|
||||||
.containers_mut()
|
.containers_mut()
|
||||||
.remove(focused_idx)
|
.remove(focused_idx)
|
||||||
.context("there is not container")?;
|
.ok_or_else(|| anyhow!("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
|
||||||
@@ -559,7 +560,7 @@ impl Workspace {
|
|||||||
|
|
||||||
self.monocle_container_mut()
|
self.monocle_container_mut()
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.context("there is no monocle container")?
|
.ok_or_else(|| anyhow!("there is no monocle container"))?
|
||||||
.load_focused_window();
|
.load_focused_window();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -568,12 +569,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()
|
||||||
.context("there is no monocle restore index")?;
|
.ok_or_else(|| anyhow!("there is no monocle restore index"))?;
|
||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.monocle_container_mut()
|
.monocle_container_mut()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.context("there is no monocle container")?;
|
.ok_or_else(|| anyhow!("there is no monocle container"))?;
|
||||||
|
|
||||||
let container = container.clone();
|
let container = container.clone();
|
||||||
if restore_idx > self.containers().len() - 1 {
|
if restore_idx > self.containers().len() - 1 {
|
||||||
@@ -584,7 +585,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()
|
||||||
.context("there is no container")?
|
.ok_or_else(|| anyhow!("there is no container"))?
|
||||||
.load_focused_window();
|
.load_focused_window();
|
||||||
|
|
||||||
self.set_monocle_container(None);
|
self.set_monocle_container(None);
|
||||||
@@ -598,11 +599,11 @@ impl Workspace {
|
|||||||
|
|
||||||
let container = self
|
let container = self
|
||||||
.focused_container_mut()
|
.focused_container_mut()
|
||||||
.context("there is no container")?;
|
.ok_or_else(|| anyhow!("there is no container"))?;
|
||||||
|
|
||||||
let window = container
|
let window = container
|
||||||
.remove_focused_window()
|
.remove_focused_window()
|
||||||
.context("there is no window")?;
|
.ok_or_else(|| anyhow!("there is no window"))?;
|
||||||
|
|
||||||
if container.windows().is_empty() {
|
if container.windows().is_empty() {
|
||||||
self.containers_mut().remove(focused_idx);
|
self.containers_mut().remove(focused_idx);
|
||||||
@@ -626,12 +627,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()
|
||||||
.context("there is no monocle restore index")?;
|
.ok_or_else(|| anyhow!("there is no monocle restore index"))?;
|
||||||
|
|
||||||
let window = self
|
let window = self
|
||||||
.maximized_window()
|
.maximized_window()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.context("there is no monocle container")?;
|
.ok_or_else(|| anyhow!("there is no monocle container"))?;
|
||||||
|
|
||||||
let window = *window;
|
let window = *window;
|
||||||
if !self.containers().is_empty() && restore_idx > self.containers().len() - 1 {
|
if !self.containers().is_empty() && restore_idx > self.containers().len() - 1 {
|
||||||
@@ -646,7 +647,7 @@ impl Workspace {
|
|||||||
self.focus_container(restore_idx);
|
self.focus_container(restore_idx);
|
||||||
|
|
||||||
self.focused_container_mut()
|
self.focused_container_mut()
|
||||||
.context("there is no container")?
|
.ok_or_else(|| anyhow!("there is no container"))?
|
||||||
.load_focused_window();
|
.load_focused_window();
|
||||||
|
|
||||||
self.set_maximized_window(None);
|
self.set_maximized_window(None);
|
||||||
|
|||||||
Reference in New Issue
Block a user