summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2021-06-08 20:21:28 +0200
committerDave Davenport <qball@gmpclient.org>2021-06-08 20:21:28 +0200
commitcb250fa73a53010ebe94859f76c18e81802801e8 (patch)
tree32f267b184190b04585e6f8cced1d8ad4938ef80 /source
parent6178970499bef87ddd7db5e2039a24735e7be8c2 (diff)
Add fallback icon option.
Diffstat (limited to 'source')
-rw-r--r--source/dialogs/drun.c27
-rw-r--r--source/dialogs/run.c30
-rw-r--r--source/xrmoptions.c2
3 files changed, 54 insertions, 5 deletions
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c
index fafc6068..2bb12009 100644
--- a/source/dialogs/drun.c
+++ b/source/dialogs/drun.c
@@ -169,6 +169,10 @@ struct _DRunModePrivateData
char *old_completer_input;
uint32_t selected_line;
char *old_input;
+
+ /** fallback icon */
+ uint32_t fallback_icon_fetch_uid;
+ cairo_surface_t *fallback_icon;
};
struct RegexEvalArg
@@ -1242,6 +1246,17 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in
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 )
{
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;
}
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 );
- 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 )
diff --git a/source/dialogs/run.c b/source/dialogs/run.c
index 69dbe659..d2bd3428 100644
--- a/source/dialogs/run.c
+++ b/source/dialogs/run.c
@@ -87,6 +87,9 @@ typedef struct
Mode *completer;
char *old_completer_input;
+ /** fallback icon */
+ uint32_t fallback_icon_fetch_uid;
+ cairo_surface_t *fallback_icon;
} RunModePrivateData;
/**
@@ -520,6 +523,18 @@ static char *run_get_message ( const Mode *sw )
}
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 )
{
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 );
RunEntry *dr = &( pd->cmd_list[selected_line] );
+
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);
if ( str ) {
dr->icon_fetch_uid = rofi_icon_fetcher_query ( str[0], height );
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"
diff --git a/source/xrmoptions.c b/source/xrmoptions.c
index 0de18903..18837ae0 100644
--- a/source/xrmoptions.c
+++ b/source/xrmoptions.c
@@ -233,6 +233,8 @@ static XrmOption xrmOptions[] = {
"Normalize string when matching (disables match highlighting).", CONFIG_DEFAULT },
{ 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 },
+ { 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 */