From f2c4aff37c44839b97b7f6c5e38602af80032134 Mon Sep 17 00:00:00 2001 From: QC Date: Fri, 3 Apr 2015 18:40:07 +0200 Subject: [PATCH] Add active/urgent color. --- config/config.def.c | 4 +++- include/rofi.h | 2 ++ include/textbox.h | 6 +++--- source/dialogs/window.c | 4 ++-- source/textbox.c | 31 +++++++++++++++++-------------- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/config/config.def.c b/config/config.def.c index 7d21f11b..cbb6ed2b 100644 --- a/config/config.def.c +++ b/config/config.def.c @@ -47,7 +47,9 @@ Settings config = { /** Font */ .menu_font = "mono 12", /** Foreground color */ - .menu_fg = "#222222", + .menu_fg = "#222222", + .menu_fg_urgent = "#aa0000", + .menu_fg_active = "#00aaff", /** Background color */ .menu_bg = "#f2f1f0", /** Background color alternate row */ diff --git a/include/rofi.h b/include/rofi.h index 0054624b..387bbe92 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -154,6 +154,8 @@ typedef struct _Settings char * menu_font; /** Foreground color */ char * menu_fg; + char * menu_fg_urgent; + char * menu_fg_active; /** Background color */ char * menu_bg; /** Background color alt */ diff --git a/include/textbox.h b/include/textbox.h index b035ecee..3ae8b118 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -43,10 +43,10 @@ typedef enum STATE_MASK = ( NORMAL | ALT | HIGHLIGHT ), - BOLD = 8, - ITALIC = 16, + ACTIVE = 8, + URGENT = 16, - FMOD_MASK = ( BOLD | ITALIC ) + FMOD_MASK = ( ACTIVE | URGENT ) } TextBoxFontType; textbox* textbox_create ( Window parent, diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 729170c7..44f84757 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -523,10 +523,10 @@ static const char *mgrv ( unsigned int selected_line, void *sw, G_GNUC_UNUSED in { SwitcherModePrivateData *rmpd = ( (Switcher *) sw )->private_data; if ( window_client ( display, rmpd->ids->array[selected_line] )->demands ) { - *state |= ITALIC; + *state |= URGENT; } if ( window_client ( display, rmpd->ids->array[selected_line] )->active ) { - *state |= BOLD; + *state |= ACTIVE; } return rmpd->cmd_list[selected_line]; } diff --git a/source/textbox.c b/source/textbox.c index f1144d91..c10fa8d1 100644 --- a/source/textbox.c +++ b/source/textbox.c @@ -47,6 +47,8 @@ extern Display *display; * Font + font color cache. * Avoid re-loading font on every change on every textbox. */ +XftColor color_fg_urgent; +XftColor color_fg_active; XftColor color_fg; XftColor color_bg; XftColor color_hlfg; @@ -99,9 +101,9 @@ textbox* textbox_create ( Window parent, tb->window = XCreateWindow ( display, tb->parent, tb->x, tb->y, tb->w, tb->h, 0, vinfo->depth, InputOutput, vinfo->visual, CWColormap | CWBorderPixel | CWBackPixel, &attr ); - // need to preload the font to calc line height - // Force update of font descriptor. - tb->tbft = ~tbft; + PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font ); + pango_layout_set_font_description ( tb->layout, pfd ); + pango_font_description_free ( pfd ); textbox_font ( tb, tbft ); textbox_text ( tb, text ? text : "" ); @@ -127,17 +129,6 @@ textbox* textbox_create ( Window parent, // set an Xft font by name void textbox_font ( textbox *tb, TextBoxFontType tbft ) { - if ( ( tbft & FMOD_MASK ) != ( tb->tbft & FMOD_MASK ) ) { - PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font ); - if ( ( tbft & BOLD ) == BOLD ) { - pango_font_description_set_weight ( pfd, PANGO_WEIGHT_BOLD ); - } - if ( ( tbft & ITALIC ) == ITALIC ) { - pango_font_description_set_style ( pfd, PANGO_STYLE_ITALIC ); - } - pango_layout_set_font_description ( tb->layout, pfd ); - pango_font_description_free ( pfd ); - } switch ( ( tbft & STATE_MASK ) ) { case HIGHLIGHT: @@ -154,6 +145,14 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft ) tb->color_fg = color_fg; break; } + if ( ( tbft & FMOD_MASK ) ) { + if ( ( tbft & ACTIVE ) ) { + tb->color_fg = color_fg_active; + } + else if ( ( tbft & URGENT ) ) { + tb->color_fg = color_fg_urgent; + } + } tb->tbft = tbft; } @@ -628,6 +627,8 @@ void textbox_setup ( XVisualInfo *visual, Colormap colormap, parse_color ( visual_info->visual, target_colormap, bg, &color_bg ); parse_color ( visual_info->visual, target_colormap, fg, &color_fg ); + parse_color ( visual_info->visual, target_colormap, config.menu_fg_active, &color_fg_active ); + parse_color ( visual_info->visual, target_colormap, config.menu_fg_urgent, &color_fg_urgent ); parse_color ( visual_info->visual, target_colormap, bg_alt, &color_bg_alt ); parse_color ( visual_info->visual, target_colormap, hlfg, &color_hlfg ); parse_color ( visual_info->visual, target_colormap, hlbg, &color_hlbg ); @@ -641,6 +642,8 @@ void textbox_cleanup ( void ) { if ( p_context ) { XftColorFree ( display, visual_info->visual, target_colormap, &color_fg ); + XftColorFree ( display, visual_info->visual, target_colormap, &color_fg_urgent ); + XftColorFree ( display, visual_info->visual, target_colormap, &color_fg_active ); XftColorFree ( display, visual_info->visual, target_colormap, &color_bg ); XftColorFree ( display, visual_info->visual, target_colormap, &color_bg_alt ); XftColorFree ( display, visual_info->visual, target_colormap, &color_hlfg );