config: add ‘url-launch’ option, defaulting to “xdg-open ${url}”

This commit is contained in:
Daniel Eklöf 2021-01-31 14:27:13 +01:00
parent 0cbdf657a7
commit 4233c806c3
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 63 additions and 22 deletions

View file

@ -453,6 +453,33 @@ str_to_pt_or_px(const char *s, struct pt_or_px *res, struct config *conf,
return true;
}
static bool
str_to_spawn_template(struct config *conf,
const char *s, struct config_spawn_template *template,
const char *path, int lineno, const char *section,
const char *key)
{
free(template->raw_cmd);
free(template->argv);
template->raw_cmd = NULL;
template->argv = NULL;
char *raw_cmd = xstrdup(s);
char **argv = NULL;
if (!tokenize_cmdline(raw_cmd, &argv)) {
LOG_AND_NOTIFY_ERR(
"%s:%d: [%s]: %s: syntax error in command line",
path, lineno, section, key);
return false;
}
template->raw_cmd = raw_cmd;
template->argv = argv;
return true;
}
static bool
parse_section_main(const char *key, const char *value, struct config *conf,
const char *path, unsigned lineno)
@ -675,24 +702,19 @@ parse_section_main(const char *key, const char *value, struct config *conf,
}
else if (strcmp(key, "notify") == 0) {
free(conf->notify.raw_cmd);
free(conf->notify.argv);
conf->notify.raw_cmd = NULL;
conf->notify.argv = NULL;
char *raw_cmd = xstrdup(value);
char **argv = NULL;
if (!tokenize_cmdline(raw_cmd, &argv)) {
LOG_AND_NOTIFY_ERR(
"%s:%d: [default]: notify: syntax error in command line",
path, lineno);
if (!str_to_spawn_template(conf, value, &conf->notify, path, lineno,
"default", "notify"))
{
return false;
}
}
conf->notify.raw_cmd = raw_cmd;
conf->notify.argv = argv;
else if (strcmp(key, "url-launch") == 0) {
if (!str_to_spawn_template(conf, value, &conf->url_launch, path, lineno,
"default", "url-launch"))
{
return false;
}
}
else if (strcmp(key, "selection-target") == 0) {
@ -2308,6 +2330,9 @@ config_load(struct config *conf, const char *conf_path,
"notify-send -a foot -i foot ${title} ${body}");
tokenize_cmdline(conf->notify.raw_cmd, &conf->notify.argv);
conf->url_launch.raw_cmd = xstrdup("xdg-open ${url}");
tokenize_cmdline(conf->url_launch.raw_cmd, &conf->url_launch.argv);
tll_foreach(*initial_user_notifications, it)
tll_push_back(conf->notifications, it->item);
tll_free(*initial_user_notifications);
@ -2372,6 +2397,13 @@ out:
return ret;
}
static void
free_spawn_template(struct config_spawn_template *template)
{
free(template->raw_cmd);
free(template->argv);
}
void
config_free(struct config conf)
{
@ -2381,8 +2413,8 @@ config_free(struct config conf)
free(conf.app_id);
free(conf.word_delimiters);
free(conf.scrollback.indicator.text);
free(conf.notify.raw_cmd);
free(conf.notify.argv);
free_spawn_template(&conf.notify);
free_spawn_template(&conf.url_launch);
for (size_t i = 0; i < ALEN(conf.fonts); i++) {
tll_foreach(conf.fonts[i], it)
config_font_destroy(&it->item);

View file

@ -66,6 +66,11 @@ struct pt_or_px {
float pt;
};
struct config_spawn_template {
char *raw_cmd;
char **argv;
};
struct config {
char *term;
char *shell;
@ -198,10 +203,8 @@ struct config {
SELECTION_TARGET_BOTH
} selection_target;
struct {
char *raw_cmd;
char **argv;
} notify;
struct config_spawn_template notify;
struct config_spawn_template url_launch;
struct {
enum fcft_scaling_filter fcft_filter;

View file

@ -225,6 +225,10 @@ in this order:
Default: _notify-send -a foot -i foot ${title} ${body}_.
*url-launch*
Command to execute when opening URLs. _${url}_ will be replaced
with the actual URL. Default: _xdg-open ${url}_.
*selection-target*
Clipboard target to automatically copy selected text to. One of
*none*, *primary*, *clipboard* or *both*. Default: _primary_.

View file

@ -20,10 +20,12 @@
# pad=2x2 # optionally append 'center'
# resize-delay-ms=100
# notify=notify-send -a foot -i foot ${title} ${body}
# url-launch=xdg-open ${url}
# bold-text-in-bright=no
# bell=none
# word-delimiters=,│`|:"'()[]{}<>
# notify=notify-send -a foot -i foot ${title} ${body}
# selection-target=primary
# workers=<number of logical CPUs>