diff --git a/src/config.rs b/src/config.rs index 2322059..94ba503 100644 --- a/src/config.rs +++ b/src/config.rs @@ -52,6 +52,7 @@ pub enum Widget { Launcher { font: Option, font_size: f32, + launch_cmd: Option, }, Battery { font: Option, @@ -148,6 +149,7 @@ impl Config { Widget::Launcher { font: None, font_size: 32., + launch_cmd: None, }, ])), }; @@ -236,6 +238,7 @@ impl Config { widget: Box::new(Widget::Launcher { font: None, font_size: 32., + launch_cmd: None, }), }, ]), @@ -321,11 +324,12 @@ impl Widget { sections_x, sections_y, ))), - Widget::Launcher { font, font_size } => v.push(Box::new(Interface::new( + Widget::Launcher { font, font_size, launch_cmd } => v.push(Box::new(Interface::new( events.clone(), &mut fm, leak_or_default(font, "sans"), font_size, + launch_cmd, ))), Widget::Battery { font, font_size } => v.push(Box::new(Battery::new( events.clone(), diff --git a/src/widgets/launcher.rs b/src/widgets/launcher.rs index c5ce594..a6be498 100644 --- a/src/widgets/launcher.rs +++ b/src/widgets/launcher.rs @@ -212,10 +212,11 @@ struct Launcher { next_token: Option, options: Arc>>, matches: Vec, + launch_cmd: Option, } impl Launcher { - fn new(events: Arc>) -> Launcher { + fn new(events: Arc>, launch_cmd: Option) -> Launcher { let options = Arc::new(Mutex::new(Vec::new())); { let options = Arc::clone(&options); @@ -242,15 +243,22 @@ impl Launcher { next_token: None, options: options, matches: Vec::new(), + launch_cmd, } } - fn exec(&self, args: Vec) { - let mut cmd = Command::new(args[0].clone()); + fn exec(&self, cmdline: &str) { + let mut cmd = Command::new("/bin/sh"); if let Some(token) = &self.next_token { cmd.env("XDG_ACTIVATION_TOKEN", token); } - cmd.args(&args[1..]).spawn().unwrap(); + cmd.arg("-c"); + if let Some(l) = &self.launch_cmd { + cmd.arg(format!("{} {}", l, cmdline)); + } else { + cmd.arg(cmdline); + } + cmd.spawn().unwrap(); exit(0); } } @@ -266,10 +274,7 @@ impl InterfaceWidget for Launcher { .replace("%u", "") .replace("%U", ""); - let lexed = shlex::split(&exec).unwrap(); - if !lexed.is_empty() { - self.exec(lexed); - } + self.exec(&exec); } } } @@ -379,12 +384,9 @@ struct Shell { next_token: Option, } - impl Shell { fn new() -> Shell { - Shell { - next_token: None, - } + Shell { next_token: None } } fn exec(&self, args: Vec) { @@ -613,6 +615,7 @@ impl Interface { fm: &mut FontMap, font: &'static str, size: f32, + launch_cmd: Option ) -> Interface { fm.queue_font( font, @@ -621,7 +624,7 @@ impl Interface { ); Interface { - launcher: Launcher::new(events), + launcher: Launcher::new(events, launch_cmd), shell: Shell::new(), calc: Calc::new(), inner: InnerInterface {