diff --git a/awesome-widgets/battery/battery.lua b/awesome-widgets/battery/battery.lua new file mode 100644 index 0000000..efae8bb --- /dev/null +++ b/awesome-widgets/battery/battery.lua @@ -0,0 +1,117 @@ +local wibox = require("wibox") +local beautiful = require("beautiful") +local awful = require("awful") +local naughty = require("naughty") + +local io = io +local math = math +local tonumber = tonumber +local tostring = tostring +local print = print +local pairs = pairs + +local limits = {{12, 3}, + { 5, 1}, + {0}} + +function get_bat_state (adapter) + -- power_supply/charge_now changes to energy_now when resuming from hibernation + local fcur = io.open("/sys/class/power_supply/"..adapter.."/charge_now") + local fcap = io.open("/sys/class/power_supply/"..adapter.."/charge_full") + local fsta = io.open("/sys/class/power_supply/"..adapter.."/status") + if fcur == nil then + fcur = io.open("/sys/class/power_supply/"..adapter.."/energy_now") + if fcur == nil then + -- most probably, we just returned from sleep or + -- nibernation and file is not here yet + return nil, nil + end + end + + if fcap == nil then + fcap = io.open("/sys/class/power_supply/"..adapter.."/energy_full") + end + + local cur = fcur:read() + local cap = fcap:read() + local sta = fsta:read() + fcur:close() + fcap:close() + fsta:close() + local battery = math.floor(cur * 100 / cap) + if sta:match("Charging") then + dir = 1 + elseif sta:match("Discharging") then + dir = -1 + else + dir = 0 + battery = "" + end + return battery, dir +end + +function getnextlim (num) + for ind, pair in pairs(limits) do + lim = pair[1]; step = pair[2]; nextlim = limits[ind+1][1] or 0 + if num > nextlim then + repeat + lim = lim - step + until num > lim + if lim < nextlim then + lim = nextlim + end + return lim + end + end +end + + +function batclosure (adapter) + local nextlim = limits[1][1] + return function () + local prefix = "⚡C⚡" + local battery, dir = get_bat_state(adapter) + if battery == nil then return end -- just thawed or woke up + if dir == -1 then + dirsign = "↓" + prefix = "Bat:" + if battery <= nextlim then + naughty.notify({title = "⚡ Warning ⚡", + text = "Battery charge is low ( ⚡ "..battery.."%)!", + timeout = 7, + position = "bottom_right", + fg = beautiful.fg_focus, + bg = beautiful.bg_focus + }) + nextlim = getnextlim(battery) + end + return " "..prefix.." "..dirsign..battery..dirsign.." " + elseif dir == 1 then + dirsign = "↑" + nextlim = limits[1][1] + return " "..prefix.." "..dirsign..battery..dirsign.." " + else + dirsign = "" + return " "..prefix.." " + end + if dir ~= 0 then battery = battery.."%" end + + end +end + +battery_widget_text = wibox.widget.textbox() +battery_widget_text:set_align("right") + +bat_clo = batclosure("BAT0") + +battery_widget_text:set_markup(bat_clo()) +battimer = timer({ timeout = 30 }) +battimer:connect_signal("timeout", + function() + battery_widget_text:set_markup(bat_clo()) + end) +battimer:start() + +battery_widget = wibox.widget.background() +battery_widget:set_widget(battery_widget_text) +--battery_widget:set_bg('#660066') diff --git a/awesome-widgets/sound/volume.lua b/awesome-widgets/sound/volume.lua new file mode 100644 index 0000000..5683c56 --- /dev/null +++ b/awesome-widgets/sound/volume.lua @@ -0,0 +1,29 @@ +local wibox = require("wibox") +local awful = require("awful") + +volume_widget_text = wibox.widget.textbox() +volume_widget_text:set_align("right") + +function update_volume(widget) + local fd = io.popen("amixer sget Master") + local status = fd:read("*all") + fd:close() + + local volume = string.match(status, "(%d?%d?%d)%%") + volume = string.format("%d", volume) + + status = string.match(status, "%[(o[^%]]*)%]") + + if string.find(status, "on", 1, true) then + volume = " " .. volume .. " " + else + volume = " " .. volume .. " " + end + widget:set_markup(volume) +end + +update_volume(volume_widget_text) + +volume_widget = wibox.widget.background() +volume_widget:set_widget(volume_widget_text) +--volume_widget:set_bg('#000066')