-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindicator.lua
92 lines (71 loc) · 2.66 KB
/
indicator.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
local wibox = require("wibox")
local awful = require("awful")
local beautiful = require("beautiful")
local naughty = require("naughty")
local gears = require("gears")
local indicator = {}
local function worker(args)
local args = args or {}
local widget = wibox.layout.fixed.horizontal()
-- Settings come here
local timeout = args.timeout or 60
local battery = args.battery or "BAT0/"
local font = args.font or beautiful.font
local battery_path = "/sys/class/power_supply/" .. battery
local catbat = "cat " .. battery_path
-- Widget contents
local bat_text = wibox.widget.textbox()
bat_text:set_text("No info!")
local battery_level = 0
local status = ""
-- Change this based on lookup
local battery_connected = true
local acpi_timer = nil
local function acpi_update()
local battery_status = ""
-- Do acpi update stuff and set bat text accordingly
awful.spawn.easy_async(catbat .. "capacity", function(capacity, _, _, _)
battery_level = string.match(capacity, "([0-9]*)") or "N/A"
awful.spawn.easy_async(catbat .. "status", function(status_val, _, _, _)
status = status_val
if string.match(status, "Charging") then
battery_status = "⬆"
else
battery_status = "⬇"
end
bat_text:set_text(battery_status .. battery_level .. "%")
acpi_timer:start()
end)
end)
end
acpi_timer = gears.timer.start_new(timeout, function() acpi_update() end)
acpi_update()
widget:add(bat_text)
local notification = nil
function widget:hide()
if notification ~= nil then
naughty.destroy(notification)
notification = nil
end
end
function widget:show(tout)
widget:hide()
local msg = "Battery not present."
awful.spawn.easy_async({"bash", "-c", "acpi | cut -d, -f 3"}, function(remaining, _, _, _)
msg =
"<span font_desc=\""..font.."\">"..
"┌["..battery.."]\n"..
"├Status: "..status..
"└Time:\t"..remaining.."</span>"
notification = naughty.notify({
preset = fs_notification_preset,
text = msg,
timeout = tout
})
end)
end
widget:connect_signal('mouse::enter', function () widget:show(0) end)
widget:connect_signal('mouse::leave', function () widget:hide() end)
return widget
end
return setmetatable(indicator, {__call = function(_,...) return worker(...) end})