It most likely is better positioned here instead of next to the conky configuration.
140 lines
4.5 KiB
Python
140 lines
4.5 KiB
Python
from barpyrus import hlwm
|
|
from barpyrus import widgets as W
|
|
from barpyrus.core import Theme
|
|
from barpyrus import lemonbar
|
|
from barpyrus import conky
|
|
import sys
|
|
import os
|
|
|
|
# set up connection to herbstluftwm in order to get events and to call
|
|
# herbstclient commands
|
|
hc = hlwm.connect()
|
|
|
|
# get monitor geometry
|
|
monitor = sys.argv[1] if len(sys.argv) >= 2 else 0
|
|
(x, y, monitor_w, monitor_h) = hc.monitor_rect(monitor)
|
|
|
|
# height/width of the panel
|
|
height = 16 if os.uname().nodename != 'warthog' else 30
|
|
width = monitor_w
|
|
|
|
# set fonts used by lemonbar
|
|
if os.uname().nodename == 'warthog':
|
|
text_font = '*-*-lucidatypewriter-medium-*-*-*-26-*-*-*-*-*-*-*'
|
|
symbol_font = '*-wuncon-siji-medium-r-normal-*-26-200-100-*-c-*-iso10646-1'
|
|
else:
|
|
text_font = '*-*-lucidatypewriter-medium-*-*-*-12-*-*-*-*-*-*-*'
|
|
symbol_font = '*-wuncon-siji-medium-r-normal-*-12-100-100-*-c-80-iso10646-1'
|
|
|
|
# create color-dict for often used colors
|
|
color = {
|
|
'black': '#000000',
|
|
'grey': '#303030',
|
|
'lightgrey':'#989898',
|
|
'white': '#EFEFEF',
|
|
'orange': '#FFA500',
|
|
'yellow': '#FFFD00',
|
|
'green': '#19CB00',
|
|
'cyan': '#0DCDCD',
|
|
'lightblue':'#8470FF',
|
|
'blue': '#0026FF',
|
|
'magenta': '#CB1ED1',
|
|
'red': '#CC0403',
|
|
}
|
|
|
|
# function to insert colored icon into conky_text
|
|
def conky_icon(icon_code, icon_color, text_color = 'lightgrey'):
|
|
text = '%{F\\' + color[icon_color] + '}%{T2}' + icon_code + '%{T-}'
|
|
text += '%{F\\' + color[text_color] + '}'
|
|
return text
|
|
|
|
# conky specific configuration
|
|
# cpu temperature
|
|
conky_text = '${if_match \"$acpitemp\" <= \"50\"}'
|
|
conky_text += conky_icon('\ue01b', 'lightblue')
|
|
conky_text += '${else}'
|
|
conky_text += '${if_match \"$acpitemp\" <= \"70\"}'
|
|
conky_text += conky_icon('\ue01b', 'orange')
|
|
conky_text += '${else}'
|
|
conky_text += conky_icon('\ue01b', 'red')
|
|
conky_text += '${endif}'
|
|
conky_text += '${endif}'
|
|
conky_text += '${acpitemp}°C '
|
|
|
|
# cpu and memory load factor
|
|
conky_text += conky_icon('\ue026', 'green') + '${cpu}% '
|
|
conky_text += conky_icon('\ue021', 'green') + '${memperc}% '
|
|
|
|
# battery display
|
|
bat_icons = [
|
|
'\ue242', '\ue243', '\ue244', '\ue245', '\ue246',
|
|
'\ue247', '\ue248', '\ue249', '\ue24a', '\ue24b',
|
|
]
|
|
bat_delta = 100 / len(bat_icons)
|
|
|
|
conky_text += '${if_existing /sys/class/power_supply/BAT0}'
|
|
conky_text += '${if_match \"$battery\" == \"discharging $battery_percent%\"}'
|
|
for i, icon in enumerate(bat_icons[:-1]):
|
|
percentage = (i + 1) * bat_delta
|
|
conky_text += '${if_match $battery_percent < %d}' % (percentage)
|
|
if percentage <= 20:
|
|
conky_text += conky_icon(icon, 'red')
|
|
elif percentage <= 65:
|
|
conky_text += conky_icon(icon, 'yellow')
|
|
else:
|
|
conky_text += conky_icon(icon, 'green')
|
|
conky_text += '${else}'
|
|
# 100 percent icon
|
|
conky_text += conky_icon(bat_icons[-1], 'green')
|
|
# close all previously opened if_match tags
|
|
for _ in bat_icons[:-1]:
|
|
conky_text += '${endif}'
|
|
conky_text += '${else}'
|
|
conky_text += conky_icon('\ue239', 'cyan')
|
|
conky_text += '${endif}'
|
|
conky_text += ' $battery_percent% '
|
|
conky_text += '${endif}'
|
|
conky_text += '%{F-}'
|
|
|
|
# options for hlwm.HLWMLayoutSwitcher widget
|
|
xkblayouts = [
|
|
'us us -variant altgr-intl us'.split(' '),
|
|
'de de de'.split(' '),
|
|
]
|
|
setxkbmap = 'setxkbmap -option compose:menu -option ctrl:nocaps'
|
|
setxkbmap += ' -option compose:ralt -option compose:rctrl'
|
|
|
|
# function to create colored frames
|
|
def frame(content, bg, fg, padding = (3, 3)):
|
|
return Theme(bg = color[bg], fg = color[fg], padding = padding)(content)
|
|
|
|
# get space for the panel
|
|
hc(['pad', str(monitor), str(height)])
|
|
|
|
# initialize lemonbar
|
|
bar = lemonbar.Lemonbar(geometry = (x, y, width, height),
|
|
font = text_font, symbol_font = symbol_font)
|
|
|
|
# widget configuration
|
|
bar.widget = W.ListLayout([
|
|
W.RawLabel('%{l}'),
|
|
hlwm.HLWMTags(hc, monitor, tag_renderer = hlwm.underlined_tags),
|
|
|
|
W.RawLabel('%{c}'),
|
|
hlwm.HLWMMonitorFocusLayout(hc, monitor,
|
|
# this widget is shown on the focused monitor:
|
|
frame(hlwm.HLWMWindowTitle(hc), 'grey', 'white'),
|
|
# this widget is shown on all unfocused monitors:
|
|
W.RawLabel('')),
|
|
|
|
W.RawLabel('%{r}'),
|
|
conky.ConkyWidget(text = conky_text),
|
|
W.ShortLongLayout(
|
|
W.RawLabel(''),
|
|
W.ListLayout([
|
|
hlwm.HLWMLayoutSwitcher(hc, xkblayouts, command = setxkbmap.split(' ')),
|
|
W.RawLabel(' '),
|
|
])
|
|
),
|
|
frame(W.DateTime('%d. %B, %H:%M'), 'grey', 'white'),
|
|
])
|