mirror of
https://github.com/swaywm/sway.git
synced 2026-04-25 06:46:24 -04:00
Search for deskop files in correct directories
Signed-off-by: Felix Weilbach <felix.weilbach@t-online.de>
This commit is contained in:
parent
7f2fd4a716
commit
66d3502769
4 changed files with 41 additions and 9 deletions
|
|
@ -9,6 +9,7 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
#include <sys/stat.h>
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
|
|
@ -162,3 +163,8 @@ char *append_path_safe(const char *base_path, const char *append_path) {
|
|||
snprintf(path, path_len, "%s/%s", base_path, append_path);
|
||||
return path;
|
||||
}
|
||||
|
||||
bool dir_exists(char *path) {
|
||||
struct stat sb;
|
||||
return stat(path, &sb) == 0 && S_ISDIR(sb.st_mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,4 +69,6 @@ bool sway_set_cloexec(int fd, bool cloexec);
|
|||
|
||||
char *append_path_safe(const char *base_path, const char *append_path);
|
||||
|
||||
bool dir_exists(char *path);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <wordexp.h>
|
||||
|
||||
#include "swaybar/icon.h"
|
||||
#include "desktop.h"
|
||||
|
|
@ -14,9 +15,38 @@
|
|||
|
||||
static list_t *get_desktop_files_basedirs() {
|
||||
list_t *basedirs = create_list();
|
||||
// TODO: Get correct list of directories
|
||||
list_add(basedirs, "/usr/share/applications");
|
||||
return basedirs;
|
||||
|
||||
char *data_home = getenv("XDG_DATA_HOME");
|
||||
list_add(basedirs,
|
||||
strdup(data_home && *data_home
|
||||
? "$XDG_DATA_HOME/applications"
|
||||
: "$HOME/.local/share/applications"));
|
||||
char *data_dirs = getenv("XDG_DATA_DIRS");
|
||||
if (!(data_dirs && *data_dirs)) {
|
||||
data_dirs = "/usr/local/share:/usr/share";
|
||||
}
|
||||
data_dirs = strdup(data_dirs);
|
||||
char *dir = strtok(data_dirs, ":");
|
||||
do {
|
||||
char *path = append_path_safe(dir, "applications");
|
||||
list_add(basedirs, path);
|
||||
} while ((dir = strtok(NULL, ":")));
|
||||
free(data_dirs);
|
||||
|
||||
list_t *basedirs_expanded = create_list();
|
||||
for (int i = 0; i < basedirs->length; ++i) {
|
||||
wordexp_t p;
|
||||
if (wordexp(basedirs->items[i], &p, WRDE_UNDEF) == 0) {
|
||||
if (dir_exists(p.we_wordv[0])) {
|
||||
list_add(basedirs_expanded, strdup(p.we_wordv[0]));
|
||||
}
|
||||
wordfree(&p);
|
||||
}
|
||||
}
|
||||
|
||||
list_free_items_and_destroy(basedirs);
|
||||
|
||||
return basedirs_expanded;
|
||||
}
|
||||
|
||||
static char *load_desktop_entry(const char *app_name, list_t *basedirs) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <wordexp.h>
|
||||
#include "swaybar/icon.h"
|
||||
|
|
@ -20,11 +19,6 @@ static int cmp_id(const void *item, const void *cmp_to) {
|
|||
return strcmp(item, cmp_to);
|
||||
}
|
||||
|
||||
static bool dir_exists(char *path) {
|
||||
struct stat sb;
|
||||
return stat(path, &sb) == 0 && S_ISDIR(sb.st_mode);
|
||||
}
|
||||
|
||||
static list_t *get_basedirs(void) {
|
||||
list_t *basedirs = create_list();
|
||||
list_add(basedirs, strdup("$HOME/.icons")); // deprecated
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue