Commit 9bcad76e authored by epsi sayidina's avatar epsi sayidina

herbstluftwm dual statusbar

parent 0ce49173
-- vim: ts=4 sw=4 noet ai cindent syntax=lua
--[[
Conky, a system monitor, based on torsmo
]]
conky.config = {
out_to_x = false,
out_to_console = true,
short_units = true,
update_interval = 1
}
--[[
Prepare
]]
local dirname = debug.getinfo(1).source:match("@?(.*/)")
local path = dirname .. "../assets/"
dofile(path .. 'gmc.lua')
dofile(path .. 'helper.lua')
dofile(path .. 'parts.lua')
-- shortcut
local _h = helper
lf = helper.lemonForeground
lb = helper.lemonBackground
la = helper.lemonBackgroundAlpha
lu = helper.lemonUnderline
lr = helper.lemonReset
conky.text = [[\
%{l}\
]] .. lr() .. lf(colRed500) .. [[ \
]] .. parts.uptime () .. [[\
%{c}\
]] .. lr() .. [[\
]] .. parts.battery ()
.. parts.cpu0 ()
.. parts.cputemp ()
.. parts.memory ()
.. parts.volume ()
.. lr() .. [[\
%{r}\
]] .. lr() .. [[\
]] .. parts.host () .. [[\
]] .. lf(colRed500) .. [[ \
]]
-- vim: ts=4 sw=4 noet ai cindent syntax=lua
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- google material colors
-- https://material.io/guidelines/style/color.html
colWhite = '\\#ffffff'
colBlack = '\\#000000'
colGrey50 = '\\#fafafa'
colGrey100 = '\\#f5f5f5'
colGrey200 = '\\#eeeeee'
colGrey300 = '\\#e0e0e0'
colGrey400 = '\\#bdbdbd'
colGrey500 = '\\#9e9e9e'
colGrey600 = '\\#757575'
colGrey700 = '\\#616161'
colGrey800 = '\\#424242'
colGrey900 = '\\#212121'
colRed50 = '\\#ffebee'
colRed100 = '\\#ffcdd2'
colRed200 = '\\#ef9a9a'
colRed300 = '\\#e57373'
colRed400 = '\\#ef5350'
colRed500 = '\\#f44336'
colRed600 = '\\#e53935'
colRed700 = '\\#d32f2f'
colRed800 = '\\#c62828'
colRed900 = '\\#b71c1c'
colRedA100 = '\\#ff8a80'
colRedA200 = '\\#ff5252'
colRedA400 = '\\#ff1744'
colRedA700 = '\\#d50000'
colPink50 = '\\#fce4ec'
colPink100 = '\\#f8bbd0'
colPink200 = '\\#f48fb1'
colPink300 = '\\#f06292'
colPink400 = '\\#ec407a'
colPink500 = '\\#e91e63'
colPink600 = '\\#d81b60'
colPink700 = '\\#c2185b'
colPink800 = '\\#ad1457'
colPink900 = '\\#880e4f'
colPinkA100 = '\\#ff80ab'
colPinkA200 = '\\#ff4081'
colPinkA400 = '\\#f50057'
colPinkA700 = '\\#c51162'
colIndigo50 = '\\#e8eaf6'
colIndigo100 = '\\#c5cae9'
colIndigo200 = '\\#9fa8da'
colIndigo300 = '\\#7986cb'
colIndigo400 = '\\#5c6bc0'
colIndigo500 = '\\#3f51b5'
colIndigo600 = '\\#3949ab'
colIndigo700 = '\\#303f9f'
colIndigo800 = '\\#283593'
colIndigo900 = '\\#1a237e'
colIndigoA100 = '\\#8c9eff'
colIndigoA200 = '\\#536dfe'
colIndigoA400 = '\\#3d5afe'
colIndigoA700 = '\\#304ffe'
colBlue50 = '\\#e3f2fd'
colBlue100 = '\\#bbdefb'
colBlue200 = '\\#90caf9'
colBlue300 = '\\#64b5f6'
colBlue400 = '\\#42a5f5'
colBlue500 = '\\#2196f3'
colBlue600 = '\\#1e88e5'
colBlue700 = '\\#1976d2'
colBlue800 = '\\#1565c0'
colBlue900 = '\\#0d47a1'
colBlueA100 = '\\#82b1ff'
colBlueA200 = '\\#448aff'
colBlueA400 = '\\#2979ff'
colBlueA700 = '\\#2962ff'
colYellow50 = '\\#fffde7'
colYellow100 = '\\#fff9c4'
colYellow200 = '\\#fff59d'
colYellow300 = '\\#fff176'
colYellow400 = '\\#ffee58'
colYellow500 = '\\#ffeb3b'
colYellow600 = '\\#fdd835'
colYellow700 = '\\#fbc02d'
colYellow800 = '\\#f9a825'
colYellow900 = '\\#f57f17'
colYellowA100 = '\\#ffff8d'
colYellowA200 = '\\#ffff00'
colYellowA400 = '\\#ffea00'
colYellowA700 = '\\#ffd600'
colTeal50 = '\\#e0f2f1'
colTeal100 = '\\#b2dfdb'
colTeal200 = '\\#80cbc4'
colTeal300 = '\\#4db6ac'
colTeal400 = '\\#26a69a'
colTeal500 = '\\#009688'
colTeal600 = '\\#00897b'
colTeal700 = '\\#00796b'
colTeal800 = '\\#00695c'
colTeal900 = '\\#004d40'
colTealA100 = '\\#a7ffeb'
colTealA200 = '\\#64ffda'
colTealA400 = '\\#1de9b6'
colTealA700 = '\\#00bfa5'
colGreen50 = '\\#e8f5e9'
colGreen100 = '\\#c8e6c9'
colGreen200 = '\\#a5d6a7'
colGreen300 = '\\#81c784'
colGreen400 = '\\#66bb6a'
colGreen500 = '\\#4caf50'
colGreen600 = '\\#43a047'
colGreen700 = '\\#388e3c'
colGreen800 = '\\#2e7d32'
colGreen900 = '\\#1b5e20'
colGreenA100 = '\\#b9f6ca'
colGreenA200 = '\\#69f0ae'
colGreenA400 = '\\#00e676'
colGreenA700 = '\\#00c853'
colOrange50 = '\\#fff3e0'
colOrange100 = '\\#ffe0b2'
colOrange200 = '\\#ffcc80'
colOrange300 = '\\#ffb74d'
colOrange400 = '\\#ffa726'
colOrange500 = '\\#ff9800'
colOrange600 = '\\#fb8c00'
colOrange700 = '\\#f57c00'
colOrange800 = '\\#ef6c00'
colOrange900 = '\\#e65100'
colOrangeA100 = '\\#ffd180'
colOrangeA200 = '\\#ffab40'
colOrangeA400 = '\\#ff9100'
colOrangeA700 = '\\#ff6d00'
colDeepOrange50 = '\\#fbe9e7'
colDeepOrange100 = '\\#ffccbc'
colDeepOrange200 = '\\#ffab91'
colDeepOrange300 = '\\#ff8a65'
colDeepOrange400 = '\\#ff7043'
colDeepOrange500 = '\\#ff5722'
colDeepOrange600 = '\\#f4511e'
colDeepOrange700 = '\\#e64a19'
colDeepOrange800 = '\\#d84315'
colDeepOrange900 = '\\#bf360c'
colDeepOrangeA100 = '\\#ff9e80'
colDeepOrangeA200 = '\\#ff6e40'
colDeepOrangeA400 = '\\#ff3d00'
colDeepOrangeA700 = '\\#dd2c00'
-- vim: ts=4 sw=4 noet ai cindent syntax=lua-- global
helper = {}
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- constant
helper.alphaValue = 'aa'
colorPresetDark = {
icon = colYellow500,
label = colBlue500,
value = colGrey700,
underline = colWhite,
background = '-'
}
colorPresetBright = {
icon = colWhite,
label = colPink500,
value = colWhite,
underline = colBlack,
background = '-'
}
helper.count = 0
colorPreset = colorPresetDark
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- lemonade
function helper.alpha(color)
alphaValue = helper.alphaValue
color = string.sub(color, 3)
color = '\\#' .. alphaValue .. color
return color
end
function helper.lemonized(tag, color)
return '%{' .. tag .. color .. '}'
end
function helper.lemonForeground(color)
return '%{F' .. color .. '}'
end
function helper.lemonBackground(color)
return '-' and '%{B-}' or '%{B' .. color .. '}'
end
function helper.lemonBackgroundAlpha(color)
return '-' and '%{B-}' or '%{B' .. helper.alpha(color) .. '}'
end
function helper.lemonUnderline(color)
return '%{U' .. color .. '}'
end
function helper.lemonReset()
return '%{B-}%{F-}%{-u}'
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
function helper.icon(text, color)
color = color or colorPreset.icon
return ' ' .. helper.lemonForeground(color) .. text .. ' '
end
function helper.label(text, color)
color = color or colorPreset.label
return helper.lemonForeground(color) .. text
end
function helper.separator(color)
color = color or colorPreset.separator
return helper.lemonForeground(color) .. '|'
end
function helper.value(text, color)
color = color or colorPreset.value
return helper.lemonForeground(color) .. text
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
function helper.common(icon, label, value)
text = ''
if icon then text = text
.. helper.icon(icon, colorPreset.icon)
end
if label then text = text
.. ' ' .. helper.label(label, colorPreset.label)
end
if value then text = text
.. ' ' .. helper.value(value, colorPreset.value) .. ' '
end
return text
end
function helper.compose(icon, label, value, colorBg)
colorBg = colorBg or colorPreset.background
if (helper.count % 2) == 0 then
colorPreset = colorPresetDark
else
colorPreset = colorPresetBright
end
text = helper.lemonBackgroundAlpha(colorBg)
text = text .. helper.lemonUnderline(colorPreset.underline)
text = text .. helper.common(icon, label, value)
text ='%{+u}' .. text .. '%{-u}' .. helper.lemonReset()
helper.count = helper.count + 1
return text
end
-- vim: ts=4 sw=4 noet ai cindent syntax=lua
--[[
You may consider change glyph using FontAwesome icon
http://fontawesome.io/cheatsheet/
* Sample: Battery Icon: 
]]
parts = {}
-- user variables
local wlandev = 'wlp0s3f3u2'
-- shortcut
local _h = helper
-- template variables: Color Indicator
local color_indicator_dark = {
good = colBlack,
degraded = colRed900,
bad = colRed500
}
local color_indicator_bright = {
good = colGrey300,
degraded = colRed700,
bad = colRed900
}
local ci = color_indicator_bright
-- Separator
function parts.separator(colorBgSt, colorBgNd, colorFg)
text = '%{+u}'
text = text .. _h.lemonForeground(colorFg)
text = text .. _h.lemonBackgroundAlpha(colorBgSt)
if (helper.count % 2) == 0 then
colorUnderline = colBlack
else
colorUnderline = colWhite
end
text = text .. _h.lemonUnderline(colorUnderline)
text = text .. ''
text = text .. _h.lemonBackgroundAlpha(colorBgNd)
if (helper.count % 2) == 0 then
colorUnderline = colWhite
else
colorUnderline = colBlack
end
text = text .. _h.lemonUnderline(colorUnderline)
text = text .. ''
text = text .. '%{-u}'
return text
end
-- Time
function parts.time(colorBg)
return _h.compose('', nil, '${time %H:%M }', colorBg)
end
-- Date
function parts.date(colorBg)
return _h.compose('', nil, '${time %D}', colorBg)
end
-- Volume
function parts.volume(colorBg)
local volume_command = [[amixer get Master | tail -1 | sed 's/.*\[\([0-9]*%\)\].*/\1/']]
return _h.compose('', 'Vol', "${execi 1 " .. volume_command .. "}", colorBg)
end
-- Host
function parts.host(colorBg)
return _h.compose('', 'Host', '$nodename', colorBg)
end
-- Uptime
function parts.uptime(colorBg)
return _h.compose('', 'Uptime', '$uptime', colorBg)
end
-- Memory
function parts.mem(colorBg)
return _h.compose('', 'RAM', '$mem/$memmax', colorBg)
end
-- SSID
function parts.ssid(colorBg)
return _h.compose(' ', '', '$wireless_essid', colorBg)
end
-- Lua Function Demo
-- https://github.com/brndnmtthws/conky/issues/62
function _h.exec(command)
local file = assert(io.popen(command, 'r'))
local s = file:read('*all')
file:close()
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
-- read once
local machine = _h.exec('uname -r')
function parts.machine(colorBg)
return _h.compose('', nil, machine, colorBg)
end
-- Media Player Daemon
function parts.mpd(colorBg)
local mpd = [[\
${if_mpd_playing}\
]] .. _h.icon('')
.. _h.value(' ${mpd_artist 20} ')
.. _h.icon('')
.. _h.value(' ${mpd_title 30}') ..[[
${else}]] .. _h.icon('') .. [[${endif}\
]]
return _h.compose(nil, nil, mpd, colorBg)
end
-- CPU temperature:
function parts.cputemp(colorBg)
local cputemp = [[\
${if_match ${acpitemp}<45}\
]] .. _h.value('${acpitemp}°C', ci.good) .. [[
${else}${if_match ${acpitemp}<55}\
]] .. _h.value('${acpitemp}°C', ci.degraded) .. [[
${else}${if_match ${acpitemp}>=55}\
]] .. _h.value('${acpitemp}°C', ci.bad) .. [[
${endif}${endif}${endif}\
]]
return _h.compose('', 'CPU', cputemp, colorBg)
end
-- Network
function parts.network(colorBg)
local download = _h.icon('') .. [[\
${if_match ${downspeedf ]] .. wlandev .. [[}<1000}\
]] .. _h.value('${downspeed ' .. wlandev .. '}', ci.good) .. [[
${else}${if_match ${downspeedf ]] .. wlandev .. [[}<3000}\
]] .. _h.value('${downspeed ' .. wlandev .. '}', ci.degraded) .. [[
${else}${if_match ${downspeedf ]] .. wlandev .. [[}>=3000}\
]] .. _h.value('${downspeed ' .. wlandev .. '}', ci.bad) .. [[
${endif}${endif}${endif}\
]]
local upload = _h.icon('') .. [[\
${if_match ${upspeedf ]] .. wlandev .. [[}<300}\
]] .. _h.value('${upspeed ' .. wlandev .. '}', ci.good) .. [[
${else}${if_match ${upspeedf ]] .. wlandev .. [[}<800}\
]] .. _h.value('${upspeed ' .. wlandev .. '}', ci.degraded) .. [[
${else}${if_match ${upspeedf ]] .. wlandev .. [[}>=800}\
]] .. _h.value('${upspeed ' .. wlandev .. '}', ci.bad) .. [[
${endif}${endif}${endif}\
]]
return _h.compose(nil, nil, download .. upload, colorBg)
end
-- Memory
function parts.memory(colorBg)
local memory = [[\
${if_match ${memperc}<30}\
]] .. _h.value('${memeasyfree}', ci.good) .. [[
${else}${if_match ${memperc}<70}\
]] .. _h.value('${memeasyfree}',ci.degraded) .. [[
${else}${if_match ${memperc}>=70}\
]] .. _h.value('${memeasyfree}', ci.bad) .. [[
${endif}${endif}${endif}\
]]
return _h.compose('', 'MEM', memory, colorBg)
end
-- CPU 0
function parts.cpu0(colorBg)
local cpu0 = [[\
${if_match ${cpu cpu0}<50}\
]] .. _h.value('${cpu cpu0}%', ci.good) .. [[
${else}${if_match ${cpu cpu0}<60}\
]] .. _h.value('${cpu cpu0}%',ci.degraded) .. [[
${else}${if_match ${cpu cpu0}<=100}\
]] .. _h.value('${cpu cpu0}%', ci.bad) .. [[
${endif}${endif}${endif}\
]]
return _h.compose('', 'CPU', cpu0, colorBg)
end
-- Battery
function parts.battery(colorBg)
local battery = [[\
${if_match ${battery_percent}<30}\
]] .. _h.value('${battery_percent}%', ci.bad) .. [[
${else}${if_match ${battery_percent}<70}\
]] .. _h.value('${battery_percent}%', ci.degraded) .. [[
${else}${if_match ${battery_percent}>=70}\
]] .. _h.value('${battery_percent}%', ci.good) .. [[
${endif}${endif}${endif}\
]]
return _h.compose('', 'Battery', battery, colorBg)
end
-- Template
--parts.template = [[
--]] .. _h.separator() .. [[,
--]] .. _h.icon('') .. [[,
--]] .. _h.label('') .. [[,
--]] .. _h.value('', '#aaaaaa') .. [[
--]]
......@@ -51,7 +51,7 @@ function get_bottom_panel_geometry() {
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# lemonbar Parameters
function get_lemon_parameters() {
function get_params_top() {
# parameter: function argument
local monitor=$1
local panel_height=$2
......@@ -69,7 +69,6 @@ function get_lemon_parameters() {
# XFT: require lemonbar_xft_git
local font_takaop="takaopgothic-9"
local font_bottom="monospace-9"
local font_symbol="PowerlineSymbols-11"
local font_awesome="FontAwesome-9"
......@@ -78,3 +77,34 @@ function get_lemon_parameters() {
lemon_parameters+=" -B $bgcolor -F $fgcolor"
lemon_parameters+=" -f $font_takaop -f $font_awesome -f $font_symbol"
}
function get_params_bottom() {
# parameter: function argument
local monitor=$1
local panel_height=$2
# calculate geometry
get_geometry $monitor
get_bottom_panel_geometry $panel_height "${geometry[@]}"
# geometry: -g widthxheight+x+y
geom_res="${width}x${height}+${xpos}+${ypos}"
# color, with transparency
local bgcolor="#aa000000"
local fgcolor="#ffffff"
# XFT: require lemonbar_xft_git
local font_mono="monospace-9"
local font_symbol="PowerlineSymbols-11"
local font_awesome="FontAwesome-9"
# finally
lemon_parameters=" -g $geom_res -u 2"
lemon_parameters+=" -B $bgcolor -F $fgcolor"
lemon_parameters+=" -f $font_mono -f $font_awesome -f $font_symbol"
}
function get_lemon_parameters() {
get_params_top $monitor $panel_height
}
......@@ -16,17 +16,14 @@ DIR=$(dirname "$0")
panel_height=24
get_monitor ${@}
get_lemon_parameters $monitor $panel_height
# do `man herbsluftclient`, and type \pad to search what it means
herbstclient pad $monitor $panel_height 0 $panel_height 0
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# pipe
# remove all lemonbar instance
pkill lemonbar
herbstclient pad $monitor $panel_height 0 $panel_height 0
# run process in the background
get_params_top $monitor $panel_height
detach_lemon $monitor $lemon_parameters
get_params_bottom $monitor $panel_height
detach_lemon_conky $lemon_parameters
......@@ -98,3 +98,15 @@ function detach_lemon() {
run_lemon $monitor $parameters &
}
function detach_lemon_conky() {
parameters=$@
command_out="lemonbar $parameters"
{
dirname=$(dirname $(readlink -f "$0"))
path="$dirname/../assets"
conky -c "$path/conky.lua"
} | $command_out &
}
......@@ -4,7 +4,8 @@ module MyHelper
, XYWH (XYWH)
, getTopPanelGeometry
, getBottomPanelGeometry
, getLemonParameters
, getParamsTop
, getParamsBottom
) where
import System.Process
......@@ -66,9 +67,8 @@ getBottomPanelGeometry
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- lemonbar Parameters
getLemonParameters :: Int -> [Int] -> [String]
getLemonParameters
panelHeight geometry = [
getParamsTop :: Int -> [Int] -> [String]
getParamsTop panelHeight geometry = [
"-g", geom_res, "-u", "2",
"-B", bgcolor, "-F", fgcolor,
"-f", font_takaop,
......@@ -90,6 +90,35 @@ getLemonParameters
-- XFT: require lemonbar_xft_git
font_takaop = "takaopgothic-9"
font_bottom = "monospace-9"
font_symbol = "PowerlineSymbols-11"
font_awesome = "FontAwesome-9"
getParamsBottom :: Int -> [Int] -> [String]
getParamsBottom panelHeight geometry = [
"-g", geom_res, "-u", "2",
"-B", bgcolor, "-F", fgcolor,
"-f", font_mono,
"-f", font_awesome,
"-f", font_symbol
]
where
-- calculate geometry
XYWH xpos ypos width height = getBottomPanelGeometry
panelHeight geometry
-- geometry: -g widthxheight++y
geom_res = width ++ "x" ++ height
++ "+" ++ xpos ++ "+" ++ ypos
-- color, with transparency
bgcolor = "#aa000000"
fgcolor = "#ffffff"
-- XFT: require lemonbar_xft_git
font_mono = "monospace-9"
font_symbol = "PowerlineSymbols-11"