use callback::{AsWrapper, IntoCallback, Wrapper};
use wlc::Callback;
pub mod bsp;
pub use self::bsp::{BSP, BSPConfig, BSPWrap, KeyPatterns as BSPKeyPatterns};
mod combined;
pub use self::combined::{Combined, CombinedConfig, CombinedWrap, KeyPatterns as CombinedKeyPatterns,
Predicate as CombinedPredicate};
mod floating;
pub use self::floating::*;
mod switch;
pub use self::switch::{KeyPatterns as SwitchKeyPatterns, Switch, SwitchConfig, SwitchWrap};
mod fullscreen;
pub use self::fullscreen::{Fullscreen, FullscreenConfig};
pub use self::fullscreen::{FullscreenWrap, KeyPatterns as FullscreenKeyPatterns};
pub trait Mode: Callback {
type Arguments;
fn new(arguments: Self::Arguments) -> Self;
fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
}
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
pub enum AnyMode {
Bsp(bsp::BSPWrap),
Floating(floating::Floating),
Combined(combined::CombinedWrap),
Switch(switch::SwitchWrap),
Fullscreen(fullscreen::FullscreenWrap),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)]
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
pub enum AnyModeConfig {
#[serde(rename = "bsp")]
Bsp(bsp::BSPConfig),
#[serde(rename = "floating")]
Floating(floating::FloatingConfig),
#[serde(rename = "combined")]
Combined(combined::CombinedConfig),
#[serde(rename = "switch")]
Switch(switch::SwitchConfig),
#[serde(rename = "fullscreen")]
Fullscreen(fullscreen::FullscreenConfig),
}
impl Default for AnyModeConfig {
fn default() -> AnyModeConfig {
AnyModeConfig::Fullscreen(fullscreen::FullscreenConfig {
mode: Box::new(AnyModeConfig::Floating(floating::FloatingConfig::default())),
keys: fullscreen::KeyPatterns { toggle: None },
})
}
}
impl AsWrapper for AnyMode {
fn child(&mut self) -> Option<&mut Callback> {
Some(match *self {
AnyMode::Bsp(ref mut mode) => mode as &mut Callback,
AnyMode::Floating(ref mut mode) => mode as &mut Callback,
AnyMode::Combined(ref mut mode) => mode as &mut Callback,
AnyMode::Switch(ref mut mode) => mode as &mut Callback,
AnyMode::Fullscreen(ref mut mode) => mode as &mut Callback,
})
}
}
pub type AnyModeWrap = Wrapper<AnyMode>;
impl Mode for Wrapper<AnyMode> {
type Arguments = AnyModeConfig;
fn new(arguments: Self::Arguments) -> Self {
match arguments {
AnyModeConfig::Bsp(config) => AnyMode::Bsp(bsp::BSPWrap::new(config)),
AnyModeConfig::Floating(config) => AnyMode::Floating(floating::Floating::new(config)),
AnyModeConfig::Combined(config) => AnyMode::Combined(combined::CombinedWrap::new(config)),
AnyModeConfig::Switch(config) => AnyMode::Switch(switch::SwitchWrap::new(config)),
AnyModeConfig::Fullscreen(config) => {
AnyMode::Fullscreen(fullscreen::FullscreenWrap::new(config))
}
}
.into_callback()
}
fn len(&self) -> usize {
match **self {
AnyMode::Bsp(ref mode) => mode.len(),
AnyMode::Floating(ref mode) => mode.len(),
AnyMode::Combined(ref mode) => mode.len(),
AnyMode::Switch(ref mode) => mode.len(),
AnyMode::Fullscreen(ref mode) => mode.len(),
}
}
}