refactor(wm): reduce boilerplate with getset

This commit introduces the getset crate to reduce a lot of the
boilerplate, especially in workspace.rs, around different variations of
getters. Hopefully this will make the codebase easier to navigate for
contributors in the future.

Also trying to avoid pinning to patch versions and minor versions
wherever possible.
This commit is contained in:
LGUG2Z
2021-08-13 10:24:29 -07:00
parent c15f1e1d7b
commit 0d3751a7cc
8 changed files with 89 additions and 147 deletions

View File

@@ -3,6 +3,9 @@ use std::collections::VecDeque;
use color_eyre::eyre::ContextCompat;
use color_eyre::Result;
use getset::CopyGetters;
use getset::Getters;
use getset::MutGetters;
use serde::Serialize;
use komorebi_core::Rect;
@@ -11,13 +14,16 @@ use crate::container::Container;
use crate::ring::Ring;
use crate::workspace::Workspace;
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Getters, CopyGetters, MutGetters)]
pub struct Monitor {
#[getset(get_copy = "pub")]
id: isize,
monitor_size: Rect,
#[getset(get = "pub")]
work_area_size: Rect,
workspaces: Ring<Workspace>,
#[serde(skip_serializing)]
#[getset(get_mut = "pub")]
workspace_names: HashMap<usize, String>,
}
@@ -131,16 +137,4 @@ impl Monitor {
Ok(())
}
pub fn workspace_names_mut(&mut self) -> &mut HashMap<usize, String> {
&mut self.workspace_names
}
pub const fn id(&self) -> isize {
self.id
}
pub const fn work_area_size(&self) -> &Rect {
&self.work_area_size
}
}