Skip to content
Myr

launch-prefix: Pass more environment variables

Before adoption: this commit came in with the history the project adopted, so no landing records it.

For more advanced launchers, this saves them reparsing the .desktop file to get what they need. Fixes #292

authored by Mark Stosberg · committed by Daniel Eklöf · parent ccf43f3 · Browse files · 7 files+157 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+157 added−13 removed

  • other:+157 added−13 removed

7 files+157 added−13 removed

modified:doc/fuzzel.1.scd+3 added-2 removed
405 unmodified lines
406407*--launch-prefix*=_COMMAND_408 Command to launch XDG applications with.409 If set, fuzzel will pass the Desktop File ID of the chosen application410 (see the Desktop Entry specification) in the FUZZEL_DESKTOP_FILE_ID411 environment variables. Default: _not set_.410 (see the Desktop Entry specification) in the DESKTOP_ENTRY_ID411 environment variable (also exported as FUZZEL_DESKTOP_FILE_ID for412 backward compatibility). Default: _not set_.413414*--list-executables-in-path*415 Include executables from the PATH environment variable. Applies to416 the normal application mode, not the dmenu mode.
242 unmodified lines
modified:doc/fuzzel.ini.5.scd+16 added-3 removed
247 unmodified lines
248 from the PATH environment variable. Default: _no_.249250*launch-prefix*251 Prefix to add before argv of executed program.252 If set, fuzzel will pass the Desktop File ID of the chosen application253 (see the Desktop Entry specification) in the FUZZEL_DESKTOP_FILE_ID254 environment variables.252 If set, fuzzel will pass desktop file metadata through environment253 variables:254255 - DESKTOP_ENTRY_ID (also exported as FUZZEL_DESKTOP_FILE_ID for backward compatibility)256 - DESKTOP_ENTRY_PATH257 - DESKTOP_ENTRY_NAME258 - DESKTOP_ENTRY_COMMENT259 - DESKTOP_ENTRY_NAME_L (Localized)260 - DESKTOP_ENTRY_COMMENT_L (Localized)261 - DESKTOP_ENTRY_ICON262 And if launching an action:263 - DESKTOP_ENTRY_ACTION (Action identifier)264 - DESKTOP_ENTRY_ACTION_NAME265 - DESKTOP_ENTRY_ACTION_NAME_L (Localized)266 - DESKTOP_ENTRY_ACTION_ICON267268 Default: _not set_.269270*anchor*271 Set window anchor, i.e. where on screen the window will be
454 unmodified lines
modified:application.c+75 added-1 removed
167 unmodified lines
168 unescaped = xmalloc(launch_len + execute_len + 2 /* whitespace + null terminator */);169 memcpy(unescaped, launch_prefix, launch_len);170 unescaped[launch_len] = ' ';171 execute_dest = unescaped + launch_len + 1;172173 if (id != NULL) {174 setenv("DESKTOP_ENTRY_ID", id, 1);175 /* Keep FUZZEL_DESKTOP_FILE_ID for backward compatibility */176 setenv("FUZZEL_DESKTOP_FILE_ID", id, 1);177 } else {175 LOG_WARN("No Desktop File ID, not setting FUZZEL_DESKTOP_FILE_ID");178 LOG_WARN("No Desktop File ID, not setting DESKTOP_ENTRY_ID");179 }180181 if (app != NULL) {182 if (app->desktop_file_path != NULL) {183 setenv("DESKTOP_ENTRY_PATH", app->desktop_file_path, 1);184 }185186 if (app->action_id != NULL) {187 setenv("DESKTOP_ENTRY_ACTION", app->action_id, 1);188 }189190 if (app->original_name != NULL) {191 char *name_utf8 = ac32tombs(app->original_name);192 setenv("DESKTOP_ENTRY_NAME", name_utf8, 1);193 free(name_utf8);194 }195196 if (app->localized_name != NULL) {197 char *localized_name_utf8 = ac32tombs(app->localized_name);198 setenv("DESKTOP_ENTRY_NAME_L", localized_name_utf8, 1);199 free(localized_name_utf8);200 }201202 if (app->comment != NULL) {203 char *comment_utf8 = ac32tombs(app->comment);204 setenv("DESKTOP_ENTRY_COMMENT", comment_utf8, 1);205 setenv("DESKTOP_ENTRY_COMMENT_L", comment_utf8, 1); /* TODO: distinguish localized */206 free(comment_utf8);207 }208209 if (app->icon.name != NULL) {210 setenv("DESKTOP_ENTRY_ICON", app->icon.name, 1);211 }212213 if (app->original_generic_name != NULL) {214 char *generic_name_utf8 = ac32tombs(app->original_generic_name);215 setenv("DESKTOP_ENTRY_GENERICNAME", generic_name_utf8, 1);216 free(generic_name_utf8);217 }218219 if (app->localized_generic_name != NULL) {220 char *localized_generic_name_utf8 = ac32tombs(app->localized_generic_name);221 setenv("DESKTOP_ENTRY_GENERICNAME_L", localized_generic_name_utf8, 1);222 free(localized_generic_name_utf8);223 }224225 if (app->action_name != NULL) {226 char *action_name_utf8 = ac32tombs(app->action_name);227 setenv("DESKTOP_ENTRY_ACTION_NAME", action_name_utf8, 1);228 free(action_name_utf8);229 }230231 if (app->localized_action_name != NULL) {232 char *localized_action_name_utf8 = ac32tombs(app->localized_action_name);233 setenv("DESKTOP_ENTRY_ACTION_NAME_L", localized_action_name_utf8, 1);234 free(localized_action_name_utf8);235 }236237 if (app->action_id != NULL && app->icon.name != NULL) {238 setenv("DESKTOP_ENTRY_ACTION_ICON", app->icon.name, 1);239 }240 }241 } else {242 unescaped = xmalloc(execute_len + 1);243 execute_dest = unescaped;244 }
160 unmodified lines
405 free(app->generic_name);406 free(app->comment);407 free(app->icon.name);408409 /* Free additional metadata fields */410 free(app->desktop_file_path);411 free(app->action_id);412 free(app->original_name);413 free(app->localized_name);414 free(app->action_name);415 free(app->localized_action_name);416 free(app->original_generic_name);417 free(app->localized_generic_name);418419 tll_free_and_free(app->keywords, free);420 tll_free_and_free(app->categories, free);421422 free(app->dmenu_input);
54 unmodified lines
modified:application.h+10 added
68 unmodified lines
69 char32_t *title;70 char32_t *render_title;71 size_t index;7273 /* Additional metadata for desktop entries */74 char *desktop_file_path; /* Full path to the .desktop file */75 char *action_id; /* Action identifier if this is an action entry */76 char32_t *original_name; /* Non-localized name */77 char32_t *localized_name; /* Localized name */78 char32_t *action_name; /* Action name (if applicable) */79 char32_t *localized_action_name; /* Localized action name */80 char32_t *original_generic_name; /* Non-localized generic name */81 char32_t *localized_generic_name; /* Localized generic name */8283 /*84 * To get good search performance, we cache both the lower-case85 * versions of metadata, and their (string) lengths. This way, we86 * can avoid having to call c32len() and toc32lower() over and
43 unmodified lines
modified:CHANGELOG.md+8 added
55 unmodified lines
56 match (if you had selected an entry further down the list, with57 either the mouse or the arrow keys). Previously, the same _index_58 would stay selected (meaning the actually selected entry may have59 changed). ([#684][684]).60 * More environment variables are now passed to --launch-prefix. This saves61 launcher that need more details from reparsing the desktop file, spending62 up launching. ([#292][292])6364[292]: https://codeberg.org/dnkl/fuzzel/issues/29265[684]: https://codeberg.org/dnkl/fuzzel/issues/6846667### Deprecated6869 * FUZZEL_DESKTOP_FILE_ID has been deprecated and will be removed in a future release. The replacement is DESKTOP_ENTRY_ID which is consistent with other DESKTOP_ENTRY_* variables we now export.7071### Removed72### Fixed7374* `--with-nth` and `--accept-nth` crashing if a column is empty
1066 unmodified lines
modified:icon.c+1 added-1 removed
472 unmodified lines
473 resvg_options_destroy(opt);474475 if (result != RESVG_OK || tree == NULL) {476 /* Only log actual parsing errors, not just files that aren't valid SVGs */477 if (result == RESVG_ERROR_PARSING_FAILED || 477 if (result == RESVG_ERROR_PARSING_FAILED ||478 result == RESVG_ERROR_MALFORMED_GZIP ||479 result == RESVG_ERROR_INVALID_SIZE) {480 LOG_DBG("%s: resvg failed to parse SVG (code %d)", file_name, result);481 }
418 unmodified lines
modified:xdg.c+44 added-6 removed
57 unmodified lines
58 char *path;59 bool visible;60 bool use_terminal;61 bool no_startup_notify;62 char *action_id;63};6465static bool66filter_desktop_entry(const struct action *act, const char_list_t *desktops)
22 unmodified lines
89parse_desktop_file(int fd, char *id, const char32_t *file_basename_lowercase,90 const char *terminal, bool include_actions,91 bool filter_desktops, char_list_t *desktops,92 const struct locale_variants *lc_messages,92 application_llist_t *applications)93 application_llist_t *applications, const char *desktop_file_path)94{95 FILE *f = fdopen(fd, "re");96 if (f == NULL) {97 close(fd);
4 unmodified lines
102103 tll(char *) action_names = tll_init();104105 tll(struct action) actions = tll_init();105 tll_push_back(actions, ((struct action){.visible = true}));106 tll_push_back(actions, ((struct action){.visible = true, .action_id = NULL}));107 struct action *action = &tll_back(actions);108 struct action *default_action = action;109110 while (true) {
55 unmodified lines
166 {167 tll_push_back(actions, ((struct action){0}));168 action = &tll_back(actions);169170171 action->action_id = xstrndup(action_name, name_len);172 action->generic_name =173 default_action->generic_name != NULL174 ? xc32dup(default_action->generic_name) : NULL;175 action->comment = default_action->comment != NULL
280 unmodified lines
456 free(a->exec);457 a->exec = exec_with_terminal;458 }459460 /* Save original action name before modifying title */461 char32_t *saved_action_name = a->name ? xc32dup(a->name) : NULL;462 char32_t *saved_default_name = default_action->name ? xc32dup(default_action->name) : NULL;463464 /* Save original generic name before converting to lowercase */465 char32_t *saved_generic_name = a->generic_name ? xc32dup(a->generic_name) : NULL;466 char32_t *saved_default_generic_name = default_action->generic_name ? xc32dup(default_action->generic_name) : NULL;467468 char32_t *title = a->name;469 if (a != default_action) {470 title = xc32join3(default_action->name, U" — ", a->name);471 free(a->name);
55 unmodified lines
527 .icon = {.name = a->icon},528 .visible = a->visible && (!filter_desktops || filter_desktop_entry(a, desktops)),529 .startup_notify = !a->no_startup_notify,530 .count = 0,531 /* Additional metadata */532 .desktop_file_path = xstrdup(desktop_file_path),533 .action_id = a->action_id ? xstrdup(a->action_id) : NULL,534 .original_name = saved_default_name,535 .localized_name = saved_action_name ? xc32dup(saved_action_name) : NULL,536 .action_name = (a->action_id && saved_action_name) ? xc32dup(saved_action_name) : NULL,537 .localized_action_name = (a->action_id && saved_action_name) ? xc32dup(saved_action_name) : NULL,538 .original_generic_name = saved_default_generic_name,539 .localized_generic_name = saved_generic_name,540 };541 tll_push_back(*applications, app);542 tll_free_and_free(a->onlyshowin, free);543 tll_free_and_free(a->notshowin, free);544545 /* Clean up saved names */546 if (a == default_action) {547 /* All saved names already transferred to app: saved_action_name, saved_default_name,548 saved_generic_name, saved_default_generic_name */549 } else {550 /* saved_action_name and saved_generic_name already transferred */551 free(saved_action_name);552 }553 }554555 free(id);556 tll_foreach(actions, it) {557 free(it->item.action_id);558 }559 tll_free(actions);560 tll_free_and_free(action_names, free);561}562
8 unmodified lines
571572static void573scan_dir(int base_fd, const char *terminal, bool include_actions,574 bool filter_desktop, char_list_t *desktops,543 application_llist_t *applications, const char *base_id)575 application_llist_t *applications, const char *base_id, const char *base_path)576{577 DIR *d = fdopendir(base_fd);578 if (d == NULL) {579 LOG_ERRNO("failed to open directory");
53 unmodified lines
633 continue;634 }635636 char *nested_base_id = new_id(base_id, e->d_name);637 char nested_base_path[PATH_MAX];638 xsnprintf(nested_base_path, sizeof(nested_base_path), "%s/%s", base_path, e->d_name);639 scan_dir(dir_fd, terminal, include_actions,640 filter_desktop, desktops,607 applications, nested_base_id);641 applications, nested_base_id, nested_base_path);642 free(nested_base_id);643 close(dir_fd);644 } else if (S_ISREG(st.st_mode)) {645 /* Skip files not ending with ".desktop" */
40 unmodified lines
686 }687 }688689 if (!already_added) {690 /* Construct full desktop file path */691 char desktop_file_path[PATH_MAX];692 xsnprintf(desktop_file_path, sizeof(desktop_file_path), "%s/%s", base_path, e->d_name);693694 parse_desktop_file(695 fd, id, wfile_basename, terminal, include_actions,696 filter_desktop, desktops,659 &lc_messages, applications);697 &lc_messages, applications, desktop_file_path);698 /* fd closed by parse_desktop_file() */699 } else {700 free(id);701 close(fd);
30 unmodified lines
732 sprintf(path, "%s/applications", it->item.path);733734 int fd = open(path, O_RDONLY | O_CLOEXEC);735 if (fd != -1) {698 scan_dir(fd, terminal, include_actions, filter_desktop, desktops, &apps, NULL);736 scan_dir(fd, terminal, include_actions, filter_desktop, desktops, &apps, NULL, path);737 close(fd);738 }739 }740
164 unmodified lines