Try to fix bug in GNOME for duplicate entries in Ly

This commit is contained in:
AnErrupTion 2022-04-20 00:23:46 +02:00
parent bd59e5dda8
commit b6cf448f3d
2 changed files with 21 additions and 2 deletions

View File

@ -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;
}

View File

@ -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