use leftwm_core::{
config::WindowHidingStrategy,
models::{FocusOnActivationBehaviour, ScratchPad, Size},
};
use crate::Backend;
#[cfg(feature = "lefthk")]
use super::{default_terminal, exit_strategy, BaseCommand, Keybind};
use super::{Config, Default, FocusBehaviour, LayoutMode, ThemeConfig};
impl Default for Config {
#[allow(clippy::too_many_lines)]
fn default() -> Self {
#[cfg(feature = "lefthk")]
const WORKSPACES_NUM: usize = 10;
#[cfg(feature = "lefthk")]
let mut commands = vec![
Keybind {
command: BaseCommand::Execute,
value: "dmenu_run".to_owned(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "p".to_owned(),
},
Keybind {
command: BaseCommand::Execute,
value: default_terminal().to_owned(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: "Return".to_owned(),
},
Keybind {
command: BaseCommand::CloseWindow,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: "q".to_owned(),
},
Keybind {
command: BaseCommand::SoftReload,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: "r".to_owned(),
},
Keybind {
command: BaseCommand::Execute,
value: exit_strategy().to_owned(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: "x".to_owned(),
},
Keybind {
command: BaseCommand::Execute,
value: "slock".to_owned(),
modifier: Some(vec!["modkey".to_owned(), "Control".to_owned()].into()),
key: "l".to_owned(),
},
Keybind {
command: BaseCommand::MoveToLastWorkspace,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: "w".to_owned(),
},
Keybind {
command: BaseCommand::SwapTags,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "w".to_owned(),
},
Keybind {
command: BaseCommand::MoveWindowUp,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: "k".to_owned(),
},
Keybind {
command: BaseCommand::MoveWindowDown,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: "j".to_owned(),
},
Keybind {
command: BaseCommand::MoveWindowTop,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "Return".to_owned(),
},
Keybind {
command: BaseCommand::FocusWindowUp,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "k".to_owned(),
},
Keybind {
command: BaseCommand::FocusWindowDown,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "j".to_owned(),
},
Keybind {
command: BaseCommand::NextLayout,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Control".to_owned()].into()),
key: "k".to_owned(),
},
Keybind {
command: BaseCommand::PreviousLayout,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Control".to_owned()].into()),
key: "j".to_owned(),
},
Keybind {
command: BaseCommand::FocusWorkspaceNext,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "l".to_owned(),
},
Keybind {
command: BaseCommand::FocusWorkspacePrevious,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "h".to_owned(),
},
Keybind {
command: BaseCommand::MoveWindowUp,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: "Up".to_owned(),
},
Keybind {
command: BaseCommand::MoveWindowDown,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: "Down".to_owned(),
},
Keybind {
command: BaseCommand::FocusWindowUp,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "Up".to_owned(),
},
Keybind {
command: BaseCommand::FocusWindowDown,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "Down".to_owned(),
},
Keybind {
command: BaseCommand::NextLayout,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Control".to_owned()].into()),
key: "Up".to_owned(),
},
Keybind {
command: BaseCommand::PreviousLayout,
value: String::default(),
modifier: Some(vec!["modkey".to_owned(), "Control".to_owned()].into()),
key: "Down".to_owned(),
},
Keybind {
command: BaseCommand::FocusWorkspaceNext,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "Right".to_owned(),
},
Keybind {
command: BaseCommand::FocusWorkspacePrevious,
value: String::default(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: "Left".to_owned(),
},
];
#[cfg(feature = "lefthk")]
for i in 1..WORKSPACES_NUM {
commands.push(Keybind {
command: BaseCommand::GotoTag,
value: i.to_string(),
modifier: Some(vec!["modkey".to_owned()].into()),
key: i.to_string(),
});
}
#[cfg(feature = "lefthk")]
for i in 1..WORKSPACES_NUM {
commands.push(Keybind {
command: BaseCommand::MoveToTag,
value: i.to_string(),
modifier: Some(vec!["modkey".to_owned(), "Shift".to_owned()].into()),
key: i.to_string(),
});
}
let tags = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
.iter()
.map(|s| (*s).to_string())
.collect();
let scratchpad = ScratchPad {
name: "Alacritty".into(),
value: "alacritty".to_string(),
args: None,
x: Some(Size::Pixel(860)),
y: Some(Size::Pixel(390)),
height: Some(Size::Pixel(300)),
width: Some(Size::Pixel(200)),
};
let layouts = leftwm_layouts::layouts::Layouts::default();
Self {
log_level: String::from("debug"),
backend: Backend::default(),
workspaces: Some(vec![]),
tags: Some(tags),
layouts: layouts.names(),
layout_definitions: layouts.layouts,
layout_mode: LayoutMode::Tag,
scratchpad: Some(vec![scratchpad]),
window_rules: Some(vec![]),
disable_current_tag_swap: false,
disable_tile_drag: false,
disable_window_snap: true,
focus_behaviour: FocusBehaviour::Sloppy, focus_on_activation: FocusOnActivationBehaviour::default(),
focus_new_windows: true, single_window_border: true,
insert_behavior: leftwm_core::config::InsertBehavior::Bottom,
window_hiding_strategy: WindowHidingStrategy::default(),
modkey: "Mod4".to_owned(), mousekey: Some("Mod4".into()), #[cfg(feature = "lefthk")]
keybind: commands,
theme_setting: ThemeConfig::default(),
state_path: None,
sloppy_mouse_follows_focus: true,
create_follows_cursor: None,
disable_cursor_reposition_on_resize: false,
auto_derive_workspaces: true,
}
}
}
#[cfg(test)]
mod tests {
use crate::Config;
#[test]
fn serialize_default_config() {
let config = Config::default();
assert!(ron::to_string(&config).is_ok());
}
}