2023-05-12 09:18:24 -05:00
|
|
|
local gfs = require "gears.filesystem"
|
2023-05-21 03:12:46 -05:00
|
|
|
local gtimer = require "gears.timer"
|
|
|
|
local phosphor = require "assets.phosphor"
|
|
|
|
local qfs = require "quarrel.fs"
|
2023-05-12 09:18:24 -05:00
|
|
|
local qjson = require "quarrel.json"
|
|
|
|
local qmath = require "quarrel.math"
|
2023-05-21 03:12:46 -05:00
|
|
|
local qnative = require "quarrel.native"
|
|
|
|
local qstore = require "quarrel.store"
|
2023-05-12 09:18:24 -05:00
|
|
|
local qvars = require "quarrel.vars"
|
|
|
|
|
2023-05-21 03:12:46 -05:00
|
|
|
local q = require "quarrel"
|
|
|
|
|
|
|
|
local function register(name, service, icon)
|
|
|
|
gtimer {
|
|
|
|
timeout = 0.5,
|
|
|
|
call_now = true,
|
|
|
|
autostart = true,
|
|
|
|
callback = function()
|
|
|
|
local service_result = table.pack(service())
|
|
|
|
awesome.emit_signal("services::" .. name, table.unpack(service_result))
|
|
|
|
awesome.emit_signal("services::" .. name .. "::icon", icon(table.unpack(service_result)))
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local function read(file, format)
|
|
|
|
local content = file:read(format or "a")
|
|
|
|
file:seek("set")
|
|
|
|
return content
|
|
|
|
end
|
|
|
|
|
|
|
|
-- create file in case it's not there yet
|
|
|
|
if not gfs.file_readable("/tmp/wp_audio_status") then
|
|
|
|
assert(io.open("/tmp/wp_audio_status", "w")):write("{}"):close()
|
|
|
|
end
|
|
|
|
qstore.audio_file = assert(io.open("/tmp/wp_audio_status", "r"))
|
|
|
|
qstore.battery_capacity_file = assert(io.open("/sys/class/power_supply/BAT0/capacity", "r"))
|
|
|
|
qstore.battery_status_file = assert(io.open("/sys/class/power_supply/BAT0/status", "r"))
|
|
|
|
qstore.brightness_file = assert(io.open("/sys/class/backlight/amdgpu_bl0/actual_brightness", "r"))
|
|
|
|
qstore.wifi_file = assert(io.open("/proc/net/wireless", "r"))
|
|
|
|
|
2023-05-12 09:18:24 -05:00
|
|
|
-- follows the format `service = { provider, icon_provider }`
|
|
|
|
local services = {
|
|
|
|
audio = {
|
|
|
|
-- volume, muted
|
|
|
|
function()
|
2023-05-21 03:12:46 -05:00
|
|
|
local audio_status = qjson.decode(read(qstore.audio_file))
|
|
|
|
local default_sink = audio_status["G435 Wireless Gaming Headset Analog Stereo"]
|
2023-05-12 09:18:24 -05:00
|
|
|
|
|
|
|
if not default_sink then
|
|
|
|
return nil, false
|
|
|
|
end
|
|
|
|
|
|
|
|
return default_sink.volume, default_sink.muted
|
|
|
|
end,
|
|
|
|
function(volume, muted)
|
|
|
|
if muted or not volume then
|
2023-05-21 03:12:46 -05:00
|
|
|
return phosphor.speaker_simple_x_fill, qvars.colors.red
|
2023-05-12 09:18:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local icon_data = qmath.step_value(volume, {
|
|
|
|
{ 0, "slash" },
|
|
|
|
{ 25, "none" },
|
|
|
|
{ 50, "low" },
|
|
|
|
{ 75, "high" },
|
|
|
|
{ 100 }
|
|
|
|
})
|
|
|
|
|
2023-05-21 03:12:46 -05:00
|
|
|
return phosphor["speaker_simple_" .. icon_data .. "_fill"], qvars.colors.fg
|
2023-05-12 09:18:24 -05:00
|
|
|
end
|
|
|
|
},
|
|
|
|
battery = {
|
|
|
|
-- capacity, status
|
|
|
|
function()
|
2023-05-21 03:12:46 -05:00
|
|
|
return read(qstore.battery_capacity_file, "n"), read(qstore.battery_status_file, "l")
|
2023-05-12 09:18:24 -05:00
|
|
|
end,
|
|
|
|
function(capacity, status)
|
|
|
|
local icon_data = status == "Charging" and { "charging", "green" } or qmath.step_value(capacity, {
|
|
|
|
{ 0, { "empty", "red" } },
|
|
|
|
{ 20, { "low", "red" } },
|
|
|
|
{ 40, { "medium", "yellow" } },
|
|
|
|
{ 60, { "high", "green" } },
|
|
|
|
{ 80, { "full", "green" } },
|
|
|
|
{ 100 }
|
|
|
|
})
|
|
|
|
|
2023-05-21 03:12:46 -05:00
|
|
|
return phosphor["battery_vertical_" .. icon_data[1] .. "_fill"], qvars.colors[icon_data[2]]
|
2023-05-12 09:18:24 -05:00
|
|
|
end
|
|
|
|
},
|
|
|
|
brightness = {
|
|
|
|
-- brightness
|
|
|
|
function()
|
2023-05-21 03:12:46 -05:00
|
|
|
return read(qstore.brightness_file, "n")
|
2023-05-12 09:18:24 -05:00
|
|
|
end,
|
|
|
|
function(brightness)
|
|
|
|
local icon_data = qmath.step_value(brightness, {
|
|
|
|
{ 0, "cloud_moon" },
|
|
|
|
{ 51, "moon" },
|
|
|
|
{ 102, "sun_horizon" },
|
|
|
|
{ 153, "sun_dim" },
|
|
|
|
{ 204, "sun" },
|
|
|
|
{ 255 }
|
|
|
|
})
|
|
|
|
|
2023-05-21 03:12:46 -05:00
|
|
|
return phosphor[icon_data .. "_fill"], qvars.colors.fg
|
2023-05-12 09:18:24 -05:00
|
|
|
end
|
|
|
|
},
|
|
|
|
wifi = {
|
|
|
|
-- essid, strength, connected
|
|
|
|
function()
|
|
|
|
local lines = {}
|
|
|
|
|
2023-05-21 03:12:46 -05:00
|
|
|
for line in qstore.wifi_file:lines() do
|
2023-05-12 09:18:24 -05:00
|
|
|
table.insert(lines, line)
|
|
|
|
end
|
2023-05-21 03:12:46 -05:00
|
|
|
qstore.wifi_file:seek("set")
|
2023-05-12 09:18:24 -05:00
|
|
|
|
|
|
|
if not lines[3] then
|
|
|
|
return nil, 0, false
|
|
|
|
end
|
|
|
|
|
|
|
|
local strength = lines[3]:match("^%s*(.*)"):match("^.-%s+.-%s+.-(%S+)%.")
|
|
|
|
|
|
|
|
return qnative.get_essid(), math.floor(tonumber(strength) * 10 / 7), true
|
|
|
|
end,
|
|
|
|
function(_, strength, connected)
|
|
|
|
if not connected then
|
2023-05-21 03:12:46 -05:00
|
|
|
return phosphor.wifi_x_fill, qvars.colors.red
|
2023-05-12 09:18:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local icon_data = qmath.step_value(strength, {
|
|
|
|
{ 0, { "none", "red" } },
|
|
|
|
{ 25, { "low", "yellow" } },
|
|
|
|
{ 50, { "medium", "yellow" } },
|
|
|
|
{ 75, { "high", "green" } },
|
|
|
|
{ 100 }
|
|
|
|
})
|
|
|
|
|
2023-05-21 03:12:46 -05:00
|
|
|
return phosphor["wifi_" .. icon_data[1] .. "_fill"], qvars.colors[icon_data[2]]
|
2023-05-12 09:18:24 -05:00
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, service in pairs(services) do
|
2023-05-21 03:12:46 -05:00
|
|
|
register(name, service[1], service[2])
|
2023-05-12 09:18:24 -05:00
|
|
|
end
|