[theme] Add pango markup for prefix/suffix

Add 4 new theme specifiers:
- prefixfg
- prefixbg
- suffixfg
- suffixbg

All of those are only evaluated if markup type is pango, and result in
pango-formatted prefixes/suffixes.

fixes #520
This commit is contained in:
Tobias Witek 2020-01-11 13:54:53 +01:00
parent 3d4ba73460
commit 629b3381f2
2 changed files with 27 additions and 0 deletions

View file

@ -249,9 +249,20 @@ class I3BarOutput(object):
if not any(state in widget.state() for state in ["warning", "critical"]):
return
padding = self._theme.padding(widget)
prefix = self._theme.prefix(widget, padding)
suffix = self._theme.suffix(widget, padding)
if self._config.markup() == "pango":
# add prefix/suffix colors
fg = self._theme.prefix_fg(widget)
bg = self._theme.prefix_bg(widget)
prefix = "<span {} {}>{}</span>".format(
"foreground='{}'".format(fg) if fg else "",
"background='{}'".format(bg) if bg else "",
prefix
)
if prefix:
full_text = u"{}{}".format(prefix, full_text)
if suffix:

View file

@ -118,6 +118,22 @@ class Theme(object):
pre = self._get(widget, "prefix", None)
return u"{}{}{}".format(padding, pre, padding) if pre else default
def prefix_fg(self, widget):
"""Return the foreground color for the prefix"""
return self._get(widget, "prefixfg", None)
def prefix_bg(self, widget):
"""Return the background color for the prefix"""
return self._get(widget, "prefixbg", None)
def suffix_fg(self, widget):
"""Return the foreground color for the suffix"""
return self._get(widget, "suffixfg", None)
def suffix_bg(self, widget):
"""Return the background color for the suffix"""
return self._get(widget, "suffixbg", None)
def symbol(self, widget, name, default=None):
return self._get(widget, name, default)