From acb1979f10fc3afc77fdb44936170d6d6dfea4dd Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 24 Aug 2021 18:19:25 +0200 Subject: [PATCH] [Theme] Undo part of default theme changes, always pick build-in --- Makefile.am | 15 ++++++-- doc/default_configuration.rasi | 2 + themes/default.rasi => doc/default_theme.rasi | 0 lexer/theme-lexer.l | 37 +++++++++++++++++++ meson.build | 6 ++- releasenotes/1.7.0/release-1.7.0.markdown | 25 +++++++++++++ resources/resources.xml | 2 +- source/rofi.c | 26 +------------ 8 files changed, 82 insertions(+), 31 deletions(-) rename themes/default.rasi => doc/default_theme.rasi (100%) diff --git a/Makefile.am b/Makefile.am index 2561c829..022f3d6d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -238,8 +238,7 @@ theme_DATA=\ themes/solarized_alternate.rasi\ themes/fancy.rasi\ themes/iggy.rasi\ - themes/iggy.jpg\ - themes/default.rasi + themes/iggy.jpg ## # Extra DIST @@ -257,6 +256,7 @@ EXTRA_DIST+=\ script/get_git_rev.sh\ $(theme_DATA)\ doc/default_configuration.rasi\ + doc/default_theme.rasi\ Changelog ## # Indent @@ -328,6 +328,7 @@ textbox_test_CFLAGS=\ -I$(top_builddir)/lexer/\ -I$(top_srcdir)/lexer/\ -I$(top_srcdir)/config/\ + -I$(top_builddir)/resources/\ -I$(top_builddir)/ textbox_test_LDADD=\ @@ -368,7 +369,8 @@ widget_test_SOURCES=\ config/config.c\ lexer/theme-parser.y\ lexer/theme-lexer.l\ - test/widget-test.c + test/widget-test.c\ + resources/resources.c box_test_LDADD=$(textbox_test_LDADD) box_test_CFLAGS=$(textbox_test_CFLAGS) @@ -384,6 +386,7 @@ box_test_SOURCES=\ include/theme.h\ include/css-colors.h\ config/config.c\ + resources/resources.c\ test/box-test.c scrollbar_test_LDADD=$(textbox_test_LDADD) @@ -400,7 +403,8 @@ scrollbar_test_SOURCES=\ include/theme.h\ include/css-colors.h\ config/config.c\ - test/scrollbar-test.c + test/scrollbar-test.c\ + resources/resources.c textbox_test_SOURCES=\ source/widgets/widget.c\ @@ -424,6 +428,7 @@ textbox_test_SOURCES=\ include/xrmoptions.h\ include/helper.h\ include/helper-theme.h\ + resources/resources.c\ test/textbox-test.c if USE_CHECK @@ -448,6 +453,7 @@ theme_parser_test_SOURCES=\ source/rofi-types.c\ include/rofi-types.h\ source/css-colors.c\ + resources/resources.c\ test/theme-parser-test.c endif @@ -481,6 +487,7 @@ helper_test_CFLAGS=\ -I$(top_builddir)/lexer/\ -I$(top_srcdir)/lexer/\ -I$(top_srcdir)/config/\ + -I$(top_builddir)/resources/\ -I$(top_builddir)/ helper_test_LDADD=\ diff --git a/doc/default_configuration.rasi b/doc/default_configuration.rasi index 339dc829..bc07d5a9 100644 --- a/doc/default_configuration.rasi +++ b/doc/default_configuration.rasi @@ -14,3 +14,5 @@ configuration { directories-first: true; } } + +@theme "default" diff --git a/themes/default.rasi b/doc/default_theme.rasi similarity index 100% rename from themes/default.rasi rename to doc/default_theme.rasi diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 4f288454..0b1c03de 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -34,8 +34,10 @@ %{ #include "config.h" +#include "resources.h" #include #include +#include #include #include #include @@ -56,6 +58,8 @@ typedef enum { PT_FILE, /** Parse a string */ PT_STRING, + /** Parse a string */ + PT_STRING_ALLOC, /** Parse environment */ PT_ENV } ParseType; @@ -75,6 +79,8 @@ typedef struct _ParseObject { int str_len; /** String */ const char *input_str; + /** For where we need to free at end. (PT_STRING_ALLOC); */ + char *malloc_str; /** Position in file */ YYLTYPE location; } ParseObject; @@ -127,6 +133,7 @@ static double rofi_theme_parse_convert_hex ( char high, char low) break;\ }\ case PT_ENV:\ + case PT_STRING_ALLOC:\ case PT_STRING:\ {\ yy_size_t len = MIN (max_size, current->str_len);\ @@ -273,6 +280,7 @@ C_COMMENT_OPEN "/*" INCLUDE "@import" THEME "@theme" +DEFAULT (?i:\"default\"?) MEDIA "@media" @@ -363,6 +371,26 @@ if ( queue == NULL ) { {WHITESPACE} {} /** Parse path. Last element in this INCLUDE */ +{DEFAULT} { + yytext[yyleng-1] = '\0'; + /** Add Parse object */ + GBytes *theme_data = g_resource_lookup_data( resources_get_resource(), + "/org/qtools/rofi/default.rasi", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); + if (theme_data) { + const char *theme = g_bytes_get_data(theme_data, NULL); + file_queue = g_queue_new (); + ParseObject *po = g_malloc0(sizeof(ParseObject)); + po->type = PT_STRING_ALLOC; + po->malloc_str = g_strdup(theme); + po->input_str = po->malloc_str; + po->str_len = strlen(po->malloc_str); + current = po; + g_queue_push_head ( file_queue, po ); + g_bytes_unref(theme_data); + } + // Pop out of include. */ + BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); +} {STRING} { yytext[yyleng-1] = '\0'; ParseObject *top = g_queue_peek_head ( file_queue ); @@ -666,6 +694,9 @@ if ( queue == NULL ) { if ( po->type == PT_FILE ) { fclose ( po->filein ); } + if ( po->type == PT_STRING_ALLOC ) { + g_free( po->malloc_str); + } g_free ( po ); } po = g_queue_peek_head ( file_queue ); @@ -812,6 +843,9 @@ gboolean rofi_theme_parse_file ( const char *file ) if ( po->type == PT_FILE ) { fclose ( po->filein ); } + if ( po->type == PT_STRING_ALLOC ) { + g_free( po->malloc_str); + } g_free ( po ); } } @@ -847,6 +881,9 @@ gboolean rofi_theme_parse_string ( const char *string ) if ( po->type == PT_FILE ) { fclose ( po->filein ); } + if ( po->type == PT_STRING_ALLOC ) { + g_free( po->malloc_str); + } g_free ( po ); } } diff --git a/meson.build b/meson.build index a882a16c..055736a6 100644 --- a/meson.build +++ b/meson.build @@ -266,7 +266,6 @@ install_data( 'themes/fancy.rasi', 'themes/iggy.rasi', 'themes/iggy.jpg', - 'themes/default.rasi', install_dir: themedir ) @@ -312,6 +311,7 @@ test('widget test', executable('widget.test', [ 'test/widget-test.c', theme_parser, theme_lexer, + default_theme, ], objects: rofi.extract_objects([ 'source/widgets/widget.c', @@ -329,6 +329,7 @@ test('box test', executable('box.test', [ 'test/box-test.c', theme_parser, theme_lexer, + default_theme, ], objects: rofi.extract_objects([ 'source/widgets/widget.c', @@ -345,6 +346,7 @@ test('scrollbar test', executable('scrollbar.test', [ 'test/scrollbar-test.c', theme_parser, theme_lexer, + default_theme, ], objects: rofi.extract_objects([ 'source/widgets/widget.c', @@ -361,6 +363,7 @@ test('textbox test', executable('textbox.test', [ 'test/textbox-test.c', theme_parser, theme_lexer, + default_theme, ], objects: rofi.extract_objects([ 'source/widgets/widget.c', @@ -428,6 +431,7 @@ if check.found() 'source/theme.c', 'source/rofi-types.c', 'source/css-colors.c', + 'resources/resources.c', ]), dependencies: deps, )) diff --git a/releasenotes/1.7.0/release-1.7.0.markdown b/releasenotes/1.7.0/release-1.7.0.markdown index 86ca2bf5..a4e3de88 100644 --- a/releasenotes/1.7.0/release-1.7.0.markdown +++ b/releasenotes/1.7.0/release-1.7.0.markdown @@ -17,6 +17,31 @@ some of the more 'off-script' use of rofi. This release was made possible by many contributors, see below for a full list. Big thanks again to SardemFF7 and TonCherAmi. + +## Default theme loading + +In older version of **rofi** the default theme was (almost) always loaded based on some unclear rules, sometimes +some random patch code was loaded and sometimes no theme was loaded before loading another theme. + +The current version of rofi this is hopefully more logic. It loads the default +theme by default using the default configuration. (Can be disabled by `-no-default-config`). +Using `-theme`, or `@theme` primitive will discard the theme completely. + +So the below css completely removes the default theme, and loads `iggy`. + +```css +configuration { + + +} + +@theme "iggy" + +element { + children: [element-icon, element-text]; +} +``` + ## File Browser TonCherAmi made several very nice usability improvements to the file-browser. His changes allow you to define sorting diff --git a/resources/resources.xml b/resources/resources.xml index 968a75d5..06ad76f9 100644 --- a/resources/resources.xml +++ b/resources/resources.xml @@ -1,7 +1,7 @@ - themes/default.rasi + doc/default_theme.rasi doc/default_configuration.rasi diff --git a/source/rofi.c b/source/rofi.c index 86de4787..7c667c21 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -841,7 +841,7 @@ int main(int argc, char *argv[]) { "Pidfile location"); /** default configuration */ - { + if (find_arg("-no-default-config") < 0) { GBytes *theme_data = g_resource_lookup_data( resources_get_resource(), "/org/qtools/rofi/default_configuration.rasi", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); @@ -987,30 +987,6 @@ int main(int argc, char *argv[]) { windowid = config.monitor; } } - // Load default theme, if no theme was set and we don't have a current theme - // loaded. - if (config.theme == NULL && rofi_theme_is_empty()) { - GBytes *theme_data = g_resource_lookup_data( - resources_get_resource(), "/org/qtools/rofi/default.rasi", - G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); - if (theme_data) { - const char *theme = g_bytes_get_data(theme_data, NULL); - if (rofi_theme_parse_string((const char *)theme)) { - g_warning("Failed to parse default theme. Giving up.."); - if (list_of_error_msgs) { - for (GList *iter = g_list_first(list_of_error_msgs); iter != NULL; - iter = g_list_next(iter)) { - g_warning("Error: %s%s%s", color_bold, ((GString *)iter->data)->str, - color_reset); - } - } - rofi_theme = NULL; - cleanup(); - return EXIT_FAILURE; - } - g_bytes_unref(theme_data); - } - } /** * Make small commandline changes to the current theme.