1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[Modes] Support icons off multiple icons.

This commit is contained in:
Dave Davenport 2022-06-27 20:52:12 +02:00
parent 9c18aaef22
commit ceb2b9d295
7 changed files with 37 additions and 6 deletions

View file

@ -12,6 +12,7 @@ typedef struct {
char *icon_name;
/** Async icon fetch handler. */
uint32_t icon_fetch_uid;
uint32_t icon_fetch_size;
/** Hidden meta keywords. */
char *meta;

View file

@ -127,6 +127,7 @@ static void read_add_block(DmenuModePrivateData *pd, Block **block, char *data,
gsize data_len = len;
// Init.
(*block)->values[(*block)->length].icon_fetch_uid = 0;
(*block)->values[(*block)->length].icon_fetch_size = 0;
(*block)->values[(*block)->length].icon_name = NULL;
(*block)->values[(*block)->length].meta = NULL;
(*block)->values[(*block)->length].info = NULL;
@ -156,6 +157,7 @@ static void read_add(DmenuModePrivateData *pd, char *data, gsize len) {
}
// Init.
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_name = NULL;
pd->cmd_list[pd->cmd_list_length].meta = NULL;
pd->cmd_list[pd->cmd_list_length].info = NULL;
@ -629,11 +631,12 @@ static cairo_surface_t *dmenu_get_icon(const Mode *sw,
if (dr->icon_name == NULL) {
return NULL;
}
if (dr->icon_fetch_uid > 0) {
if (dr->icon_fetch_uid > 0 && dr->icon_fetch_size == height) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
uint32_t uid = dr->icon_fetch_uid =
rofi_icon_fetcher_query(dr->icon_name, height);
dr->icon_fetch_size = height;
return rofi_icon_fetcher_get(uid);
}

View file

@ -130,6 +130,7 @@ typedef struct {
gint sort_index;
/* UID for the icon to display */
uint32_t icon_fetch_uid;
uint32_t icon_fetch_size;
/* Type of desktop file */
DRunDesktopEntryType type;
} DRunModeEntry;
@ -620,6 +621,7 @@ static void read_desktop_file(DRunModePrivateData *pd, const char *root,
}
pd->entry_list[pd->cmd_list_length].icon_size = 0;
pd->entry_list[pd->cmd_list_length].icon_fetch_uid = 0;
pd->entry_list[pd->cmd_list_length].icon_fetch_size = 0;
pd->entry_list[pd->cmd_list_length].root = g_strdup(root);
pd->entry_list[pd->cmd_list_length].path = g_strdup(path);
pd->entry_list[pd->cmd_list_length].desktop_id = g_strdup(id);
@ -1336,11 +1338,12 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
g_return_val_if_fail(pd->entry_list != NULL, NULL);
DRunModeEntry *dr = &(pd->entry_list[selected_line]);
if (dr->icon_name != NULL) {
if (dr->icon_fetch_uid > 0) {
if (dr->icon_fetch_uid > 0 && dr->icon_fetch_size == height) {
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
return icon;
}
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height);
dr->icon_fetch_size = height;
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
return icon;
}

View file

@ -84,6 +84,7 @@ typedef struct {
char *path;
enum FBFileType type;
uint32_t icon_fetch_uid;
uint32_t icon_fetch_size;
gboolean link;
time_t time;
} FBFile;
@ -234,6 +235,7 @@ static void get_file_browser(Mode *sw) {
pd->array[pd->array_length].path = NULL;
pd->array[pd->array_length].type = UP;
pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].icon_fetch_size = 0;
pd->array[pd->array_length].link = FALSE;
pd->array[pd->array_length].time = -1;
pd->array_length++;
@ -265,6 +267,7 @@ static void get_file_browser(Mode *sw) {
pd->array[pd->array_length].type =
(rd->d_type == DT_DIR) ? DIRECTORY : RFILE;
pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].icon_fetch_size = 0;
pd->array[pd->array_length].link = FALSE;
if (file_browser_config.sorting_method == FB_SORT_TIME) {
@ -284,6 +287,7 @@ static void get_file_browser(Mode *sw) {
pd->array[pd->array_length].path =
g_build_filename(cdir, rd->d_name, NULL);
pd->array[pd->array_length].icon_fetch_uid = 0;
pd->array[pd->array_length].icon_fetch_size = 0;
pd->array[pd->array_length].link = TRUE;
// Default to file.
pd->array[pd->array_length].type = RFILE;
@ -562,7 +566,7 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
(FileBrowserModePrivateData *)mode_get_private_data(sw);
g_return_val_if_fail(pd->array != NULL, NULL);
FBFile *dr = &(pd->array[selected_line]);
if (dr->icon_fetch_uid > 0) {
if (dr->icon_fetch_uid > 0 && dr->icon_fetch_size == height) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
if (rofi_icon_fetcher_file_is_image(dr->path)) {
@ -570,6 +574,7 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
} else {
dr->icon_fetch_uid = rofi_icon_fetcher_query(icon_name[dr->type], height);
}
dr->icon_fetch_size = height;
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}

View file

@ -65,6 +65,7 @@
typedef struct {
char *entry;
uint32_t icon_fetch_uid;
uint32_t icon_fetch_size;
/* Surface holding the icon. */
cairo_surface_t *icon;
} RunEntry;
@ -203,6 +204,7 @@ static RunEntry *get_apps_external(RunEntry *retv, unsigned int *length,
retv[(*length)].entry = g_strdup(buffer);
retv[(*length)].icon = NULL;
retv[(*length)].icon_fetch_uid = 0;
retv[(*length)].icon_fetch_size = 0;
(*length)++;
}
@ -218,6 +220,7 @@ static RunEntry *get_apps_external(RunEntry *retv, unsigned int *length,
retv[(*length)].entry = NULL;
retv[(*length)].icon = NULL;
retv[(*length)].icon_fetch_uid = 0;
retv[(*length)].icon_fetch_size = 0;
return retv;
}
@ -328,9 +331,11 @@ static RunEntry *get_apps(unsigned int *length) {
retv[(*length)].entry = name;
retv[(*length)].icon = NULL;
retv[(*length)].icon_fetch_uid = 0;
retv[(*length)].icon_fetch_size = 0;
retv[(*length) + 1].entry = NULL;
retv[(*length) + 1].icon = NULL;
retv[(*length) + 1].icon_fetch_uid = 0;
retv[(*length) + 1].icon_fetch_size = 0;
(*length)++;
}
@ -537,7 +542,7 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
g_return_val_if_fail(pd->cmd_list != NULL, NULL);
RunEntry *dr = &(pd->cmd_list[selected_line]);
if (dr->icon_fetch_uid > 0) {
if (dr->icon_fetch_uid > 0 && dr->icon_fetch_size == height) {
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
return icon;
}
@ -545,6 +550,7 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
char **str = g_strsplit(dr->entry, " ", 2);
if (str) {
dr->icon_fetch_uid = rofi_icon_fetcher_query(str[0], height);
dr->icon_fetch_size = height;
g_strfreev(str);
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
return icon;

View file

@ -224,6 +224,7 @@ static DmenuScriptEntry *execute_executor(Mode *sw, char *arg,
retv[(*length)].meta = NULL;
retv[(*length)].info = NULL;
retv[(*length)].icon_fetch_uid = 0;
retv[(*length)].icon_fetch_size = 0;
retv[(*length)].nonselectable = FALSE;
if (buf_length > 0 && (read_length > (ssize_t)buf_length)) {
dmenuscript_parse_entry_extras(sw, &(retv[(*length)]),
@ -430,10 +431,11 @@ script_get_icon(const Mode *sw, unsigned int selected_line, int height) {
if (dr->icon_name == NULL) {
return NULL;
}
if (dr->icon_fetch_uid > 0) {
if (dr->icon_fetch_uid > 0 && dr->icon_fetch_size == height) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height);
dr->icon_fetch_size = height;
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
@ -467,7 +469,8 @@ void script_mode_gather_user_scripts(void) {
const char *file = NULL;
while ((file = g_dir_read_name(sd)) != NULL) {
char *sp = g_build_filename(cpath, "rofi", "scripts", file, NULL);
user_scripts = g_realloc(user_scripts, sizeof(ScriptUser)*(num_scripts + 1));
user_scripts =
g_realloc(user_scripts, sizeof(ScriptUser) * (num_scripts + 1));
user_scripts[num_scripts].path = sp;
user_scripts[num_scripts].name = g_strdup(file);
char *dot = strrchr(user_scripts[num_scripts].name, '.');

View file

@ -125,6 +125,7 @@ typedef struct {
cairo_surface_t *icon;
gboolean icon_checked;
uint32_t icon_fetch_uid;
uint32_t icon_fetch_size;
gboolean thumbnail_checked;
} client;
@ -1028,6 +1029,14 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
if (c == NULL) {
return NULL;
}
if (c->icon_fetch_size != size) {
if (c->icon) {
cairo_surface_destroy(c->icon);
c->icon = NULL;
c->thumbnail_checked = FALSE;
c->icon_checked = FALSE;
}
}
if (config.window_thumbnail && c->thumbnail_checked == FALSE) {
c->icon = x11_helper_get_screenshot_surface_window(c->window, size);
c->thumbnail_checked = TRUE;
@ -1045,6 +1054,7 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
g_free(class_lower);
return rofi_icon_fetcher_get(c->icon_fetch_uid);
}
c->icon_fetch_size = size;
return c->icon;
}