made terminal command configurable
This commit is contained in:
parent
c72356a087
commit
8f5f60455c
37
src/state.rs
37
src/state.rs
|
@ -34,6 +34,8 @@ pub struct WMConfig {
|
||||||
active_window_border_color: String,
|
active_window_border_color: String,
|
||||||
#[serde(default = "WMConfig::default_inactive_window_border_color")]
|
#[serde(default = "WMConfig::default_inactive_window_border_color")]
|
||||||
inactive_window_border_color: String,
|
inactive_window_border_color: String,
|
||||||
|
#[serde(default = "WMConfig::default_terminal")]
|
||||||
|
terminal_command: (String, Vec<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WMConfig {
|
impl WMConfig {
|
||||||
|
@ -44,6 +46,10 @@ impl WMConfig {
|
||||||
fn default_inactive_window_border_color() -> String {
|
fn default_inactive_window_border_color() -> String {
|
||||||
"#444444".to_string()
|
"#444444".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_terminal() -> (String, Vec<String>) {
|
||||||
|
("alacritty".to_string(), vec![])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WMConfig {
|
impl Default for WMConfig {
|
||||||
|
@ -57,6 +63,7 @@ impl Default for WMConfig {
|
||||||
Self::default_active_window_border_color(),
|
Self::default_active_window_border_color(),
|
||||||
inactive_window_border_color:
|
inactive_window_border_color:
|
||||||
Self::default_inactive_window_border_color(),
|
Self::default_inactive_window_border_color(),
|
||||||
|
terminal_command: Self::default_terminal(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +178,7 @@ where
|
||||||
KeyBind::new(VirtualKeyCode::P).with_mod(self.config.mod_key),
|
KeyBind::new(VirtualKeyCode::P).with_mod(self.config.mod_key),
|
||||||
|wm, _| {
|
|wm, _| {
|
||||||
wm.spawn(
|
wm.spawn(
|
||||||
"dmenu_run",
|
&"dmenu_run",
|
||||||
&[
|
&[
|
||||||
"-m",
|
"-m",
|
||||||
"0",
|
"0",
|
||||||
|
@ -234,7 +241,12 @@ where
|
||||||
KeyBind::new(VirtualKeyCode::Return)
|
KeyBind::new(VirtualKeyCode::Return)
|
||||||
.with_mod(self.config.mod_key)
|
.with_mod(self.config.mod_key)
|
||||||
.with_mod(ModifierKey::Shift),
|
.with_mod(ModifierKey::Shift),
|
||||||
|wm, _| wm.spawn("alacritty", &[]),
|
|wm, _| {
|
||||||
|
wm.spawn(
|
||||||
|
&wm.config.terminal_command.0,
|
||||||
|
&wm.config.terminal_command.1,
|
||||||
|
)
|
||||||
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
self.add_keybind(KeyBinding::new(
|
self.add_keybind(KeyBinding::new(
|
||||||
|
@ -848,12 +860,25 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn(&self, command: &str, args: &[&str]) {
|
pub fn spawn<'a, S, I>(&self, command: S, args: I)
|
||||||
info!("spawn: {:?} {:?}", command, args.join(" "));
|
where
|
||||||
match std::process::Command::new(command).args(args).spawn() {
|
S: AsRef<str> + AsRef<std::ffi::OsStr>,
|
||||||
|
I: IntoIterator<Item = S> + std::fmt::Debug,
|
||||||
|
{
|
||||||
|
info!("spawn: {:?} {:?}", AsRef::<str>::as_ref(&command), args);
|
||||||
|
match std::process::Command::new(AsRef::<std::ffi::OsStr>::as_ref(
|
||||||
|
&command,
|
||||||
|
))
|
||||||
|
.args(args)
|
||||||
|
.spawn()
|
||||||
|
{
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Failed to spawn {:?}: {:?}", command, err);
|
error!(
|
||||||
|
"Failed to spawn {:?}: {:?}",
|
||||||
|
AsRef::<str>::as_ref(&command),
|
||||||
|
err
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue