lazy push before updates
This commit is contained in:
85
widgets/battery.lua
Normal file
85
widgets/battery.lua
Normal file
@@ -0,0 +1,85 @@
|
||||
local awful = require("awful")
|
||||
local beautiful = require("beautiful")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local _M = {}
|
||||
|
||||
function _M.update(stdout)
|
||||
local bat_now = {
|
||||
present = "N/A",
|
||||
state = "N/A",
|
||||
warninglevel = "N/A",
|
||||
energy = "N/A",
|
||||
energyfull = "N/A",
|
||||
energyrate = "N/A",
|
||||
voltage = "N/A",
|
||||
percentage = "N/A",
|
||||
capacity = "N/A",
|
||||
icon = "N/A",
|
||||
}
|
||||
|
||||
for k, v in stdout:gmatch("([%a]+[%a|-]+):%s*([%a|%d|']+[,|%a|%d|'|-]+)") do
|
||||
if k == "present" then
|
||||
bat_now.present = v
|
||||
elseif k == "state" then
|
||||
bat_now.state = v
|
||||
elseif k == "warning-level" then
|
||||
bat_now.warninglevel = v
|
||||
elseif k == "energy" then
|
||||
bat_now.energy = v:gsub(",", ".") -- Wh
|
||||
elseif k == "energy-full" then
|
||||
bat_now.energyfull = v:gsub(",", ".") -- Wh
|
||||
elseif k == "energy-rate" then
|
||||
bat_now.energyrate = v:gsub(",", ".") -- W
|
||||
elseif k == "voltage" then
|
||||
bat_now.voltage = v:gsub(",", ".") -- V
|
||||
elseif k == "percentage" then
|
||||
bat_now.percentage = tonumber(v) -- %
|
||||
elseif k == "capacity" then
|
||||
bat_now.capacity = v:gsub(",", ".") -- %
|
||||
elseif k == "icon-name" then
|
||||
bat_now.icon = v
|
||||
end
|
||||
end
|
||||
|
||||
return bat_now
|
||||
end
|
||||
|
||||
function _M.get(show_percentage)
|
||||
_M.show_percentage = show_percentage or true
|
||||
local battery = awful.widget.watch(
|
||||
{
|
||||
awful.util.shell,
|
||||
"-c",
|
||||
"upower -i /org/freedesktop/UPower/devices/battery_BAT0 | sed -n '/present/,/icon-name/p'",
|
||||
},
|
||||
1,
|
||||
function(widget, stdout)
|
||||
local bat_now = _M.update(stdout)
|
||||
|
||||
local icon = wibox.widget.imagebox(beautiful.battery_icon(bat_now.icon) or beautiful.battery_icon_full)
|
||||
local text = wibox.widget.textbox(bat_now.percentage .. "%")
|
||||
|
||||
widget.children = {
|
||||
(_M.show_percentage and text) or wibox.widget.textbox(),
|
||||
icon
|
||||
}
|
||||
end,
|
||||
wibox.widget {
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
}
|
||||
)
|
||||
|
||||
battery.toggle_percentage = function()
|
||||
_M.show_percentage = not _M.show_percentage
|
||||
battery:emit_signal("widget::redraw_needed")
|
||||
end
|
||||
|
||||
return battery
|
||||
end
|
||||
|
||||
return setmetatable({}, {
|
||||
__call = function(_, ...)
|
||||
return _M.get(...)
|
||||
end,
|
||||
})
|
||||
7
widgets/init.lua
Normal file
7
widgets/init.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
return {
|
||||
battery = require("widgets.battery"),
|
||||
volume = require("widgets.volume"),
|
||||
separator = require("widgets.separator"),
|
||||
text_clock = require("widgets.text_clock"),
|
||||
net_widget = require("widgets.net_widgets").wireless({interface="wlp2s0", popup_position = "bottom_right"}),
|
||||
}
|
||||
1
widgets/net_widgets
Submodule
1
widgets/net_widgets
Submodule
Submodule widgets/net_widgets added at 13bc07b875
3
widgets/separator.lua
Normal file
3
widgets/separator.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
local wibox = require("wibox")
|
||||
|
||||
return wibox.widget.textbox(" | ")
|
||||
32
widgets/text_clock.lua
Normal file
32
widgets/text_clock.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local awful = require("awful")
|
||||
local beautiful = require("beautiful")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local lain = require("lain")
|
||||
local markup = lain.util.markup
|
||||
|
||||
local _M = {}
|
||||
|
||||
function _M.get(icon)
|
||||
if not icon then
|
||||
icon = wibox.widget.imagebox(beautiful.clock_icon)
|
||||
end
|
||||
|
||||
local clock = awful.widget.textclock(
|
||||
markup(beautiful.clock_date_color, "%A %B %d ")
|
||||
.. markup(beautiful.clock_text_color, ">")
|
||||
.. markup(beautiful.clock_text_color, " %I:%M %p ")
|
||||
)
|
||||
|
||||
return wibox.widget({
|
||||
icon,
|
||||
clock,
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
})
|
||||
end
|
||||
|
||||
return setmetatable({}, {
|
||||
__call = function(_, ...)
|
||||
return _M.get(...)
|
||||
end,
|
||||
})
|
||||
68
widgets/volume.lua
Normal file
68
widgets/volume.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
local awful = require("awful")
|
||||
local beautiful = require("beautiful")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local _M = {}
|
||||
|
||||
function _M.update(stdout)
|
||||
local vol_now = {
|
||||
volume = "N/A",
|
||||
muted = "N/A",
|
||||
icon = "N/A",
|
||||
}
|
||||
|
||||
vol_now.volume = stdout:gsub("%s+", "")
|
||||
vol_now.volume = vol_now.volume:gsub("%%", "")
|
||||
if vol_now.volume == "muted" then
|
||||
vol_now.muted = true
|
||||
vol_now.volume = -1
|
||||
else
|
||||
vol_now.volume = tonumber(vol_now.volume)
|
||||
vol_now.muted = false
|
||||
end
|
||||
|
||||
if vol_now.muted or vol_now.volume == 0 then
|
||||
vol_now.icon = beautiful.volume_muted_icon
|
||||
elseif vol_now.volume >= 66 then
|
||||
vol_now.icon = beautiful.volume_high_icon
|
||||
elseif vol_now.volume >= 33 then
|
||||
vol_now.icon = beautiful.volume_medium_icon
|
||||
else
|
||||
vol_now.icon = beautiful.volume_low_icon
|
||||
end
|
||||
|
||||
return vol_now
|
||||
end
|
||||
|
||||
function _M.get()
|
||||
local volume = awful.widget.watch(
|
||||
{
|
||||
awful.util.shell,
|
||||
"-c",
|
||||
"pamixer --get-volume-human",
|
||||
},
|
||||
1,
|
||||
function(widget, stdout)
|
||||
local vol_now = _M.update(stdout)
|
||||
|
||||
local icon = wibox.widget.imagebox(vol_now.icon)
|
||||
local text = wibox.widget.textbox(vol_now.volume .. "% ")
|
||||
|
||||
widget.children = {
|
||||
text,
|
||||
icon,
|
||||
}
|
||||
end,
|
||||
wibox.widget({
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
})
|
||||
)
|
||||
|
||||
return volume
|
||||
end
|
||||
|
||||
return setmetatable({}, {
|
||||
__call = function(_, ...)
|
||||
return _M.get(...)
|
||||
end,
|
||||
})
|
||||
Reference in New Issue
Block a user