[core/output] Add generic pango support

Allow any piece of a theme that specifies a set of attributes (default,
cycles, states, widgets) to use pango *instead* of the usual attributes.

If pango is present, this will have precedence.

A practical example of this can be found in the powerline-pango theme,
which is added solely for demonstration purposes.

fixes #531
This commit is contained in:
tobi-wan-kenobi 2020-04-04 14:37:19 +02:00
parent 89247d834b
commit b5c2ca6ccf
4 changed files with 118 additions and 6 deletions

View file

@ -73,21 +73,59 @@ class i3(object):
if not self.__theme.separator(): if not self.__theme.separator():
return [] return []
attr = self.__common_attributes(module, widget) attr = self.__common_attributes(module, widget)
attr.update({
'_decorator': True,
})
pango = self.__theme.pango(widget)
prev_pango = self.__theme.pango('previous') or {}
if pango:
pango = dict(pango)
if 'bgcolor' in pango:
pango['fgcolor'] = pango['bgcolor']
del pango['bgcolor']
if 'background' in pango:
pango['foreground'] = pango['background']
del pango['background']
if 'bgcolor' in prev_pango:
pango['bgcolor'] = prev_pango['bgcolor']
if 'background' in prev_pango:
pango['background'] = prev_pango['background']
attr.update({
'full_text': self.__pango(self.__theme.separator(), pango),
'markup': 'pango'
})
else:
attr.update({ attr.update({
'full_text': self.__theme.separator(), 'full_text': self.__theme.separator(),
'color': self.__theme.bg(widget), 'color': self.__theme.bg(widget),
'background': self.__theme.bg('previous'), 'background': self.__theme.bg('previous'),
'_decorator': True,
}) })
return [attr] return [attr]
def __pango(self, text, attributes):
result = '<span'
for key, value in attributes.items():
result = '{} {}="{}"'.format(result, key, value)
result = '{}>{}</span>'.format(result, text)
return result
def __main(self, module, widget, text): def __main(self, module, widget, text):
attr = self.__common_attributes(module, widget) attr = self.__common_attributes(module, widget)
attr.update({
'min_width': self.__decorate(module, widget, widget.get('theme.minwidth')),
})
pango = self.__theme.pango(widget)
if pango:
attr.update({
'full_text': self.__pango(self.__decorate(module, widget, text), pango),
'markup': 'pango'
})
else:
attr.update({ attr.update({
'full_text': self.__decorate(module, widget, text), 'full_text': self.__decorate(module, widget, text),
'color': self.__theme.fg(widget), 'color': self.__theme.fg(widget),
'background': self.__theme.bg(widget), 'background': self.__theme.bg(widget),
'min_width': self.__decorate(module, widget, widget.get('theme.minwidth')),
}) })
if (self.__config.debug()): if (self.__config.debug()):
attr.update({ attr.update({

View file

@ -44,6 +44,7 @@ class Theme(object):
('border-right', 0), ('border-right', 0),
('padding', ''), ('padding', ''),
('prefix', ''), ('suffix', ''), ('prefix', ''), ('suffix', ''),
('pango', None),
]: ]:
setattr(self, attr.replace('-', '_'), lambda widget=None, default=default, attr=attr: self.__get(widget, attr, default)) setattr(self, attr.replace('-', '_'), lambda widget=None, default=default, attr=attr: self.__get(widget, attr, default))

View file

@ -0,0 +1,3 @@
# How to write themes
## TODO: Pango support!

View file

@ -0,0 +1,70 @@
{
"icons": [ "awesome-fonts" ],
"defaults": {
"separator-block-width": 0,
"critical": {
"pango": {
"foreground": "#ffffff",
"background": "#ff0000"
}
},
"warning": {
"pango": {
"foreground": "#d75f00",
"background": "#ffd700"
}
},
"default_separators": false
},
"cycle": [
{
"pango": {
"foreground": "#ffd700",
"background": "#d75f00"
}
},
{
"pango": {
"foreground": "#ffffff",
"background": "#0087af"
}
}
],
"dnf": {
"good": {
"fg": "#494949",
"bg": "#41db00"
}
},
"apt": {
"good": {
"fg": "#494949",
"bg": "#41db00"
}
},
"battery": {
"charged": {
"fg": "#494949",
"bg": "#41db00"
},
"AC": {
"fg": "#494949",
"bg": "#41db00"
}
},
"pomodoro": {
"paused": {
"fg": "#d75f00",
"bg": "#ffd700"
},
"work": {
"fg": "#ffd700",
"bg": "#d75f00"
},
"break": {
"fg": "#494949",
"bg": "#41db00"
}
}
}