更改 awesome pulse 音量显示组件

This commit is contained in:
2025-02-25 04:29:30 +08:00
parent 8df4070ec1
commit 2419068ede
5 changed files with 108 additions and 57 deletions

View File

@@ -16,9 +16,8 @@
ln -sf "${dir}/pravitekeys.lua" ~/.config/awesome/ ln -sf "${dir}/pravitekeys.lua" ~/.config/awesome/
# 链接定制主题 # 链接定制主题
ln -sf "${dir}/multicolor-theme.lua" ~/.config/awesome/themes/multicolor/theme-personal.lua ln -sf "${dir}/multicolor-theme.lua" ~/.config/awesome/themes/multicolor/theme-personal.lua
# pulse 组建打补丁,该补丁主要为修正蓝牙耳机显示名称 # 链接 pulse 音量显示组件
cd ~/.config/awesome/lain/ ln -sf "${dir}/pulse.lua" ~/.config/awesome/lain/widget/pulse.lua
git apply "$dir/pulse-audio.diff"
#+end_src #+end_src
* 定制 =multicolor= 主题 * 定制 =multicolor= 主题

View File

@@ -203,7 +203,7 @@ local volicon = wibox.widget.imagebox(theme.widget_vol)
theme.volume = lain.widget.pulse({ theme.volume = lain.widget.pulse({
settings = function() settings = function()
vlevel = volume_now.left .. "-" .. volume_now.right .. "%|" .. volume_now.device vlevel = volume_now.left .. "-" .. volume_now.right .. "%|" .. volume_now.device
if volume_now.muted == "yes" then if volume_now.muted then
vlevel = vlevel .. " M" vlevel = vlevel .. " M"
end end
widget:set_markup(markup.fontfg(theme.font, "#7493d2", vlevel)) widget:set_markup(markup.fontfg(theme.font, "#7493d2", vlevel))

View File

@@ -1,51 +0,0 @@
diff --git a/widget/pulse.lua b/widget/pulse.lua
index 69f4d70..d485d97 100644
--- a/widget/pulse.lua
+++ b/widget/pulse.lua
@@ -22,14 +22,17 @@ local function factory(args)
local settings = args.settings or function() end
pulse.devicetype = args.devicetype or "sink"
- pulse.cmd = args.cmd or "pacmd list-" .. pulse.devicetype .. "s | sed -n -e '/*/,$!d' -e '/index/p' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'"
+ pulse.cmd = args.cmd or "pacmd list-" .. pulse.devicetype .. "s | sed -n -e '/*/,$!d' -e '/index/p' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p' -e '/device\\.description/p'"
function pulse.update()
helpers.async({ shell, "-c", type(pulse.cmd) == "string" and pulse.cmd or pulse.cmd() },
function(s)
+ local description = string.match(s, "device.description = \"(.-)\"")
+ local devicestring = string.match(s, "device.string = \"(%S+)\"")
+ local device = string.len(description) < string.len(devicestring) and description or devicestring
volume_now = {
index = string.match(s, "index: (%S+)") or "N/A",
- device = string.match(s, "device.string = \"(%S+)\"") or "N/A",
+ device = device or "N/A",
muted = string.match(s, "muted: (%S+)") or "N/A"
}
diff --git a/widget/pulsebar.lua b/widget/pulsebar.lua
index 19e73b9..b1dbc1c 100644
--- a/widget/pulsebar.lua
+++ b/widget/pulsebar.lua
@@ -51,7 +51,7 @@ local function factory(args)
pulsebar.followtag = args.followtag or false
pulsebar.notification_preset = args.notification_preset
pulsebar.devicetype = args.devicetype or "sink"
- pulsebar.cmd = args.cmd or "pacmd list-" .. pulsebar.devicetype .. "s | sed -n -e '/*/,$!d' -e '/index/p' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'"
+ pulsebar.cmd = args.cmd or "pacmd list-" .. pulsebar.devicetype .. "s | sed -n -e '/*/,$!d' -e '/index/p' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p' -e '/device\\.description/p'"
if not pulsebar.notification_preset then
pulsebar.notification_preset = {
@@ -76,9 +76,12 @@ local function factory(args)
function pulsebar.update(callback)
helpers.async({ awful.util.shell, "-c", type(pulsebar.cmd) == "string" and pulsebar.cmd or pulsebar.cmd() },
function(s)
+ local description = string.match(s, "device.description = \"(.-)\"")
+ local devicestring = string.match(s, "device.string = \"(%S+)\"")
+ local device = string.len(description) < string.len(devicestring) and description or devicestring
volume_now = {
index = string.match(s, "index: (%S+)") or "N/A",
- device = string.match(s, "device.string = \"(%S+)\"") or "N/A",
+ device = device or "N/A",
muted = string.match(s, "muted: (%S+)") or "N/A"
}

103
awesome/pulse.lua Normal file
View File

@@ -0,0 +1,103 @@
local helpers = require("lain.helpers")
local dkjson = require("lain.util.dkjson")
local shell = require("awful.util").shell
local wibox = require("wibox")
local string = string
local type = type
-- PulseAudio volume
-- lain.widget.pulse
local function get_device_name(sink)
local names = {
sink.description,
sink.properties["api.alsa.path"],
sink.properties["device.description"],
}
local name = names[1]
for i = 2, #names do
local current_name = names[i]
if not name then
name = names[i]
elseif current_name and string.len(name) > string.len(current_name) then
name = current_name
end
end
return name or "N/A"
end
local function split_sink_and_json(text)
local fn = string.gmatch(text, "[^\r\n]+")
local default_sink = fn()
local json_text = fn()
return default_sink, json_text
end
local function parse_sink(text)
local sink_name, json_text = split_sink_and_json(text)
local sink
for _, s in pairs(dkjson.decode(json_text)) do
if sink then
break
end
if s.name == sink_name then
sink = s
end
end
local names = {}
local channel_map, vol, props = sink.channel_map, sink.volume, sink.properties
local channel = {}
local ch = 1
for ch_name in string.gmatch(channel_map, "([%w-]+)") do
local vol_text = vol[ch_name].value_percent
channel[ch] = string.match(vol_text, "(%d+)%%") or "N/A"
ch = ch + 1
end
local volume = {
index = sink.index,
device = get_device_name(sink),
muted = sink.mute,
channel = channel,
left = channel[1] or "N/A",
right = channel[2] or "N/A",
}
return volume
end
local function factory(args)
args = args or {}
local pulse = { widget = args.widget or wibox.widget.textbox(), device = "N/A" }
local timeout = args.timeout or 5
local settings = args.settings or function() end
pulse.devicetype = args.devicetype or "sink"
pulse.cmd = args.cmd or "pactl get-default-" .. pulse.devicetype .. ";pactl -f json list " .. pulse.devicetype .. "s"
function pulse.update()
helpers.async({ shell, "-c", type(pulse.cmd) == "string" and pulse.cmd or pulse.cmd() },
function(s)
volume_now = parse_sink(s)
pulse.device = volume_now.index
widget = pulse.widget
settings()
end)
end
helpers.newtimer("pulse", timeout, pulse.update)
return pulse
end
return factory

View File

@@ -57,7 +57,7 @@ local function run_once(cmd_arr)
end end
end end
run_once({ "unclutter -root", "pulseaudio --start", "picom -b --backend xrender" }) -- entries must be separated by commas run_once({ "unclutter -root", "gentoo-pipewire-launcher", "picom -b --backend xrender" }) -- entries must be separated by commas
-- This function implements the XDG autostart specification -- This function implements the XDG autostart specification
--[[ --[[
@@ -769,7 +769,7 @@ awful.rules.rules = {
properties = { tag = mytags.specify.virtualbox } }, properties = { tag = mytags.specify.virtualbox } },
{ rule = { class = "Emacs" }, { rule = { class = "Emacs" },
properties = { tag = mytags.specify.emacs, switchtotag = true, fullscreen = true } }, properties = { tag = mytags.specify.emacs, switchtotag = true, fullscreen = false } },
{ rule = { class = "dingtalk" }, { rule = { class = "dingtalk" },
properties = { tag = mytags.specify.other2 } }, properties = { tag = mytags.specify.other2 } },