Skip to content
Merged
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
4 changes: 3 additions & 1 deletion include/modes/dmenuscriptshared.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ typedef struct {
char *display;

/** Icon name to display. */
char *icon_name;
char **icon_name;
/** Async icon fetch handler. */
uint32_t icon_fetch_uid;
uint32_t icon_fetch_size;
guint icon_fetch_scale;
/** Current fallback icon index being tried */
int icon_fallback_index;
/** Hidden meta keywords. */
char *meta;

Expand Down
40 changes: 34 additions & 6 deletions source/modes/dmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static void read_add_block(DmenuModePrivateData *pd, Block **block, char *data,
(*block)->values[(*block)->length].icon_fetch_uid = 0;
(*block)->values[(*block)->length].icon_fetch_size = 0;
(*block)->values[(*block)->length].icon_fetch_scale = 0;
(*block)->values[(*block)->length].icon_fallback_index = 0;
(*block)->values[(*block)->length].icon_name = NULL;
(*block)->values[(*block)->length].meta = NULL;
(*block)->values[(*block)->length].info = NULL;
Expand Down Expand Up @@ -169,6 +170,7 @@ static void read_add(DmenuModePrivateData *pd, char *data, gsize len) {
pd->cmd_list[pd->cmd_list_length].icon_fetch_uid = 0;
pd->cmd_list[pd->cmd_list_length].icon_fetch_size = 0;
pd->cmd_list[pd->cmd_list_length].icon_fetch_scale = 0;
pd->cmd_list[pd->cmd_list_length].icon_fallback_index = 0;
pd->cmd_list[pd->cmd_list_length].icon_name = NULL;
pd->cmd_list[pd->cmd_list_length].display = NULL;
pd->cmd_list[pd->cmd_list_length].meta = NULL;
Expand Down Expand Up @@ -486,7 +488,7 @@ static void dmenu_mode_free(Mode *sw) {
for (size_t i = 0; i < pd->cmd_list_length; i++) {
if (pd->cmd_list[i].entry) {
g_free(pd->cmd_list[i].entry);
g_free(pd->cmd_list[i].icon_name);
g_strfreev(pd->cmd_list[i].icon_name);
g_free(pd->cmd_list[i].display);
g_free(pd->cmd_list[i].meta);
g_free(pd->cmd_list[i].info);
Expand Down Expand Up @@ -724,12 +726,38 @@ static cairo_surface_t *dmenu_get_icon(const Mode *sw,
if (dr->icon_name == NULL) {
return NULL;
}
uint32_t uid = dr->icon_fetch_uid =
rofi_icon_fetcher_query(dr->icon_name, height);
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;

return rofi_icon_fetcher_get(uid);
if (dr->icon_fetch_uid > 0) {
cairo_surface_t *surface = NULL;
gboolean query_done = rofi_icon_fetcher_get_ex(dr->icon_fetch_uid, &surface);

if (surface != NULL) {
return surface;
} else if (query_done) {
dr->icon_fallback_index++;
dr->icon_fetch_uid = 0;
} else {
return NULL;
}
}

char *current_icon = NULL;
if (dr->icon_name && dr->icon_fallback_index >= 0) {
int icon_count = g_strv_length(dr->icon_name);
if (dr->icon_fallback_index < icon_count) {
current_icon = dr->icon_name[dr->icon_fallback_index];
}
}
if ( current_icon ){
dr->icon_fetch_uid = rofi_icon_fetcher_query(current_icon, height);
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;

} else {
dr->icon_fetch_uid = 0;
}

return NULL;
}

static void dmenu_finish(DmenuModePrivateData *pd, RofiViewState *state,
Expand Down
45 changes: 36 additions & 9 deletions source/modes/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw,
*(extra) = NULL;
*(extra + 1) = NULL;
if (strcasecmp(key, "icon") == 0) {
entry->icon_name = value;
entry->icon_name = g_strsplit(value,",", -1);
g_free(value);
} else if (strcasecmp(key, "display") == 0) {
entry->display = value;
} else if (strcasecmp(key, "meta") == 0) {
Expand Down Expand Up @@ -409,7 +410,7 @@ static void script_mode_destroy(Mode *sw) {
if (rmpd != NULL) {
for (unsigned int i = 0; i < rmpd->cmd_list_length; i++) {
g_free(rmpd->cmd_list[i].entry);
g_free(rmpd->cmd_list[i].icon_name);
g_strfreev(rmpd->cmd_list[i].icon_name);
g_free(rmpd->cmd_list[i].display);
g_free(rmpd->cmd_list[i].meta);
}
Expand Down Expand Up @@ -518,20 +519,46 @@ static cairo_surface_t *script_get_icon(const Mode *sw,
unsigned int height) {
ScriptModePrivateData *pd =
(ScriptModePrivateData *)mode_get_private_data(sw);

const guint scale = display_scale();

g_return_val_if_fail(pd->cmd_list != NULL, NULL);
DmenuScriptEntry *dr = &(pd->cmd_list[selected_line]);
if (dr->icon_name == NULL) {
return NULL;
}
if (dr->icon_fetch_uid > 0 && dr->icon_fetch_size == height &&
dr->icon_fetch_scale == scale) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);

if (dr->icon_fetch_uid > 0) {
cairo_surface_t *surface = NULL;
gboolean query_done = rofi_icon_fetcher_get_ex(dr->icon_fetch_uid, &surface);

if (surface != NULL) {
return surface;
} else if (query_done) {
dr->icon_fallback_index++;
dr->icon_fetch_uid = 0;
} else {
return NULL;
}
}

char *current_icon = NULL;
if (dr->icon_name && dr->icon_fallback_index >= 0) {
int icon_count = g_strv_length(dr->icon_name);
if (dr->icon_fallback_index < icon_count) {
current_icon = dr->icon_name[dr->icon_fallback_index];
}
}
if ( current_icon ){
dr->icon_fetch_uid = rofi_icon_fetcher_query(current_icon, height);
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;

} else {
dr->icon_fetch_uid = 0;
}
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height);
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;
return rofi_icon_fetcher_get(dr->icon_fetch_uid);

return NULL;
}

#include "mode-private.h"
Expand Down