Skip to content

Commit

Permalink
XEP-0392: get background color from theme
Browse files Browse the repository at this point in the history
So far we just used -1 (default color). Now we actually check whether
`bkgnd` is set in the theme file and use this if available.

Fix #1255
  • Loading branch information
jubalh committed Jan 22, 2020
1 parent dac6d08 commit 802df37
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/config/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#endif

#include "config/color.h"
#include "config/theme.h"
#include "log.h"

static
Expand Down Expand Up @@ -494,13 +495,19 @@ static int _color_pair_cache_get(int fg, int bg)
* possible given a 256 colors terminal.
*
* hash a string into a color that will be used as fg
* use default color as bg
* check for 'bkgnd' in theme file or use default color as bg
*/
int color_pair_cache_hash_str(const char *str, color_profile profile)
{
int fg = color_hash(str, profile);
int bg = -1;

char *bkgnd = theme_get_bkgnd();
if (bkgnd) {
bg = find_col(bkgnd, strlen(bkgnd));
free(bkgnd);
}

return _color_pair_cache_get(fg, bg);
}

Expand Down
8 changes: 8 additions & 0 deletions src/config/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,14 @@ _theme_prep_bgnd(char *setting, char *def, GString *lookup_str)
g_free(val);
}

/* return value needs to be freed */
char*
theme_get_bkgnd(void)
{
char *val = g_key_file_get_string(theme, "colours", "bkgnd", NULL);
return val;
}

static void
_theme_prep_fgnd(char *setting, GString *lookup_str, gboolean *bold)
{
Expand Down
1 change: 1 addition & 0 deletions src/config/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,6 @@ theme_item_t theme_main_presence_attrs(const char *const presence);
theme_item_t theme_roster_unread_presence_attrs(const char *const presence);
theme_item_t theme_roster_active_presence_attrs(const char *const presence);
theme_item_t theme_roster_presence_attrs(const char *const presence);
char* theme_get_bkgnd(void);

#endif

0 comments on commit 802df37

Please sign in to comment.