aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/services/common.lua
diff options
context:
space:
mode:
authordelta <darkussdelta@gmail.com>2023-05-21 10:12:46 +0200
committerdelta <darkussdelta@gmail.com>2023-05-21 10:12:46 +0200
commitf42a3a2cc941e34dd938b1e6bc24785a44781db2 (patch)
treebec91db370c7bcd5be2bb614d2d315a32c751215 /.config/awesome/services/common.lua
parentf5612f081db0dc69f5c0ebc69e67fa3b098a9ad9 (diff)
major update of awesome config
add new icons, switch over to using stylesheets instead of gears.color.recolor_image, add a music widget to the panel, optimize services in common.lua, fix the application lense filtering and increase the update rate of services in common.lua Signed-off-by: delta <darkussdelta@gmail.com>
Diffstat (limited to '.config/awesome/services/common.lua')
-rw-r--r--.config/awesome/services/common.lua70
1 files changed, 49 insertions, 21 deletions
diff --git a/.config/awesome/services/common.lua b/.config/awesome/services/common.lua
index 07300db..b23a064 100644
--- a/.config/awesome/services/common.lua
+++ b/.config/awesome/services/common.lua
@@ -1,24 +1,51 @@
-local qfs = require "quarrel.fs"
local gfs = require "gears.filesystem"
-local qservice = require "quarrel.service"
+local gtimer = require "gears.timer"
+local phosphor = require "assets.phosphor"
+local qfs = require "quarrel.fs"
local qjson = require "quarrel.json"
-local qnative = require "quarrel.native"
-local gcolor = require "gears.color"
local qmath = require "quarrel.math"
-local phosphor = require "assets.phosphor"
+local qnative = require "quarrel.native"
+local qstore = require "quarrel.store"
local qvars = require "quarrel.vars"
+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"))
+
-- follows the format `service = { provider, icon_provider }`
local services = {
audio = {
-- volume, muted
function()
- if not gfs.file_readable("/tmp/wp_audio_status") then
- awesome.emit_signal("services::audio", -1, false)
- return
- end
- local audio_status = qjson.decode(qfs.read("/tmp/wp_audio_status"))
- local default_sink = audio_status["alsa_output.usb-046d_G435_Wireless_Gaming_Headset_V001008005.1-01.analog-stereo"]
+ local audio_status = qjson.decode(read(qstore.audio_file))
+ local default_sink = audio_status["G435 Wireless Gaming Headset Analog Stereo"]
if not default_sink then
return nil, false
@@ -28,7 +55,7 @@ local services = {
end,
function(volume, muted)
if muted or not volume then
- return gcolor.recolor_image(phosphor["speaker_simple_x_fill"], qvars.colors.red)
+ return phosphor.speaker_simple_x_fill, qvars.colors.red
end
local icon_data = qmath.step_value(volume, {
@@ -39,13 +66,13 @@ local services = {
{ 100 }
})
- gcolor.recolor_image(phosphor["speaker_simple_" .. icon_data .. "_fill"], qvars.colors.fg)
+ return phosphor["speaker_simple_" .. icon_data .. "_fill"], qvars.colors.fg
end
},
battery = {
-- capacity, status
function()
- return qfs.read("/sys/class/power_supply/BAT0/capacity", "n"), qfs.read("/sys/class/power_supply/BAT0/status", "l")
+ return read(qstore.battery_capacity_file, "n"), read(qstore.battery_status_file, "l")
end,
function(capacity, status)
local icon_data = status == "Charging" and { "charging", "green" } or qmath.step_value(capacity, {
@@ -57,13 +84,13 @@ local services = {
{ 100 }
})
- return gcolor.recolor_image(phosphor["battery_vertical_" .. icon_data[1] .. "_fill"], qvars.colors[icon_data[2]])
+ return phosphor["battery_vertical_" .. icon_data[1] .. "_fill"], qvars.colors[icon_data[2]]
end
},
brightness = {
-- brightness
function()
- return qfs.read("/sys/class/backlight/amdgpu_bl0/actual_brightness", "n")
+ return read(qstore.brightness_file, "n")
end,
function(brightness)
local icon_data = qmath.step_value(brightness, {
@@ -75,7 +102,7 @@ local services = {
{ 255 }
})
- return gcolor.recolor_image(phosphor[icon_data .. "_fill"], qvars.colors.fg)
+ return phosphor[icon_data .. "_fill"], qvars.colors.fg
end
},
wifi = {
@@ -83,9 +110,10 @@ local services = {
function()
local lines = {}
- for line in io.lines("/proc/net/wireless") do
+ for line in qstore.wifi_file:lines() do
table.insert(lines, line)
end
+ qstore.wifi_file:seek("set")
if not lines[3] then
return nil, 0, false
@@ -97,7 +125,7 @@ local services = {
end,
function(_, strength, connected)
if not connected then
- return gcolor.recolor_image(phosphor.wifi_x_fill, qvars.colors.red)
+ return phosphor.wifi_x_fill, qvars.colors.red
end
local icon_data = qmath.step_value(strength, {
@@ -108,11 +136,11 @@ local services = {
{ 100 }
})
- return gcolor.recolor_image(phosphor["wifi_" .. icon_data[1] .. "_fill"], qvars.colors[icon_data[2]])
+ return phosphor["wifi_" .. icon_data[1] .. "_fill"], qvars.colors[icon_data[2]]
end
}
}
for name, service in pairs(services) do
- qservice.register(name, service[1], service[2])
+ register(name, service[1], service[2])
end