Skip to content

[Dmenu][Script] Add support for fallback icons #2122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/rofi-script.5.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ For example:

The following options are supported:

- **icon**: Set the icon for that row.
- **icon**: Set the icon for that row. Multiple fallback icons can be specified using comma-separated values.

- **display**: Replace the displayed string. (Original string will still be used for filtering)

Expand All @@ -158,7 +158,7 @@ The following options are supported:
multiple entries can be passed using the `\x1f` separator.

```bash
echo -en "aap\0icon\x1ffolder\x1finfo\x1ftest\n"
echo -en "aap\0icon\x1ffolder,inode-directory\x1finfo\x1ftest\n"
```

## Executing external program
Expand Down
31 changes: 28 additions & 3 deletions source/modes/dmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,36 @@ static cairo_surface_t *dmenu_get_icon(const Mode *sw,
if (dr->icon_name == NULL) {
return NULL;
}
uint32_t uid = dr->icon_fetch_uid =
// Check if we have multiple icons
if (strchr(dr->icon_name, ',') == NULL) {
// Single icon case
uint32_t uid = dr->icon_fetch_uid =
rofi_icon_fetcher_query(dr->icon_name, height);
dr->icon_fetch_size = height;
dr->icon_fetch_size = height;

return rofi_icon_fetcher_get(uid);
return rofi_icon_fetcher_get(uid);
} else {
// Multiple icons case
cairo_surface_t *icon_surface = NULL;
char *icon_name_copy = g_strdup(dr->icon_name);
char *icon_iter = icon_name_copy;
char *icon = NULL;
// Try each icon in the comma-separated list until one is found
while ((icon = strsep(&icon_iter, ",")) != NULL) {
// Try to fetch this icon
uint32_t uid = rofi_icon_fetcher_query(icon, height);
icon_surface = rofi_icon_fetcher_get(uid);
// If we found an icon, store the successful parameters and break the loop
if (icon_surface != NULL) {
dr->icon_fetch_uid = uid;
dr->icon_fetch_size = height;
break;
}
}
// Free the copy of the icon list
g_free(icon_name_copy);
return icon_surface;
}
}

static void dmenu_finish(DmenuModePrivateData *pd, RofiViewState *state,
Expand Down