Skip to content
Myr

xdg: only search the 'applications' subfolder

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

This *should* be the only location where the .desktop files we are interested in are. This vastly reduces startup time.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent ad09e6f · Browse files · 1 file+24 added−20 removed
This commit

State

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

Diff stats

1 file+24 added−20 removed

  • other:+24 added−20 removed

1 file+24 added−20 removed

modified:xdg.c+24 added-20 removed
149 unmodified lines
150xdg_find_programs(application_list_t *applications)151{152 const char *xdg_data_home = getenv("XDG_DATA_HOME");153 if (xdg_data_home != NULL) {154 int fd = open(xdg_data_home, O_RDONLY);155 if (fd == -1)154 int fd_base = open(xdg_data_home, O_RDONLY);155 int fd = fd_base != -1 ? openat(fd_base, "applications", O_RDONLY) : -1;156157 if (fd_base == -1 || fd == -1)158 LOG_WARN("%s: failed to open", xdg_data_home);157 else {159 else160 scan_dir(fd, applications);159 close(fd);160 }161162 close(fd);163 close(fd_base);164 } else {165 const char *home = getenv("HOME");163 char buf[strlen(home) + 1 + strlen(".local/share") + 1];164 sprintf(buf, "%s/%s", home, ".local/share");166 char buf[strlen(home) + 1 + strlen(".local/share/applications") + 1];167 sprintf(buf, "%s/%s", home, ".local/share/applications");168169 int fd = open(buf, O_RDONLY);170 if (fd == -1)171 LOG_WARN("%s: failed to open", buf);168 else {172 else173 scan_dir(fd, applications);170 close(fd);171 }174 close(fd);175 }176177 const char *_xdg_data_dirs = getenv("XDG_DATA_DIRS");178 if (_xdg_data_dirs != NULL) {
1 unmodified line
180 for (const char *data_dir = strtok(xdg_data_dirs, ":");181 data_dir != NULL;182 data_dir = strtok(NULL, ":"))183 {181 int fd = open(data_dir, O_RDONLY);182 if (fd == -1)184 int fd_base = open(data_dir, O_RDONLY);185 int fd = fd_base != -1 ? openat(fd_base, "applications", O_RDONLY) : -1;186 if (fd_base == -1 || fd == -1)187 LOG_WARN("%s: failed to open", data_dir);184 else {188 else189 scan_dir(fd, applications);186 close(fd);187 }190191 close(fd);192 close(fd_base);193 }194195 free(xdg_data_dirs);196 } else {197 static const char *const default_paths[] = {193 "/usr/local/share",194 "/usr/share",198 "/usr/local/share/applications",199 "/usr/share/applications",200 };201202 for (size_t i = 0; i < sizeof(default_paths) / sizeof(default_paths[0]); i++) {203 int fd = open(default_paths[i], O_RDONLY);204 if (fd == -1)205 LOG_WARN("%s: failed to open", default_paths[i]);201 else {206 else207 scan_dir(fd, applications);203 close(fd);204 }208 close(fd);209 }210 }211}