Linux下用窗口管理器为 Compton 配置自定义快捷键
核心原理
i3 与 Sway 的配置示例
# ~/.config/i3/config 或 ~/.config/sway/config
# 切换 Compton(先杀旧进程,再以 0.5 透明度启动)
bindsym $mod+Shift+t exec --no-startup-id bash -lc ' \
pkill -x compton 2>/dev/null; \
compton --config ~/.config/compton/compton.conf --backend glx --opacity 0.5 &'
# 可选:单独绑定“暂停/恢复”或“重开”
bindsym $mod+Shift+r exec --no-startup-id killall -USR1 compton # 若你在 compton.conf 中启用了信号控制
bindsym $mod+Shift+s exec --no-startup-id compton --config ~/.config/compton/compton.conf --backend glx --shadow false
Awesome WM 的配置示例
-- ~/.config/awesome/rc.lua
awful.keyboard.append_global_keybindings({
-- Alt + T:切换 Compton(杀旧进程后启动)
awful.key({ "Mod1" }, "t", function()
awful.spawn.with_shell("pkill -x compton 2>/dev/null; compton --config ~/.config/compton/compton.conf --backend glx --opacity 0.5 &")
end, { description = "toggle compton", group = "launcher" }),
})
进阶用法与注意事项