[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:
parent
89247d834b
commit
b5c2ca6ccf
4 changed files with 118 additions and 6 deletions
|
@ -73,21 +73,59 @@ class i3(object):
|
|||
if not self.__theme.separator():
|
||||
return []
|
||||
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({
|
||||
'full_text': self.__theme.separator(),
|
||||
'color': self.__theme.bg(widget),
|
||||
'background': self.__theme.bg('previous'),
|
||||
'_decorator': True,
|
||||
})
|
||||
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):
|
||||
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({
|
||||
'full_text': self.__decorate(module, widget, text),
|
||||
'color': self.__theme.fg(widget),
|
||||
'background': self.__theme.bg(widget),
|
||||
'min_width': self.__decorate(module, widget, widget.get('theme.minwidth')),
|
||||
})
|
||||
if (self.__config.debug()):
|
||||
attr.update({
|
||||
|
|
|
@ -44,6 +44,7 @@ class Theme(object):
|
|||
('border-right', 0),
|
||||
('padding', ''),
|
||||
('prefix', ''), ('suffix', ''),
|
||||
('pango', None),
|
||||
]:
|
||||
setattr(self, attr.replace('-', '_'), lambda widget=None, default=default, attr=attr: self.__get(widget, attr, default))
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# How to write themes
|
||||
|
||||
## TODO: Pango support!
|
70
themes/powerline-pango.json
Normal file
70
themes/powerline-pango.json
Normal 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"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue