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 {
font: Option<String>,
font_size: f32,
launch_cmd: Option<String>,
},
Battery {
font: Option<String>,
@@ -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(),
+16 -13
View File
@@ -212,10 +212,11 @@ struct Launcher {
next_token: Option<String>,
options: Arc<Mutex<Vec<Desktop>>>,
matches: Vec<Desktop>,
launch_cmd: Option<String>,
}
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::clone(&options);
@@ -242,15 +243,22 @@ impl Launcher {
next_token: None,
options: options,
matches: Vec::new(),
launch_cmd,
}
}
fn exec(&self, args: Vec<String>) {
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<String>,
}
impl Shell {
fn new() -> Shell {
Shell {
next_token: None,
}
Shell { next_token: None }
}
fn exec(&self, args: Vec<String>) {
@@ -613,6 +615,7 @@ impl Interface {
fm: &mut FontMap,
font: &'static str,
size: f32,
launch_cmd: Option<String>
) -> 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 {