From 99f2a1a9bf6fedeafe3e882f76aff876274d8ed3 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 18 Sep 2017 17:48:13 +0200 Subject: Add @theme import command, that resets the current theme. --- include/theme.h | 5 +++++ lexer/theme-lexer.l | 6 ++++++ lexer/theme-parser.y | 4 ++-- source/theme.c | 7 +++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/theme.h b/include/theme.h index df817e7c..843a658a 100644 --- a/include/theme.h +++ b/include/theme.h @@ -288,6 +288,11 @@ GList *rofi_theme_get_list ( const widget *widget, const char * property, const */ gboolean rofi_theme_is_empty ( void ); + +/** + * Reset the current theme. + */ +void rofi_theme_reset ( void ); #ifdef THEME_CONVERTER /** * Convert old theme colors into default one. diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 391ed3b8..a576e266 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -229,6 +229,7 @@ C_COMMENT_OPEN "/*" INCLUDE "@import" +THEME "@theme" CONFIGURATION (?i:configuration) @@ -301,6 +302,11 @@ if ( queue == NULL ){ {INCLUDE} { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(INCLUDE); +} +{THEME} { + rofi_theme_reset(); + g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); + BEGIN(INCLUDE); } /** Skip all whitespace */ {WHITESPACE} {} diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index de22b98b..b97bae22 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -256,8 +256,8 @@ t_entry_list: %empty { // There is always a base widget. if (rofi_theme == NULL ){ - $$ = rofi_theme = g_slice_new0 ( ThemeWidget ); - rofi_theme->name = g_strdup ( "Root" ); + rofi_theme_reset(); + $$ = rofi_theme; } } | t_entry_list diff --git a/source/theme.c b/source/theme.c index fed1afc2..06e9e490 100644 --- a/source/theme.c +++ b/source/theme.c @@ -111,6 +111,13 @@ void rofi_theme_property_free ( Property *p ) g_slice_free ( Property, p ); } +void rofi_theme_reset ( void ) +{ + rofi_theme_free ( rofi_theme ); + rofi_theme = g_slice_new0 ( ThemeWidget ); + rofi_theme->name = g_strdup("Root"); +} + void rofi_theme_free ( ThemeWidget *widget ) { if ( widget == NULL ) { -- cgit v1.2.3