summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@blame.services>2022-05-11 17:02:13 +0200
committerDave Davenport <qball@blame.services>2022-05-11 17:08:36 +0200
commitfc5abb8ef555cabb13b7530df96d3f72c933bbf7 (patch)
tree7b5815982f39f2745baef6ecd1bba7f9a5291249
parent411adfc7d397f6ce8b9c8f5c21e985d2faa0b836 (diff)
[1633][Mode] Add generic fallback option for modes.i1079
Add config option: ```css configuration { <mode> { fallback-icon: "<icon name>"; } } ``` fixes: #1633
-rw-r--r--include/mode-private.h4
-rw-r--r--include/mode.h2
-rw-r--r--source/mode.c31
3 files changed, 34 insertions, 3 deletions
diff --git a/include/mode-private.h b/include/mode-private.h
index 99d48309..0f5bcaed 100644
--- a/include/mode-private.h
+++ b/include/mode-private.h
@@ -203,6 +203,10 @@ struct rofi_mode {
/** Module */
GModule *module;
+
+ /** Fallack icon.*/
+ uint32_t fallback_icon_fetch_uid;
+ uint32_t fallback_icon_not_found;
};
G_END_DECLS
#endif // ROFI_MODE_PRIVATE_H
diff --git a/include/mode.h b/include/mode.h
index fc239223..b0b8314a 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -138,7 +138,7 @@ char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
*
* @returns allocated new cairo_surface_t if applicable
*/
-cairo_surface_t *mode_get_icon(const Mode *mode, unsigned int selected_line,
+cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line,
int height);
/**
diff --git a/source/mode.c b/source/mode.c
index 675bd519..3cb129aa 100644
--- a/source/mode.c
+++ b/source/mode.c
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <string.h>
+#include "rofi-icon-fetcher.h"
// This one should only be in mode implementations.
#include "mode-private.h"
/**
@@ -42,6 +43,9 @@
int mode_init(Mode *mode) {
g_return_val_if_fail(mode != NULL, FALSE);
g_return_val_if_fail(mode->_init != NULL, FALSE);
+ // to make sure this is initialized correctly.
+ mode->fallback_icon_fetch_uid = 0;
+ mode->fallback_icon_not_found = FALSE;
return mode->_init(mode);
}
@@ -68,13 +72,36 @@ char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
get_entry);
}
-cairo_surface_t *mode_get_icon(const Mode *mode, unsigned int selected_line,
+cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line,
int height) {
g_assert(mode != NULL);
if (mode->_get_icon != NULL) {
- return mode->_get_icon(mode, selected_line, height);
+ cairo_surface_t *icon = mode->_get_icon(mode, selected_line, height);
+ if ( icon ) {
+ return icon;
+ }
+ }
+
+
+ if ( mode->fallback_icon_not_found == TRUE) {
+ return NULL;
+ }
+ if (mode->fallback_icon_fetch_uid > 0) {
+ cairo_surface_t *icon = rofi_icon_fetcher_get(mode->fallback_icon_fetch_uid);
+ return icon;
+ }
+ ThemeWidget *wid = rofi_config_find_widget(mode->name, NULL, TRUE);
+ if ( wid ) {
+ /** Load user entires */
+ Property *p = rofi_theme_find_property(wid, P_STRING, "fallback-icon", TRUE);
+ if (p != NULL && (p->type == P_STRING && p->value.s)) {
+ mode->fallback_icon_fetch_uid =
+ rofi_icon_fetcher_query(p->value.s, height);
+ return NULL;
+ }
}
+ mode->fallback_icon_not_found = TRUE;
return NULL;
}