1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Add fallback icon option.

This commit is contained in:
Dave Davenport 2021-06-08 20:21:28 +02:00
parent 6178970499
commit cb250fa73a
5 changed files with 59 additions and 6 deletions

View file

@ -173,5 +173,7 @@ Settings config = {
/** normalize match */ /** normalize match */
.normalize_match = FALSE, .normalize_match = FALSE,
/** steal focus */ /** steal focus */
.steal_focus = FALSE .steal_focus = FALSE,
/** fallback icon */
.application_fallback_icon = NULL
}; };

View file

@ -207,6 +207,8 @@ typedef struct
gboolean normalize_match; gboolean normalize_match;
/** Steal focus */ /** Steal focus */
gboolean steal_focus; gboolean steal_focus;
/** fallback icon */
char *application_fallback_icon;
} Settings; } Settings;
/** Global Settings structure. */ /** Global Settings structure. */
extern Settings config; extern Settings config;

View file

@ -169,6 +169,10 @@ struct _DRunModePrivateData
char *old_completer_input; char *old_completer_input;
uint32_t selected_line; uint32_t selected_line;
char *old_input; char *old_input;
/** fallback icon */
uint32_t fallback_icon_fetch_uid;
cairo_surface_t *fallback_icon;
}; };
struct RegexEvalArg struct RegexEvalArg
@ -1242,6 +1246,17 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in
return retv; return retv;
} }
static cairo_surface_t *fallback_icon ( DRunModePrivateData *pd, int height )
{
if ( config.application_fallback_icon ) {
// FALLBACK
if ( pd->fallback_icon_fetch_uid > 0 ) {
return rofi_icon_fetcher_get ( pd->fallback_icon_fetch_uid );
}
pd->fallback_icon_fetch_uid = rofi_icon_fetcher_query ( config.application_fallback_icon, height );
}
return NULL;
}
static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height ) static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height )
{ {
DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw ); DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw );
@ -1254,10 +1269,18 @@ static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line,
return NULL; return NULL;
} }
if ( dr->icon_fetch_uid > 0 ) { if ( dr->icon_fetch_uid > 0 ) {
return rofi_icon_fetcher_get ( dr->icon_fetch_uid ); cairo_surface_t *icon = rofi_icon_fetcher_get ( dr->icon_fetch_uid );
if ( icon ) {
return icon;
}
return fallback_icon ( pd, height );
} }
dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->icon_name, height ); dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->icon_name, height );
return rofi_icon_fetcher_get ( dr->icon_fetch_uid ); cairo_surface_t *icon = rofi_icon_fetcher_get ( dr->icon_fetch_uid );
if ( icon ) {
return icon;
}
return fallback_icon ( pd, height );
} }
static char *drun_get_completion ( const Mode *sw, unsigned int index ) static char *drun_get_completion ( const Mode *sw, unsigned int index )

View file

@ -87,6 +87,9 @@ typedef struct
Mode *completer; Mode *completer;
char *old_completer_input; char *old_completer_input;
/** fallback icon */
uint32_t fallback_icon_fetch_uid;
cairo_surface_t *fallback_icon;
} RunModePrivateData; } RunModePrivateData;
/** /**
@ -520,6 +523,18 @@ static char *run_get_message ( const Mode *sw )
} }
return NULL; return NULL;
} }
static cairo_surface_t *fallback_icon ( RunModePrivateData *pd, int height )
{
if ( config.application_fallback_icon ) {
// FALLBACK
if ( pd->fallback_icon_fetch_uid > 0 ) {
return rofi_icon_fetcher_get ( pd->fallback_icon_fetch_uid );
}
pd->fallback_icon_fetch_uid = rofi_icon_fetcher_query ( config.application_fallback_icon, height );
}
return NULL;
}
static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height ) static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height )
{ {
RunModePrivateData *pd = (RunModePrivateData *) mode_get_private_data ( sw ); RunModePrivateData *pd = (RunModePrivateData *) mode_get_private_data ( sw );
@ -528,16 +543,25 @@ static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line,
} }
g_return_val_if_fail ( pd->cmd_list != NULL, NULL ); g_return_val_if_fail ( pd->cmd_list != NULL, NULL );
RunEntry *dr = &( pd->cmd_list[selected_line] ); RunEntry *dr = &( pd->cmd_list[selected_line] );
if ( dr->icon_fetch_uid > 0 ) { if ( dr->icon_fetch_uid > 0 ) {
return rofi_icon_fetcher_get ( dr->icon_fetch_uid ); cairo_surface_t *icon = rofi_icon_fetcher_get ( dr->icon_fetch_uid );
if ( icon ) {
return icon;
}
return fallback_icon ( pd, height );
} }
/** lookup icon */
char ** str = g_strsplit(dr->entry, " ", 2); char ** str = g_strsplit(dr->entry, " ", 2);
if ( str ) { if ( str ) {
dr->icon_fetch_uid = rofi_icon_fetcher_query ( str[0], height ); dr->icon_fetch_uid = rofi_icon_fetcher_query ( str[0], height );
g_strfreev ( str ); g_strfreev ( str );
return rofi_icon_fetcher_get ( dr->icon_fetch_uid ); cairo_surface_t *icon = rofi_icon_fetcher_get ( dr->icon_fetch_uid );
if ( icon ) {
return icon;
}
} }
return NULL; return fallback_icon ( pd, height );
} }
#include "mode-private.h" #include "mode-private.h"

View file

@ -233,6 +233,8 @@ static XrmOption xrmOptions[] = {
"Normalize string when matching (disables match highlighting).", CONFIG_DEFAULT }, "Normalize string when matching (disables match highlighting).", CONFIG_DEFAULT },
{ xrm_Boolean, "steal-focus", { .snum = &config.steal_focus }, NULL, { xrm_Boolean, "steal-focus", { .snum = &config.steal_focus }, NULL,
"Steal focus on launch and restore to window that had it on rofi start on close .", CONFIG_DEFAULT }, "Steal focus on launch and restore to window that had it on rofi start on close .", CONFIG_DEFAULT },
{ xrm_String, "application-fallback-icon", { .snum = &(config.application_fallback_icon) }, NULL,
"Fallback icon to use when the application icon is not found in run/drun.", CONFIG_DEFAULT },
}; };
/** Dynamic array of extra options */ /** Dynamic array of extra options */