diff options
author | delta <darkussdelta@gmail.com> | 2023-05-12 16:18:24 +0200 |
---|---|---|
committer | delta <darkussdelta@gmail.com> | 2023-05-12 16:18:24 +0200 |
commit | f5612f081db0dc69f5c0ebc69e67fa3b098a9ad9 (patch) | |
tree | 7a04027efe5fede7f08688a9524c5dbe6628635b /.config/awesome/services/common.lua | |
parent | ea1bdf6585caed2c0ba8669ca5c3b3b92232281a (diff) |
restructure services, add get_essid to quarrel.native and other wip work
Diffstat (limited to '.config/awesome/services/common.lua')
-rw-r--r-- | .config/awesome/services/common.lua | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/.config/awesome/services/common.lua b/.config/awesome/services/common.lua new file mode 100644 index 0000000..07300db --- /dev/null +++ b/.config/awesome/services/common.lua @@ -0,0 +1,118 @@ +local qfs = require "quarrel.fs" +local gfs = require "gears.filesystem" +local qservice = require "quarrel.service" +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 qvars = require "quarrel.vars" + +-- 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"] + + 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 + return gcolor.recolor_image(phosphor["speaker_simple_x_fill"], qvars.colors.red) + end + + local icon_data = qmath.step_value(volume, { + { 0, "slash" }, + { 25, "none" }, + { 50, "low" }, + { 75, "high" }, + { 100 } + }) + + gcolor.recolor_image(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") + 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 } + }) + + return gcolor.recolor_image(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") + end, + function(brightness) + local icon_data = qmath.step_value(brightness, { + { 0, "cloud_moon" }, + { 51, "moon" }, + { 102, "sun_horizon" }, + { 153, "sun_dim" }, + { 204, "sun" }, + { 255 } + }) + + return gcolor.recolor_image(phosphor[icon_data .. "_fill"], qvars.colors.fg) + end + }, + wifi = { + -- essid, strength, connected + function() + local lines = {} + + for line in io.lines("/proc/net/wireless") do + table.insert(lines, line) + end + + 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 + return gcolor.recolor_image(phosphor.wifi_x_fill, qvars.colors.red) + end + + local icon_data = qmath.step_value(strength, { + { 0, { "none", "red" } }, + { 25, { "low", "yellow" } }, + { 50, { "medium", "yellow" } }, + { 75, { "high", "green" } }, + { 100 } + }) + + return gcolor.recolor_image(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]) +end |