From a754815d14492c4e0d38226965c19773cbe96350 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 2 Apr 2017 12:32:11 +0200 Subject: [PATCH] Add converter back for old theme format. --- config/config.c | 4 +++ include/default-theme.h | 14 ++++----- include/settings.h | 6 ++++ include/theme.h | 5 +++ include/widgets/textbox.h | 20 ++++++------ lexer/theme-lexer.l | 9 ++++++ source/dialogs/ssh.c | 2 +- source/helper.c | 6 ++-- source/rofi.c | 26 ++++++++++------ source/theme.c | 65 +++++++++++++++++++++++++++++++++++++++ source/widgets/listview.c | 12 ++++++++ source/xrmoptions.c | 8 +++++ 12 files changed, 147 insertions(+), 30 deletions(-) diff --git a/config/config.c b/config/config.c index 813f88af..0e3aa3cf 100644 --- a/config/config.c +++ b/config/config.c @@ -111,4 +111,8 @@ Settings config = { .click_to_exit = TRUE, .show_match = TRUE, .theme = NULL, + .color_normal = NULL, + .color_active = NULL, + .color_urgent = NULL, + .color_window = NULL, }; diff --git a/include/default-theme.h b/include/default-theme.h index d913828b..c815032b 100644 --- a/include/default-theme.h +++ b/include/default-theme.h @@ -4,13 +4,13 @@ const char *default_theme = "* {" " spacing: 2;" - " background: #FFFDF6E3;" - " foreground: #FF002B36;" - " bordercolor: @foreground;" - " red: #FFDC322F;" - " blue: #FF268BD2;" - " lightbg: #FFEEE8D5;" - " lightfg: #FF586875;" + " background: #FFFDF6E3;" + " foreground: #FF002B36;" + " bordercolor: @foreground;" + " red: #FFDC322F;" + " blue: #FF268BD2;" + " lightbg: #FFEEE8D5;" + " lightfg: #FF586875;" " normal-foreground: @foreground;" " normal-background: @background;" " urgent-foreground: @red;" diff --git a/include/settings.h b/include/settings.h index e14ee48d..4273b05c 100644 --- a/include/settings.h +++ b/include/settings.h @@ -64,6 +64,12 @@ typedef struct /** Font string (pango format) */ char * menu_font; + /** New row colors */ + char * color_normal; + char * color_active; + char * color_urgent; + char * color_window; + /** Terminal to use */ char * terminal_emulator; /** SSH client to use */ diff --git a/include/theme.h b/include/theme.h index 938578a5..87a63cad 100644 --- a/include/theme.h +++ b/include/theme.h @@ -409,4 +409,9 @@ Property *rofi_theme_find_property ( ThemeWidget *widget, PropertyType type, con * @returns TRUE when empty. */ gboolean rofi_theme_is_empty ( void ); + +/** + * Convert old theme colors into default one. + */ +void rofi_theme_convert_old ( void ); #endif diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h index a1c77445..0944f709 100644 --- a/include/widgets/textbox.h +++ b/include/widgets/textbox.h @@ -45,16 +45,16 @@ typedef struct */ typedef enum { - TB_AUTOHEIGHT = 1 << 0, - TB_AUTOWIDTH = 1 << 1, - TB_LEFT = 1 << 16, - TB_RIGHT = 1 << 17, - TB_CENTER = 1 << 18, - TB_EDITABLE = 1 << 19, - TB_MARKUP = 1 << 20, - TB_WRAP = 1 << 21, - TB_PASSWORD = 1 << 22, - TB_INDICATOR = 1 << 23, + TB_AUTOHEIGHT = 1 << 0, + TB_AUTOWIDTH = 1 << 1, + TB_LEFT = 1 << 16, + TB_RIGHT = 1 << 17, + TB_CENTER = 1 << 18, + TB_EDITABLE = 1 << 19, + TB_MARKUP = 1 << 20, + TB_WRAP = 1 << 21, + TB_PASSWORD = 1 << 22, + TB_INDICATOR = 1 << 23, } TextboxFlags; /** * Flags indicating current state of the textbox. diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index a9d8bfb2..4a58587c 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -408,6 +408,15 @@ if ( queue == NULL ){ yylval->colorval.alpha = 1.0; return T_COLOR; } +argb:{HEX}{1,8} { + union { unsigned int val; struct { unsigned char b,g,r,a;};} val; + val.val = (unsigned int)strtoull ( &yytext[5], NULL, 16); + yylval->colorval.alpha = val.a/255.0; + yylval->colorval.red = val.r/255.0; + yylval->colorval.green = val.g/255.0; + yylval->colorval.blue = val.b/255.0; + return T_COLOR; +} {CENTER} { yylval->ival = WL_CENTER; diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 97c353b4..a332dd5f 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -206,7 +206,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length ) // Reading one line per time. while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { // Evaluate one line. - unsigned int index = 0, ti = 0; + unsigned int index = 0, ti = 0; char *token = buffer; // Tokenize it. diff --git a/source/helper.c b/source/helper.c index 12a49109..ff1d002c 100644 --- a/source/helper.c +++ b/source/helper.c @@ -255,7 +255,7 @@ GRegex **tokenize ( const char *input, int case_sensitive ) } char *saveptr = NULL, *token; - GRegex **retv = NULL; + GRegex **retv = NULL; if ( !config.tokenize ) { retv = g_malloc0 ( sizeof ( GRegex* ) * 2 ); retv[0] = (GRegex *) create_regex ( input, case_sensitive ); @@ -866,8 +866,8 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st // uleft: value of the upper left cell; ulefts: maximum value of uleft and cells on the left. The arbitrary initial // values suppress warnings. int uleft = 0, ulefts = 0, left, lefts; - const gchar *pit = pattern, *sit; - enum CharClass prev = NON_WORD, cur; + const gchar *pit = pattern, *sit; + enum CharClass prev = NON_WORD, cur; for ( si = 0, sit = str; si < slen; si++, sit = g_utf8_next_char ( sit ) ) { cur = rofi_scorer_get_character_class ( g_utf8_get_char ( sit ) ); score[si] = rofi_scorer_get_score_for ( prev, cur ); diff --git a/source/rofi.c b/source/rofi.c index e4e3ccbe..7e326a9c 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -197,12 +197,12 @@ static void run_switcher ( ModeMode mode ) // Otherwise check if requested mode is enabled. for ( unsigned int i = 0; i < num_modi; i++ ) { if ( !mode_init ( modi[i] ) ) { - GString *str= g_string_new ( "Failed to initialize the mode: "); + GString *str = g_string_new ( "Failed to initialize the mode: " ); g_string_append ( str, modi[i]->name ); - g_string_append ( str, "\n"); + g_string_append ( str, "\n" ); rofi_view_error_dialog ( str->str, ERROR_MSG_MARKUP ); - g_string_free (str, FALSE); + g_string_free ( str, FALSE ); break; } } @@ -350,12 +350,12 @@ static void help_print_disabled_mode ( const char *mode ) // Only output to terminal if ( is_term ) { fprintf ( stderr, "Mode %s%s%s is not enabled. I have enabled it for now.\n", - color_red, mode, color_reset); + color_red, mode, color_reset ); fprintf ( stderr, "Please consider adding %s%s%s to the list of enabled modi: %smodi: %s%s%s,%s%s.\n", - color_red, mode, color_reset, - color_green, config.modi,color_reset, - color_red, mode, color_reset - ); + color_red, mode, color_reset, + color_green, config.modi, color_reset, + color_red, mode, color_reset + ); } } static void help_print_no_arguments ( void ) @@ -391,7 +391,7 @@ static void help_print_no_arguments ( void ) } } fprintf ( stderr, "\nTo activate a mode, add it to the list of modi in the %smodi%s setting.", - is_term?color_green:"",is_term?color_reset:"" ); + is_term ? color_green : "", is_term ? color_reset : "" ); } /** @@ -1140,10 +1140,18 @@ int main ( int argc, char *argv[] ) if ( rofi_theme_is_empty ( ) ) { if ( rofi_theme_parse_string ( default_theme ) ) { fprintf ( stderr, "Failed to parse default theme. Giving up..\n" ); + if ( list_of_error_msgs ) { + for ( GList *iter = g_list_first ( list_of_error_msgs ); + iter != NULL; iter = g_list_next ( iter ) ) { + fprintf ( stderr, "Error: %s%s%s\n", + color_bold, ( (GString *) iter->data )->str, color_reset ); + } + } rofi_theme = NULL; cleanup (); return EXIT_FAILURE; } + rofi_theme_convert_old (); } if ( find_arg ( "-dump-theme" ) >= 0 ) { diff --git a/source/theme.c b/source/theme.c index d6ced01e..890ced85 100644 --- a/source/theme.c +++ b/source/theme.c @@ -574,3 +574,68 @@ gboolean rofi_theme_is_empty ( void ) return FALSE; } +void rofi_theme_convert_old ( void ) +{ + if ( config.color_window ) { + char **retv = g_strsplit ( config.color_window, ",", -1 ); + const char const *conf[] = { + "* { background: %s; }", + "* { bordercolor: %s; }", + "* { separatorcolor: %s; }" + }; + for ( int i = 0; retv && retv[i]; i++ ) { + char *str = g_strdup_printf ( conf[i], retv[i] ); + rofi_theme_parse_string ( str ); + g_free ( str ); + } + g_strfreev ( retv ); + } + if ( config.color_normal ) { + char **retv = g_strsplit ( config.color_normal, ",", -1 ); + const char const *conf[] = { + "* { normal-background: %s; }", + "* { foreground: %s; normal-foreground: @foreground; alternate-normal-foreground: @foreground; }", + "* { alternate-normal-background: %s; }", + "* { selected-normal-background: %s; }", + "* { selected-normal-foreground: %s; }" + }; + for ( int i = 0; retv && retv[i]; i++ ) { + char *str = g_strdup_printf ( conf[i], retv[i] ); + rofi_theme_parse_string ( str ); + g_free ( str ); + } + g_strfreev ( retv ); + } + if ( config.color_urgent ) { + char **retv = g_strsplit ( config.color_urgent, ",", -1 ); + const char const *conf[] = { + "* { urgent-background: %s; }", + "* { urgent-foreground: %s; alternate-urgent-foreground: @urgent-foreground;}", + "* { alternate-urgent-background: %s; }", + "* { selected-urgent-background: %s; }", + "* { selected-urgent-foreground: %s; }" + }; + for ( int i = 0; retv && retv[i]; i++ ) { + char *str = g_strdup_printf ( conf[i], retv[i] ); + rofi_theme_parse_string ( str ); + g_free ( str ); + } + g_strfreev ( retv ); + } + if ( config.color_active ) { + char **retv = g_strsplit ( config.color_active, ",", -1 ); + const char const *conf[] = { + "* { active-background: %s; }", + "* { active-foreground: %s; alternate-active-foreground: @active-foreground;}", + "* { alternate-active-background: %s; }", + "* { selected-active-background: %s; }", + "* { selected-active-foreground: %s; }" + }; + for ( int i = 0; retv && retv[i]; i++ ) { + char *str = g_strdup_printf ( conf[i], retv[i] ); + rofi_theme_parse_string ( str ); + g_free ( str ); + } + g_strfreev ( retv ); + } +} diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 6dc092a8..84a6bbce 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -433,6 +433,9 @@ static void listview_nav_down_int ( listview *lv ) void listview_nav_up ( listview *lv ) { + if ( lv == NULL ) { + return; + } if ( lv->reverse ) { listview_nav_down_int ( lv ); } @@ -442,6 +445,9 @@ void listview_nav_up ( listview *lv ) } void listview_nav_down ( listview *lv ) { + if ( lv == NULL ) { + return; + } if ( lv->reverse ) { listview_nav_up_int ( lv ); } @@ -514,6 +520,9 @@ static void listview_nav_page_next_int ( listview *lv ) void listview_nav_page_prev ( listview *lv ) { + if ( lv == NULL ) { + return; + } if ( lv->reverse ) { listview_nav_page_next_int ( lv ); } @@ -523,6 +532,9 @@ void listview_nav_page_prev ( listview *lv ) } void listview_nav_page_next ( listview *lv ) { + if ( lv == NULL ) { + return; + } if ( lv->reverse ) { listview_nav_page_prev_int ( lv ); } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 5713e22d..dd200a3d 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -171,6 +171,14 @@ static XrmOption xrmOptions[] = { "Indicate how it match by underlining it.", CONFIG_DEFAULT }, { xrm_String, "theme", { .str = &config.theme }, NULL, "New style theme file", CONFIG_DEFAULT }, + { xrm_String, "color-normal", { .str = &config.color_normal }, NULL, + "Color scheme for normal row", CONFIG_DEFAULT }, + { xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL, + "Color scheme for urgent row", CONFIG_DEFAULT }, + { xrm_String, "color-active", { .str = &config.color_active }, NULL, + "Color scheme for active row", CONFIG_DEFAULT }, + { xrm_String, "color-window", { .str = &config.color_window }, NULL, + "Color scheme window", CONFIG_DEFAULT }, }; /** Dynamic array of extra options */