mirror of
https://github.com/davatorium/rofi.git
synced 2025-04-14 17:43:01 -04:00
[Dmenu][Script] Add support for fallback icons
This adds support for fallback icons in dmenu mode using comma-separated values in the icon metadata. When the primary icon is not found, subsequent icons in the list will be tried until one is successfully loaded. Example usage: "Firefox\0icon\x1ffirefox,web-browser,application-x-executable"
This commit is contained in:
parent
f0ccf4c186
commit
41daf24642
2 changed files with 30 additions and 5 deletions
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue