Skip to content

Commit

Permalink
command config support
Browse files Browse the repository at this point in the history
  • Loading branch information
Walker-00 committed Aug 4, 2023
1 parent f27bad2 commit 5832a6d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
17 changes: 0 additions & 17 deletions src/hooks.rs

This file was deleted.

33 changes: 30 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use tracing_subscriber::{self, prelude::*};

#[derive(Serialize, Deserialize, Debug, Default)]
struct WMConfig {
bindings: HashMap<String, String>,
spawn: HashMap<String, String>,
command: HashMap<String, String>,
}

fn raw_key_bindings(
Expand All @@ -48,18 +49,44 @@ fn raw_key_bindings(
"M-S-Right" => send_layout_message(|| ExpandMain),
"M-S-Left" => send_layout_message(|| ShrinkMain),
"M-semicolon" => spawn("dmenu_run"),
"M-Return" => spawn("alacritty"),
"M-S-Return" => spawn("alacritty"),
"M-A-Escape" => exit(),

"M-slash" => Box::new(toggle_1),
"M-p" => Box::new(toggle_2),
};

if let Ok(cfg) = load::<WMConfig>("sswm", Some("config")) {
for i in cfg.bindings {
for i in cfg.spawn {
let r = i.1.clone();
raw_bindings.insert(i.0, key_handler(move |_, _| util::spawn(r.clone())));
}

for i in cfg.command {
let cmd_match: Option<Box<dyn KeyEventHandler<RustConn>>> =
match i.1.to_lowercase().as_str() {
"killf" => Some(modify_with(|cs| cs.kill_focused())),
"focdw" => Some(modify_with(|cs| cs.focus_down())),
"focup" => Some(modify_with(|cs| cs.focus_up())),
"swpdw" => Some(modify_with(|cs| cs.swap_down())),
"swpup" => Some(modify_with(|cs| cs.swap_up())),
"togtg" => Some(modify_with(|cs| cs.toggle_tag())),
"nexsc" => Some(modify_with(|cs| cs.next_screen())),
"presc" => Some(modify_with(|cs| cs.previous_screen())),
"nexly" => Some(modify_with(|cs| cs.next_layout())),
"prely" => Some(modify_with(|cs| cs.previous_layout())),
"incmn" => Some(send_layout_message(|| IncMain(1))),
"decmn" => Some(send_layout_message(|| IncMain(-1))),
"expmn" => Some(send_layout_message(|| ExpandMain)),
"shkmn" => Some(send_layout_message(|| ShrinkMain)),
"exits" => Some(exit()),
_ => None,
};

if let Some(cmd) = cmd_match {
raw_bindings.insert(i.0, cmd);
}
}
}

for tag in &["1", "2", "3", "4", "5", "6", "7", "8", "9"] {
Expand Down
14 changes: 0 additions & 14 deletions src/styles.rs

This file was deleted.

0 comments on commit 5832a6d

Please sign in to comment.