From b6cf448f3dc815e8715f88ee0040ce82cdaad4be Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Wed, 20 Apr 2022 00:23:46 +0200 Subject: [PATCH] Try to fix bug in GNOME for duplicate entries in Ly --- src/utils.c | 22 ++++++++++++++++++++-- src/utils.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/utils.c b/src/utils.c index b7bfabc..5240b38 100644 --- a/src/utils.c +++ b/src/utils.c @@ -95,11 +95,13 @@ void desktop_crawl( strncat(path, dir_info->d_name, (sizeof (path)) - 1); configator(&desktop_config, path); + const char wayland_specifier[] = " (Wayland)"; + const char gnome_wayland_specifier[] = " on Wayland"; + // if these are wayland sessions, add " (Wayland)" to their names, // as long as their names don't already contain that string if (server == DS_WAYLAND && config.wayland_specifier) { - const char wayland_specifier[] = " (Wayland)"; if (strstr(name, wayland_specifier) == NULL) { name = realloc(name, (strlen(name) + sizeof(wayland_specifier) + 1)); @@ -110,7 +112,10 @@ void desktop_crawl( if ((name != NULL) && (exec != NULL)) { - input_desktop_add(target, name, exec, server); + if (!(strstr(name, wayland_specifier) != NULL && contains(target->list, target->len, gnome_wayland_specifier) == 1)) + { + input_desktop_add(target, name, exec, server); + } } name = NULL; @@ -274,3 +279,16 @@ void load(struct desktop* desktop, struct text* login) fclose(fp); free(line); } + +int contains(char** ptr, int len, const char* substr) +{ + for (int i = 0; i < len; i++) + { + if (strstr(ptr[i], substr) != NULL) + { + return 1; + } + } + + return 0; +} \ No newline at end of file diff --git a/src/utils.h b/src/utils.h index 0913580..37addda 100644 --- a/src/utils.h +++ b/src/utils.h @@ -11,5 +11,6 @@ void free_hostname(); void switch_tty(struct term_buf* buf); void save(struct desktop* desktop, struct text* login); void load(struct desktop* desktop, struct text* login); +int contains(char** ptr, int len, const char* substr); #endif