launcher: Support launch_cmd config

This commit is contained in:
Kenny Levinsen
2025-01-12 22:51:45 +01:00
parent 2b3048faca
commit bc9ba0045c
2 changed files with 21 additions and 14 deletions
+5 -1
View File
@@ -52,6 +52,7 @@ pub enum Widget {
Launcher { Launcher {
font: Option<String>, font: Option<String>,
font_size: f32, font_size: f32,
launch_cmd: Option<String>,
}, },
Battery { Battery {
font: Option<String>, font: Option<String>,
@@ -148,6 +149,7 @@ impl Config {
Widget::Launcher { Widget::Launcher {
font: None, font: None,
font_size: 32., font_size: 32.,
launch_cmd: None,
}, },
])), ])),
}; };
@@ -236,6 +238,7 @@ impl Config {
widget: Box::new(Widget::Launcher { widget: Box::new(Widget::Launcher {
font: None, font: None,
font_size: 32., font_size: 32.,
launch_cmd: None,
}), }),
}, },
]), ]),
@@ -321,11 +324,12 @@ impl Widget {
sections_x, sections_x,
sections_y, 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(), events.clone(),
&mut fm, &mut fm,
leak_or_default(font, "sans"), leak_or_default(font, "sans"),
font_size, font_size,
launch_cmd,
))), ))),
Widget::Battery { font, font_size } => v.push(Box::new(Battery::new( Widget::Battery { font, font_size } => v.push(Box::new(Battery::new(
events.clone(), events.clone(),
+16 -13
View File
@@ -212,10 +212,11 @@ struct Launcher {
next_token: Option<String>, next_token: Option<String>,
options: Arc<Mutex<Vec<Desktop>>>, options: Arc<Mutex<Vec<Desktop>>>,
matches: Vec<Desktop>, matches: Vec<Desktop>,
launch_cmd: Option<String>,
} }
impl Launcher { impl Launcher {
fn new(events: Arc<Mutex<Events>>) -> Launcher { fn new(events: Arc<Mutex<Events>>, launch_cmd: Option<String>) -> Launcher {
let options = Arc::new(Mutex::new(Vec::new())); let options = Arc::new(Mutex::new(Vec::new()));
{ {
let options = Arc::clone(&options); let options = Arc::clone(&options);
@@ -242,15 +243,22 @@ impl Launcher {
next_token: None, next_token: None,
options: options, options: options,
matches: Vec::new(), matches: Vec::new(),
launch_cmd,
} }
} }
fn exec(&self, args: Vec<String>) { fn exec(&self, cmdline: &str) {
let mut cmd = Command::new(args[0].clone()); let mut cmd = Command::new("/bin/sh");
if let Some(token) = &self.next_token { if let Some(token) = &self.next_token {
cmd.env("XDG_ACTIVATION_TOKEN", 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); exit(0);
} }
} }
@@ -266,10 +274,7 @@ impl InterfaceWidget for Launcher {
.replace("%u", "") .replace("%u", "")
.replace("%U", ""); .replace("%U", "");
let lexed = shlex::split(&exec).unwrap(); self.exec(&exec);
if !lexed.is_empty() {
self.exec(lexed);
}
} }
} }
} }
@@ -379,12 +384,9 @@ struct Shell {
next_token: Option<String>, next_token: Option<String>,
} }
impl Shell { impl Shell {
fn new() -> Shell { fn new() -> Shell {
Shell { Shell { next_token: None }
next_token: None,
}
} }
fn exec(&self, args: Vec<String>) { fn exec(&self, args: Vec<String>) {
@@ -613,6 +615,7 @@ impl Interface {
fm: &mut FontMap, fm: &mut FontMap,
font: &'static str, font: &'static str,
size: f32, size: f32,
launch_cmd: Option<String>
) -> Interface { ) -> Interface {
fm.queue_font( fm.queue_font(
font, font,
@@ -621,7 +624,7 @@ impl Interface {
); );
Interface { Interface {
launcher: Launcher::new(events), launcher: Launcher::new(events, launch_cmd),
shell: Shell::new(), shell: Shell::new(),
calc: Calc::new(), calc: Calc::new(),
inner: InnerInterface { inner: InnerInterface {