Diff
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 90b9ff6..1afb0c5 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -12,24 +12,53 @@ pub struct GapConfig {
pub outer_vertical: u32,
}
-pub const TILING: &str = "tiling";
-pub const NORMIE: &str = "normie";
-pub const FLOATING: &str = "floating";
+pub enum LayoutType {
+ Tiling,
+ Normie,
+}
-pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> {
- match s.to_lowercase().as_str() {
- TILING => Ok(Box::new(tiling::TilingLayout)),
- NORMIE | FLOATING => Ok(Box::new(normie::NormieLayout)),
- _ => Err(format!("Unknown layout: {}", s)),
+impl LayoutType {
+ pub fn new(&self) -> LayoutBox {
+ match self {
+ Self::Tiling => Box::new(tiling::TilingLayout),
+ Self::Normie => Box::new(normie::NormieLayout),
+ }
+ }
+
+ pub fn next(&self) -> Self {
+ match self {
+ Self::Tiling => Self::Normie,
+ Self::Normie => Self::Tiling,
+ }
+ }
+
+ pub fn as_str(&self) -> &'static str {
+ match self {
+ Self::Tiling => "tiling",
+ Self::Normie => "normie",
+ }
}
+
+ pub fn from_str(s: &str) -> Result<Self, String> {
+ match s.to_lowercase().as_str() {
+ "tiling" => Ok(Self::Tiling),
+ "normie" | "floating" => Ok(Self::Normie),
+ _ => Err(format!("Invalid Layout Type: {}", s)),
+ }
+ }
+}
+
+pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> {
+ let layout_type = LayoutType::from_str(s)?;
+ Ok(layout_type.new())
}
pub fn next_layout(current_name: &str) -> &'static str {
- match current_name {
- TILING => NORMIE,
- NORMIE => TILING,
- _ => TILING,
- }
+ LayoutType::from_str(current_name)
+ .ok()
+ .map(|layout_type| layout_type.next())
+ .unwrap_or(LayoutType::Tiling)
+ .as_str()
}
pub trait Layout {
diff --git a/src/layout/normie.rs b/src/layout/normie.rs
index e189c10..bc12b0e 100644
--- a/src/layout/normie.rs
+++ b/src/layout/normie.rs
@@ -6,7 +6,7 @@ pub struct NormieLayout;
// This layout should return a no-op similar to DWM.C's "null" mode.
impl Layout for NormieLayout {
fn name(&self) -> &'static str {
- super::NORMIE
+ super::LayoutType::Normie.as_str()
}
fn symbol(&self) -> &'static str {
diff --git a/src/layout/tiling.rs b/src/layout/tiling.rs
index f0e1464..dc0e1bf 100644
--- a/src/layout/tiling.rs
+++ b/src/layout/tiling.rs
@@ -5,7 +5,7 @@ pub struct TilingLayout;
impl Layout for TilingLayout {
fn name(&self) -> &'static str {
- super::TILING
+ super::LayoutType::Tiling.as_str()
}
fn symbol(&self) -> &'static str {
diff --git a/src/window_manager.rs b/src/window_manager.rs
index 5ef536e..85de1d9 100644
--- a/src/window_manager.rs
+++ b/src/window_manager.rs
@@ -4,7 +4,7 @@ use crate::errors::WmError;
use crate::keyboard::{self, Arg, KeyAction, handlers};
use crate::layout::GapConfig;
use crate::layout::tiling::TilingLayout;
-use crate::layout::{Layout, LayoutBox, layout_from_str, next_layout};
+use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout};
use crate::monitor::{Monitor, detect_monitors};
use std::collections::HashSet;
use x11rb::cursor::Handle as CursorHandle;
@@ -1422,7 +1422,7 @@ impl WindowManager {
return Ok(());
}
- if self.layout.name() == crate::layout::NORMIE {
+ if self.layout.name() == LayoutType::Normie.as_str() {
return Ok(());
}