惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
C
Check Point Blog
G
Google Developers Blog
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
D
Docker
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News

依云's Blog

Wayfire支持不缩放Xwayland啦 - 依云's Blog 使用wayvnc远程访问无头Wayfire会话 - 依云's Blog pacfiles: 高速的 pacman -F 替代品 用 Android 手机当电脑的话筒 - 依云's Blog 使用 ffmpeg 对音频文件进行响度归一化 - 依云's Blog 使用 nftables 屏蔽大量 IP - 依云's Blog YubiKey 初体验 - 依云's Blog fcitx5 码表同步方案 - 依云's Blog 我正在使用的火狐扩展(2024年版) - 依云's Blog 使用 PipeWire 实现自动应用均衡器 如果你发现你的 OOM Killer 在乱杀进程 使用 atuin 管理 shell 命令历史 btrfs 元数据满了怎么办 btrfs 翻车记 在 nspawn 里运行 docker Linux 上的字体配置与故障排除 新的 PaddleOCR 部署方案 使用 EasyEffects 调整 Bose 音箱的体验 让离线软件真正离线 我所讨厌的网页行为 tmux 状态栏优化 Google Chrome 中的字体设置 从 getmail6 到 offlineimap 微信消息通知的困扰 Qt 的字体渲染问题 Wayfire 迁移进展(四):不那么 high 的 DPI Wayfire 迁移进展(二):Xwayland HiDPI 以及 waybar Wayfire 迁移进展 不同情况下的图形效果 Wayland 初体验
Awesome 调节音量不再依赖 GNOME
依云 · 2011-12-05 · via 依云's Blog

之前一直在用 gnome-sound-applet 来调节音量。今天终于脱离了它。

GNOME 越来越臃肿了。今天系统出了点小问题,查看日志时再次看到 dbus 报怨 NetworkManager 没有运行的错误。我是直接用的 ArchLinux 的network服务连网的,根本不需要 NetworkManager 掺和,可是自己要用 Empathy,而它奇迹般地依赖 NetworkManager。。。虽然试了下强制卸载,最后只成功pacman -Rdd几个其它的包,没能在保证 Empathy 能用的前提下干掉 NetworkManager,心中多有不甘。于是开始打 gnome-sound-applet 的主意。

gnome-sound-applet 这东西是 gnome-control-center 的一部分,其依赖了 15M 左右的奇怪 GNOME 组件。这个 applet 也很鸡肋,本来是显示和调节音量用的,结果黑黑的图标在我的灰色 Awesome 面板上并不容易找到,花了良久才习惯。另外就是,该图标本身不提供任何信息,查看音量时需要把鼠标悬停过去,心中多有不爽。好在今天这些问题一并解决了。

参考来源是 Awesome Wiki 的这个页面,不过这里的代码太老了,不能用,自己参照rc.lua的其它部分以及 wiki 和 reference 修改之后才能用。最终的效果是这样子的:

Awesome widgets 截图

你应该很容易能猜到最右边的就是音量控制了,因为它前边有个八分音符符号“𝅘𝅥𝅮”。鼠标操作很简单:单击切换静音,上下滚动调节音量。静音时百分号会被红色的“M”取代。

贴代码:

-- {{{2 Volume Control
volume_cardid  = 0
volume_channel = "Master"
function volume (mode, widget)
  if mode == "update" then
    local fd = io.popen("amixer -c " .. volume_cardid .. " -- sget " .. volume_channel)
    local status = fd:read("*all")
    fd:close()

    local volume = string.match(status, "(%d?%d?%d)%%")
    volume = string.format("% 3d", volume)

    status = string.match(status, "%[(o[^%]]*)%]")

    if string.find(status, "on", 1, true) then
      volume = '𝅘𝅥𝅮' .. volume .. "%"
    else
      volume = '𝅘𝅥𝅮' .. volume .. '<span color="red">M</span>'
    end
    widget.text = volume
  elseif mode == "up" then
    io.popen("amixer -q -c " .. volume_cardid .. " sset " .. volume_channel .. " 5%+"):read("*all")
    volume("update", widget)
  elseif mode == "down" then
    io.popen("amixer -q -c " .. volume_cardid .. " sset " .. volume_channel .. " 5%-"):read("*all")
    volume("update", widget)
  else
    io.popen("amixer -c " .. volume_cardid .. " sset " .. volume_channel .. " toggle"):read("*all")
    volume("update", widget)
  end
end
volume_clock = timer({ timeout = 10 })
volume_clock:add_signal("timeout", function () volume("update", tb_volume) end)
volume_clock:start()

tb_volume = widget({ type = "textbox", name = "tb_volume", align = "right" })
tb_volume.width = 35
tb_volume:buttons(awful.util.table.join(
  awful.button({ }, 4, function () volume("up", tb_volume) end),
  awful.button({ }, 5, function () volume("down", tb_volume) end),
  awful.button({ }, 1, function () volume("mute", tb_volume) end)
))
volume("update", tb_volume)

记得把 tb_volume 加到 wibox 里去。

这里是我的整个 Awesome 配置。

2013年3月11日更新:Awesome 3.5 版本语法变化较大,请到我的 github 上查看相关代码。