From 141bd3d197c405c0cabd7b6d76b8105ffd514094 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 12 May 2022 19:52:35 +0200 Subject: [PATCH] [Doc][Config] Update documentation for new fallback icon * Allow multiple config be combined. --- doc/rofi.1 | 40 +++++++++++++++++++++++++++++++++------- doc/rofi.1.markdown | 25 +++++++++++++++++++++---- lexer/theme-lexer.l | 3 +-- lexer/theme-parser.y | 22 ++++++++++++++++------ source/mode.c | 23 ++++++++++++----------- source/modes/drun.c | 26 +++----------------------- source/modes/run.c | 29 +++++------------------------ 7 files changed, 91 insertions(+), 77 deletions(-) diff --git a/doc/rofi.1 b/doc/rofi.1 index ecdea8e1..41e85690 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -431,12 +431,6 @@ Specify icon theme to be used. If not specified default theme from DE is used, \fIAdwaita\fP and \fIgnome\fP themes act as fallback themes. -.PP -\fB\fC-application-fallback-icon\fR - -.PP -Specify an icon to be used when the application icon in run/drun are not yet loaded or is not available. - .PP \fB\fC-markup\fR @@ -464,6 +458,38 @@ The limit of elements that is used to switch from instant to delayed filter mode .PP Default: 8192 +.PP +A fallback icon can be specified for each mode: + +.PP +.RS + +.nf +configuration { + { + fallback-icon: ""; + } +} + +.fi +.RE + +.PP +Example + +.PP +.RS + +.nf +configuration { + run,drun { + fallback-icon: "application-x-addon"; + } +} + +.fi +.RE + .SS Matching .PP \fB\fC-matching\fR \fImethod\fP @@ -1000,7 +1026,7 @@ Default: {mode} {text} .RE .PP -Note: This setting is ignored if \fB\fCcombi-hide-mode-prefix\fR is eanbled. +Note: This setting is ignored if \fB\fCcombi-hide-mode-prefix\fR is enabled. .SS History and Sorting .PP diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index 5b7aa7d5..9d3ad7d8 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -258,10 +258,6 @@ Specify icon theme to be used. If not specified default theme from DE is used, *Adwaita* and *gnome* themes act as fallback themes. -`-application-fallback-icon` - -Specify an icon to be used when the application icon in run/drun are not yet loaded or is not available. - `-markup` Use Pango markup to format output wherever possible. @@ -280,6 +276,27 @@ The limit of elements that is used to switch from instant to delayed filter mode Default: 8192 +A fallback icon can be specified for each mode: + +```css +configuration { + { + fallback-icon: ""; + } +} +``` +Example + +```css +configuration { + run,drun { + fallback-icon: "application-x-addon"; + } +} +``` + + + ### Matching `-matching` *method* diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 1439bc51..416f1e84 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -489,7 +489,7 @@ if ( queue == NULL ) { } \.|{WHITESPACE} { return T_NSEP; } -,{WHITESPACE}* { return T_SSEP; } +,{WHITESPACE}* { return T_SSEP; } /* Alias color to text-color */
"color" { yylval->sval = g_strdup("text-color"); return T_PROP_NAME;}
{WORD} { yylval->sval = g_strdup(yytext); return T_PROP_NAME;} @@ -820,7 +820,6 @@ if ( queue == NULL ) { }
. { yytext[yyleng-1] = '\0'; - fprintf(stderr,"section found: |%s|\n", yytext); return T_ERROR_SECTION; } {WORD_ELEMENT} { diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 33323dcd..8f1721e4 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -278,6 +278,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b ) %type t_entry_list %type t_entry_list_included %type t_entry_name_path +%type t_property_name_list %type t_entry_name_path_selectors %type t_color_list %type t_property @@ -459,16 +460,19 @@ t_config_property // We don't keep any reference to this after this point, so the property can be free'ed. rofi_theme_property_free ( $1 ); } -| t_property_name T_BOPEN t_property_list_optional T_BCLOSE +| t_property_name_list T_BOPEN t_property_list_optional T_BCLOSE { - ThemeWidget *widget = rofi_configuration; - widget = rofi_theme_find_or_create_name ( widget, $1 ); - widget->set = TRUE; - rofi_theme_widget_add_properties ( widget, $3); + + for ( GList *iter = g_list_first( $1) ; iter; iter = g_list_next(iter)){ + ThemeWidget *widget = rofi_configuration; + widget = rofi_theme_find_or_create_name ( widget, iter->data ); + widget->set = TRUE; + rofi_theme_widget_add_properties ( widget, $3); + } if ( $3 ) { g_hash_table_destroy ( $3 ); } - g_free ( $1 ); + g_list_free_full ( $1, g_free ); } ; @@ -1049,5 +1053,11 @@ T_NAME_ELEMENT { $$ = g_list_append ( NULL, $1 );} | t_entry_name_path T_NSEP { $$ = $1; } ; +t_property_name_list: +t_property_name { $$ = g_list_append ( NULL, $1 );} +| t_property_name_list T_SSEP t_property_name { $$ = g_list_append ( $1, $3);} +; + + %% diff --git a/source/mode.c b/source/mode.c index 3cb129aa..588f9718 100644 --- a/source/mode.c +++ b/source/mode.c @@ -78,28 +78,29 @@ cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line, if (mode->_get_icon != NULL) { cairo_surface_t *icon = mode->_get_icon(mode, selected_line, height); - if ( icon ) { + if (icon) { return icon; } } - - if ( mode->fallback_icon_not_found == TRUE) { + 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); + 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); + 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; diff --git a/source/modes/drun.c b/source/modes/drun.c index 8d4278e8..fc07bdeb 100644 --- a/source/modes/drun.c +++ b/source/modes/drun.c @@ -213,10 +213,6 @@ 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 { @@ -1331,17 +1327,6 @@ static char *_get_display_value(const Mode *sw, unsigned int selected_line, 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); @@ -1353,18 +1338,13 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line, if (dr->icon_name != NULL) { if (dr->icon_fetch_uid > 0) { cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid); - if (icon) { - return icon; - } - return fallback_icon(pd, height); + return icon; } dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height); cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid); - if (icon) { - return icon; - } + return icon; } - return fallback_icon(pd, height); + return NULL; } static char *drun_get_completion(const Mode *sw, unsigned int index) { diff --git a/source/modes/run.c b/source/modes/run.c index 47a9634e..3cc4d838 100644 --- a/source/modes/run.c +++ b/source/modes/run.c @@ -46,10 +46,10 @@ #include #include -#include "modes/filebrowser.h" -#include "modes/run.h" #include "helper.h" #include "history.h" +#include "modes/filebrowser.h" +#include "modes/run.h" #include "rofi.h" #include "settings.h" @@ -85,9 +85,6 @@ typedef struct { Mode *completer; char *old_completer_input; - /** fallback icon */ - uint32_t fallback_icon_fetch_uid; - cairo_surface_t *fallback_icon; } RunModePrivateData; /** @@ -531,17 +528,6 @@ 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); @@ -553,10 +539,7 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line, if (dr->icon_fetch_uid > 0) { cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid); - if (icon) { - return icon; - } - return fallback_icon(pd, height); + return icon; } /** lookup icon */ char **str = g_strsplit(dr->entry, " ", 2); @@ -564,11 +547,9 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line, dr->icon_fetch_uid = rofi_icon_fetcher_query(str[0], height); g_strfreev(str); cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid); - if (icon) { - return icon; - } + return icon; } - return fallback_icon(pd, height); + return NULL; } #include "mode-private.h"