From d464822505f5b57e6f5984f5468c62af83d88b2f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 30 Dec 2022 11:54:15 +0100 Subject: [PATCH] [Theme] support rasinc for theme include files. --- Makefile.am | 2 +- doc/rofi-theme.5 | 1 + doc/rofi-theme.5.markdown | 1 + include/helper.h | 4 ++-- lexer/theme-lexer.l | 5 +++-- meson.build | 2 +- source/helper.c | 13 +++++++++++-- test/box-test.c | 2 +- test/scrollbar-test.c | 2 +- .../{gruvbox-common.rasi => gruvbox-common.rasinc} | 0 themes/gruvbox-dark-hard.rasi | 2 +- themes/gruvbox-dark-soft.rasi | 2 +- themes/gruvbox-dark.rasi | 2 +- themes/gruvbox-light-hard.rasi | 2 +- themes/gruvbox-light-soft.rasi | 2 +- themes/gruvbox-light.rasi | 2 +- 16 files changed, 28 insertions(+), 16 deletions(-) rename themes/{gruvbox-common.rasi => gruvbox-common.rasinc} (100%) diff --git a/Makefile.am b/Makefile.am index 2a14c198..174ea9fe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -214,7 +214,7 @@ theme_DATA=\ themes/dmenu.rasi\ themes/docu.rasi\ themes/glue_pro_blue.rasi\ - themes/gruvbox-common.rasi\ + themes/gruvbox-common.rasinc\ themes/gruvbox-dark-hard.rasi\ themes/gruvbox-dark-soft.rasi\ themes/gruvbox-dark.rasi\ diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5 index f70aa560..b7b64b25 100644 --- a/doc/rofi-theme.5 +++ b/doc/rofi-theme.5 @@ -353,6 +353,7 @@ name .PP The preferred file extension for the new theme format is \fBrasi\fP\&. This is an abbreviation for \fBr\fPofi \fBa\fPdvanced \fBs\fPtyle \fBi\fPnformation. +If a theme file is split over multiple files, include files can have the: \fBrasinc\fP extension. .SH Basic Structure .PP diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index 24388f58..bec95423 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -233,6 +233,7 @@ name The preferred file extension for the new theme format is **rasi**. This is an abbreviation for **r**ofi **a**dvanced **s**tyle **i**nformation. +If a theme file is split over multiple files, include files can have the: **rasinc** extension. ## Basic Structure diff --git a/include/helper.h b/include/helper.h index bcae4810..efe6b07c 100644 --- a/include/helper.h +++ b/include/helper.h @@ -393,11 +393,11 @@ char *helper_string_replace_if_exists(char *string, ...); /** * @param file File name passed to option. - * @param ext File extension passed to option. + * @param ext NULL terminated array of file extension passed to option. * * @returns path to theme or copy of filename if not found. */ -char *helper_get_theme_path(const char *file, const char *ext); +char *helper_get_theme_path(const char *file, const char **ext); /** * @param name The name of the element to find. diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 0763b22e..25e8bd71 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -50,6 +50,7 @@ #define LOG_DOMAIN "Parser" int last_state = 0; +const char *rasi_theme_file_extensions[] = {".rasi", ".rasinc", NULL}; /** * Type of Object to parse. */ @@ -413,7 +414,7 @@ if ( queue == NULL ) { yytext[yyleng-1] = '\0'; ParseObject *top = g_queue_peek_head ( file_queue ); g_assert ( top != NULL ); - char *file2 = helper_get_theme_path ( &yytext[1], ".rasi" ); + char *file2 = helper_get_theme_path ( &yytext[1], rasi_theme_file_extensions ); char *filename = rofi_theme_parse_prepare_file ( file2, top->filename ); g_free ( file2 ); FILE *f = fopen ( filename, "rb" ); @@ -880,7 +881,7 @@ if ( queue == NULL ) { gboolean rofi_theme_parse_file ( const char *file ) { - char *file2 = helper_get_theme_path ( file, ".rasi" ); + char *file2 = helper_get_theme_path ( file, rasi_theme_file_extensions ); char *filename = rofi_theme_parse_prepare_file ( file2, NULL ); g_free ( file2 ); diff --git a/meson.build b/meson.build index 4cc7b7c8..6061a62d 100644 --- a/meson.build +++ b/meson.build @@ -293,7 +293,7 @@ install_data( 'themes/dmenu.rasi', 'themes/docu.rasi', 'themes/glue_pro_blue.rasi', - 'themes/gruvbox-common.rasi', + 'themes/gruvbox-common.rasinc', 'themes/gruvbox-dark-hard.rasi', 'themes/gruvbox-dark-soft.rasi', 'themes/gruvbox-dark.rasi', diff --git a/source/helper.c b/source/helper.c index 583d128c..8f5f95ff 100644 --- a/source/helper.c +++ b/source/helper.c @@ -1067,7 +1067,7 @@ gboolean helper_execute_command(const char *wd, const char *cmd, return helper_execute(wd, args, "", cmd, context); } -char *helper_get_theme_path(const char *file, const char *ext) { +char *helper_get_theme_path(const char *file, const char **ext) { char *filename = rofi_expand_path(file); g_debug("Opening theme, testing: %s\n", filename); if (g_file_test(filename, G_FILE_TEST_EXISTS)) { @@ -1075,7 +1075,16 @@ char *helper_get_theme_path(const char *file, const char *ext) { } g_free(filename); - if (g_str_has_suffix(file, ext)) { + gboolean ext_found = FALSE; + if (ext) { + for (const char **i = ext; *i != NULL; i++) { + if (g_str_has_suffix(file, *i)) { + ext_found = TRUE; + break; + } + } + } + if (ext_found) { filename = g_strdup(file); } else { filename = g_strconcat(file, ext, NULL); diff --git a/test/box-test.c b/test/box-test.c index 12b83200..36bbaaf1 100644 --- a/test/box-test.c +++ b/test/box-test.c @@ -92,7 +92,7 @@ gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p, } char *rofi_expand_path(G_GNUC_UNUSED const char *path) { return NULL; } -char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char *ext) { +char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char **ext) { return g_strdup(file); } void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {} diff --git a/test/scrollbar-test.c b/test/scrollbar-test.c index d79154a8..cb58bdcf 100644 --- a/test/scrollbar-test.c +++ b/test/scrollbar-test.c @@ -77,7 +77,7 @@ cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) { int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; } -char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char *ext) { +char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char **ext) { return g_strdup(file); } gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p, diff --git a/themes/gruvbox-common.rasi b/themes/gruvbox-common.rasinc similarity index 100% rename from themes/gruvbox-common.rasi rename to themes/gruvbox-common.rasinc diff --git a/themes/gruvbox-dark-hard.rasi b/themes/gruvbox-dark-hard.rasi index f09507e6..10be00f0 100644 --- a/themes/gruvbox-dark-hard.rasi +++ b/themes/gruvbox-dark-hard.rasi @@ -58,5 +58,5 @@ selected-urgent-foreground: @urgent-foreground; } -@import "gruvbox-common.rasi" +@import "gruvbox-common.rasinc" diff --git a/themes/gruvbox-dark-soft.rasi b/themes/gruvbox-dark-soft.rasi index d080824a..03b120cc 100644 --- a/themes/gruvbox-dark-soft.rasi +++ b/themes/gruvbox-dark-soft.rasi @@ -58,5 +58,5 @@ selected-urgent-foreground: @urgent-foreground; } -@import "gruvbox-common.rasi" +@import "gruvbox-common.rasinc" diff --git a/themes/gruvbox-dark.rasi b/themes/gruvbox-dark.rasi index 6bec1275..bc59022f 100644 --- a/themes/gruvbox-dark.rasi +++ b/themes/gruvbox-dark.rasi @@ -58,5 +58,5 @@ selected-urgent-foreground: @urgent-foreground; } -@import "gruvbox-common.rasi" +@import "gruvbox-common.rasinc" diff --git a/themes/gruvbox-light-hard.rasi b/themes/gruvbox-light-hard.rasi index e0efe33f..18e51f47 100644 --- a/themes/gruvbox-light-hard.rasi +++ b/themes/gruvbox-light-hard.rasi @@ -58,5 +58,5 @@ selected-urgent-foreground: @urgent-foreground; } -@import "gruvbox-common.rasi" +@import "gruvbox-common.rasinc" diff --git a/themes/gruvbox-light-soft.rasi b/themes/gruvbox-light-soft.rasi index 43ddb6b4..f386da75 100644 --- a/themes/gruvbox-light-soft.rasi +++ b/themes/gruvbox-light-soft.rasi @@ -58,5 +58,5 @@ selected-urgent-foreground: @urgent-foreground; } -@import "gruvbox-common.rasi" +@import "gruvbox-common.rasinc" diff --git a/themes/gruvbox-light.rasi b/themes/gruvbox-light.rasi index f8041564..29190683 100644 --- a/themes/gruvbox-light.rasi +++ b/themes/gruvbox-light.rasi @@ -58,5 +58,5 @@ selected-urgent-foreground: @urgent-foreground; } -@import "gruvbox-common.rasi" +@import "gruvbox-common.rasinc"