summaryrefslogtreecommitdiff
path: root/awesome/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'awesome/widgets')
-rw-r--r--awesome/widgets/audio.lua1
-rw-r--r--awesome/widgets/pavolctld.lua99
-rw-r--r--awesome/widgets/pipewire.lua34
-rw-r--r--awesome/widgets/temperature.lua11
4 files changed, 140 insertions, 5 deletions
diff --git a/awesome/widgets/audio.lua b/awesome/widgets/audio.lua
index fa5c747..002c556 100644
--- a/awesome/widgets/audio.lua
+++ b/awesome/widgets/audio.lua
@@ -13,7 +13,6 @@ local audio_dropdown = awful.popup {
},
ontop = true,
placement = awful.placement.centered,
- --shape = gears.shape.infobubble,
border_width = 1,
border_color = "#ff0000",
visible = true,
diff --git a/awesome/widgets/pavolctld.lua b/awesome/widgets/pavolctld.lua
new file mode 100644
index 0000000..33b03d8
--- /dev/null
+++ b/awesome/widgets/pavolctld.lua
@@ -0,0 +1,99 @@
+local awful = require("awful")
+local wibox = require("wibox")
+local naughty = require("naughty")
+
+-- Gio is used to handle the subprocess instead of awful.spawn.
+-- Gio is more flexible and allows writing to stdin.
+-- also, awful.spawn.with_line_callback does not play nicely with pavolctld, as
+-- it seems to feed the stdout back into its stdin and kill performance.
+local lgi = require("lgi")
+local Gio = lgi.Gio
+
+-- return table
+local widget = {
+ textbox = wibox.widget.textbox()
+}
+
+-- start subprocess
+local p = Gio.Subprocess.new({ "pavolctld" }, Gio.SubprocessFlags.STDIN_PIPE + Gio.SubprocessFlags.STDOUT_PIPE)
+
+local stdout = p:get_stdout_pipe()
+local stdin = p:get_stdin_pipe()
+
+-- state vars
+local sinks = {
+ default = nil,
+ current = nil, -- sink being modified by commands
+ sinks = {},
+}
+
+function sinks.get(i)
+ if sinks.sinks[i] == nil then
+ sinks.sinks[i] = {
+ vol = 0,
+ db = 0.0,
+ mute = 0,
+ name = "",
+ desc = "",
+ }
+ end
+ return sinks.sinks[i]
+end
+
+-- parse output
+function parse_csv(csv)
+ return (csv .. ","):gmatch("(.-),")
+end
+
+awful.spawn.read_lines(stdout, function(s)
+ local cmd = s:sub(1, 1) -- first char of output
+ -- volume change
+ if cmd == 'v' then
+ local v = parse_csv(s:sub(2))
+ local i = tonumber(v())
+ local sink = sinks.get(i)
+ sink.vol = tonumber(v())
+ sink.db = tonumber(v())
+ sink.mute = tonumber(v())
+
+ if sink == sinks.default then
+ widget.textbox:set_text(sink.vol)
+ end
+ -- sink description change
+ elseif cmd == 's' then
+ local v = parse_csv(s:sub(2))
+ local i = tonumber(v())
+ local sink = sinks.get(i)
+ sink.name = v()
+ sink.desc = v()
+ -- default sink change
+ elseif cmd == 'f' then
+ local f = tonumber(s:sub(2))
+ sinks.default = sinks.get(f)
+ widget.textbox:set_text(sinks.default.vol)
+ -- sink removed
+ elseif cmd == 'x' then
+ local x = tonumber(s:sub(2))
+ table.remove(sinks.sinks, x)
+ else
+ naughty.notify({
+ preset = naughty.config.presets.critical,
+ title = "pavolctld output error",
+ text = "pavolctld output data '" .. s .. "' is not recognized as a valid input"
+ })
+ end
+end)
+
+-- pavolctld takes commands in using stdin
+function pavolctld_cmd(cmd)
+ local _, err = stdin:write_all(cmd .. "\n", nil)
+
+ if err then return nil end
+ return true
+end
+
+function widget.volume_inc(vol) return pavolctld_cmd("v+" .. vol) end
+function widget.volume_dec(vol) return pavolctld_cmd("v-" .. vol) end
+function widget.volume_set(vol) return pavolctld_cmd("v" .. vol) end
+
+return widget
diff --git a/awesome/widgets/pipewire.lua b/awesome/widgets/pipewire.lua
new file mode 100644
index 0000000..3195ee7
--- /dev/null
+++ b/awesome/widgets/pipewire.lua
@@ -0,0 +1,34 @@
+local awful = require("awful")
+local wibox = require("wibox")
+
+--local get_volume_cmd = "wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed 's/Volume: //;s/0*\\.//'"
+--local set_volume_cmd = "wpctl set-volume @DEFAULT_AUDIO_SINK@ %d%%%s" -- will be formatted
+local get_volume_cmd = "wpctl get-volume @DEFAULT_AUDIO_SINK@"
+
+local widget = {
+ textbox = wibox.widget.textbox()
+}
+
+local updating = false
+function update_volume()
+ if updating then
+ return
+ end
+ awful.spawn.easy_async(get_volume_cmd, function(vol)
+ updating = true
+ vol = vol:sub(8) * 100 -- skip `Volume: ` whos len is 8
+ widget.textbox:set_text(math.floor(vol))
+ updating = false
+ end)
+end
+
+-- NOTE pulseaudio-utils (pactl) is still required due to the dependence on the
+-- `pactl subscribe` command. in the future it would be advantageous to replace
+-- this. currently it is (probably) only really possible with dbus.
+awful.spawn.with_line_callback("pactl subscribe", { stdout = function(stdout)
+ --update_volume()
+end })
+
+update_volume()
+
+return widget.textbox
diff --git a/awesome/widgets/temperature.lua b/awesome/widgets/temperature.lua
index 8cf1aa9..985291d 100644
--- a/awesome/widgets/temperature.lua
+++ b/awesome/widgets/temperature.lua
@@ -7,10 +7,13 @@ local linux = { file = nil }
function linux.temperature(widget)
-- read meminfo
local tempf = io.open(linux.file)
- local temp = tempf:read() / 1000
- tempf:close()
-
- widget:set_text(math.floor(temp))
+ if tempf then
+ local temp = tempf:read() / 1000
+ tempf:close()
+ widget:set_text(math.floor(temp))
+ else
+ widget:set_text("err")
+ end
end