Last active
January 21, 2017 05:40
-
-
Save aawray/0f405157eccfe114e3dbd7485288ec14 to your computer and use it in GitHub Desktop.
Awesome WM additional widgets #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Standard awesome library | |
local awful = require("awful") | |
local vicious = require("vicious") | |
-- Widget and layout library | |
local wibox = require("wibox") | |
---wibox2 | |
-- | |
-- Memory | |
-- Initialize widget | |
memwidget = wibox.widget.textbox() | |
-- Register widget | |
vicious.register(memwidget, vicious.widgets.mem, 'RAM: <span color="#CC9933">$1%</span> ($2MB/$3MB) ', 11) | |
-- Initialize widget | |
memwidget2 = wibox.widget.progressbar() | |
-- Progressbar properties | |
memwidget2:set_width(50) | |
memwidget2:set_vertical(true) | |
memwidget2:set_background_color("#494B4F") | |
memwidget2:set_border_color(nil) | |
memwidget2:set_color({ type = "linear", from = { 0, 0 }, to = { 10,0 }, stops = { {0, "#AECF96"}, {0.5, "#88A175"}, | |
{1, "#FF5656"}}}) | |
-- Register widget | |
vicious.register(memwidget2, vicious.widgets.mem, "$1", 10) | |
-- Initialize widget | |
cpuwidget = awful.widget.graph() | |
-- Graph properties | |
cpuwidget:set_width(50) | |
cpuwidget:set_background_color("#494B4F") | |
cpuwidget:set_color({ type = "linear", from = { 0, 0 }, to = { 10,0 }, stops = { {0, "#FF5656"}, {0.5, "#88A175"}, | |
{1, "#AECF96" }}}) | |
-- Register widget | |
vicious.register(cpuwidget, vicious.widgets.cpu, " $1") | |
-- Initialize widget | |
cpuwidget2 = wibox.widget.textbox() | |
-- Register widget | |
vicious.register(cpuwidget2, vicious.widgets.cpu, ' CPU: <span color="#CC9933">$1%</span>', 1) | |
-- wifi widget | |
wifiwidget = wibox.widget.textbox() | |
vicious.register(wifiwidget, vicious.widgets.wifi, 'Connected to <span color="#7F9F7F">${ssid}</span> at <span color="#7F9F7F">${linp}%</span> | ', 2, "wlp3s0") | |
--Weather Widget | |
weather = wibox.widget.textbox() | |
vicious.register(weather, vicious.widgets.weather, " Weather: ${city} | Temp: ${tempf}⁰F (${tempc}⁰C) | Humid: ${humid}% | ", 1200, "KPVD") | |
---vicious.register(weather, vicious.widgets.weather, "Weather: ${city}. Sky: ${sky}. Temp: ${tempc}c Humid: ${humid}%. Wind: ${windkmh} KM/h", 1200, "LFBO") | |
-- network widget | |
---- Initialize widget Ethernet | |
--ethwidget = wibox.widget.textbox() | |
---- Register widget | |
-- vicious.register(ethwidget, vicious.widgets.net, 'Eth0: <span color="#CC9933">down: ${eth0 down_kb} kB/s</span> <span color="#7F9F7F"> up: ${eth0 up_kb} kB/s</span><span color="#cccccc"> [ ${eth0 rx_gb} GB // ${eth0 tx_gb} GB ] | </span>', 2) | |
-- | |
---- Initialize widget Wifi | |
--netwidget = wibox.widget.textbox() | |
---- Register widget | |
-- vicious.register(netwidget, vicious.widgets.net, 'WiFi: <span color="#CC9933">down: ${wlp3s0 down_kb} kB/s</span> <span color="#7F9F7F"> up: ${wlp3s0 up_kb} kB/s</span><span color="#cccccc"> [ ${wlp3s0 rx_gb} GB // ${wlp3s0 tx_gb} GB ] </span>', 1) | |
-- | |
-- | |
-- Possible network devices | |
eths = { 'eth0', 'wlp3s0' } | |
netwidget = wibox.widget.textbox() | |
vicious.register( netwidget, vicious.widgets.net, | |
function(widget,args) | |
t='' | |
for i = 1, #eths do | |
e = eths[i] | |
if args["{"..e.." carrier}"] == 1 then | |
if e == 'wlp3s0' then | |
t=t..'|'..'Wifi: <span color="#CC9933"> down: '..args['{'..e..' down_kb}']..' kbps</span> <span color="#7F9F7F">up: ' ..args['{'..e..' up_kb}']..' kbps </span>'..'[ '..args['{'..e..' rx_gb}'].. ' GB // ' ..args['{'..e..' tx_gb}']..' GB ] ' | |
else | |
t=t..'|'..'Eth0: <span color="#CC9933"> down: '..args['{'..e..' down_kb}']..' kbps</span> <span color="#7F9F7F">up: ' ..args['{'..e..' up_kb}']..' kbps </span>'..'[ '..args['{'..e..' rx_gb}'].. ' GB // ' ..args['{'..e..' tx_gb}']..' GB ] ' | |
end | |
end | |
end | |
if string.len(t)>0 then -- remove leading '|' | |
return string.sub(t,2,-1) | |
end | |
return 'No network detected ' | |
end | |
, 1 ) | |
-- | |
-- Initialize widget date | |
datewidget = wibox.widget.textbox() | |
-- Register widget | |
vicious.register(datewidget, vicious.widgets.date, " %a %b %d, %H:%M:%S ", 1) | |
-- Initialize widget battery | |
batwidget = wibox.widget.textbox() | |
vicious.register(batwidget, vicious.widgets.bat, ' | Bat:<span color="#CC9933"> $2% </span> [<span color="#7F9F7F"> $3</span> ] ', 60, "BAT0") | |
-- -------------- -- | |
-- OTHER VERSIONS -- | |
-- Keyboard map indicator and switcher | |
mykeyboardlayout = awful.widget.keyboardlayout() | |
-- {{{ Battery state text | |
-- Initialize widget | |
batterywidget = wibox.widget.textbox() | |
batterywidget.border_width = 5 | |
bat_clo = battery.batclosure("BAT0") | |
batterywidget:set_text(bat_clo()) | |
battimer = timer({ timeout = 30 }) | |
battimer:connect_signal("timeout", function() batterywidget:set_text(bat_clo()) end) | |
battimer:start() | |
-- }}} | |
-- {{{ Volume | |
-- Initialize widget | |
volumewidget = wibox.widget { | |
{ | |
max_value = 100, | |
value = 0, | |
background_color = '#222222', | |
color = { type = "linear", from = { 0, 0 }, to = { 20, 0 }, stops = { { 0, "#46FF31" }, { 0.5, "#FBFF0B" }, { 1, "#FF0000" } }}, | |
widget = wibox.widget.progressbar, | |
}, | |
forced_height = 20, | |
forced_width = 15, | |
direction = 'east', | |
layout = wibox.container.rotate, | |
buttons = awful.util.table.join( | |
awful.button({ }, 4, | |
function () | |
awful.util.spawn_with_shell("amixer set Master playback 1%+ -M") | |
vicious.force({volumewidget}) | |
end), | |
awful.button({ }, 5, | |
function () | |
awful.util.spawn_with_shell("amixer set Master playback 1%- -M") | |
vicious.force({volumewidget}) | |
end) | |
) | |
} | |
volume_text = awful.tooltip({objects = {volumewidget},}) | |
vicious.register(volumewidget, vicious.widgets.volume, | |
function (widget, args) | |
if args[2] == "♫" then -- Sound is ON | |
widget.widget:set_value(args[1]) | |
volume_text:set_text(args[1] .. "%") | |
return args[1] | |
else | |
widget.widget:set_value(0) | |
volume_text:set_text("Mute") | |
return 0 | |
end | |
end, 5, "Master" | |
) | |
-- }}} | |
-- {{{ CPU load | |
-- Create CPU load widget | |
cpubar = awful.widget.graph() | |
cpubar.border_width = 5 | |
cpubar:set_width(40) | |
cpubar:set_background_color("#222222") | |
cpubar:set_color({ type = "linear", from = { 0, 0 }, to = { 0, 20 }, stops = { { 0, "#FF0000" }, { 0.5, "#391BFA" }, { 1, "#391BFA" } }}) | |
cpubar_t = awful.tooltip({ objects = { cpubar }, }) | |
--vicious.register(cpubar, vicious.widgets.cpu, "$1") | |
vicious.register(cpubar, vicious.widgets.cpu, | |
function (widget, args) | |
local p = io.popen("ps aux --sort=-pcpu | head -6 | awk '{ proc=\"\" \n for(i = 11; i <= NF; i++) proc = proc $i \" \" \n printf \"\\n%-10s %-6s %-6s %-30s\",$1,$2,$3,substr(proc, 0, 30)}'") | |
local o = p:read("*all") | |
p:close() | |
o = string.gsub(o, "<", "{") | |
o = string.gsub(o, ">", "}") | |
cpubar_t:set_text(string.format("CPU Usage %s%%%s", args[1], o)) | |
return args[1] | |
end) | |
-- }}} | |
-- {{{ RAM usage | |
-- RAM usage widget | |
memwidget = wibox.widget { | |
{ | |
max_value = 100, | |
value = 0, | |
background_color = '#222222', | |
color = { type = "linear", from = { 0, 0 }, to = { 15, 0 }, stops = { { 0, "#AECF96" }, { 0.5, "#88A175" }, { 1, "#FF5656" } }}, | |
widget = wibox.widget.progressbar, | |
}, | |
forced_height = 20, | |
forced_width = 10, | |
direction = 'east', | |
layout = wibox.container.rotate, | |
} | |
-- RAM usage tooltip | |
memwidget_t = awful.tooltip({ objects = { memwidget },}) | |
vicious.cache(vicious.widgets.mem) | |
vicious.register(memwidget, vicious.widgets.mem, | |
function (widget, args) | |
local p = io.popen("ps -eo user,pid,rss,args --sort=-rss | head -11 | awk '{hr[1024*1024]=\"GB\"; hr[1024]=\"MB\"; h=0; for (x=1024*1024*1024; x>=1024; x/=1024) { if ($3>=x) { h=x; break } } { proc=\"\"; for(i = 4; i <= NF; i++) proc = proc $i \" \" } { if(NR != 1) { printf (\"\\n%-10s %-6s %-6.2f%s %-30s\", $1, $2, $3/h, hr[h], substr(proc, 0, 30)) } else { printf (\"\\n%-10s %-6s %s %-30s\", $1, $2, \"SIZE \", substr(proc, 0, 30)) }}}'") | |
local o = p:read("*all") | |
p:close() | |
memwidget_t:set_text(string.format("RAM: %sMB / %sMB%s", args[2], args[3], o)) | |
widget.widget:set_value(args[1]) | |
return args[1] | |
end, 6) | |
--update every 6 seconds | |
-- }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment