我可以在 Awesome WM 中为不同的工作区(标签)设置不同的背景吗?

Jon*_*han 8 wallpaper awesome background

我希望能够为 Awesome WM 中的不同标签设置不同的背景。有没有办法做到这一点?

小智 8

您可以在 ~/.config/awesome/rc.lua 文件中添加一些代码,只要您更改标签,这些代码就会更改桌面墙纸。从技术上讲,它会将壁纸设置为您最近选择的标签(很棒,您可以同时选择多个标签)。

如果您还没有该文件,则将系统范围的超棒配置文件复制到该位置:

$ mkdir -p ~/.config/awesome
$ cp /etc/xdg/awesome/rc.lua ~/.config/awesome
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu 11.10 的 rc.lua 中,有一个部分创建了标签,如下所示:

-- {{{ Tags
-- {{{ Define a tag table which hold all screen tags.
[... code that creates default tags ...]
-- }}}
Run Code Online (Sandbox Code Playgroud)

在该部分之后,我添加了以下代码:

-- {{{ Tag Wallpapers
for s = 1, screen.count() do
    for t = 1, 9 do
        tags[s][t]:add_signal("property::selected", function (tag)
            if not tag.selected then return end
            wallpaper_cmd = "awsetbg /home/user/Pictures/wallpaper" .. t .. ".png"
            awful.util.spawn(wallpaper_cmd)
        end)
    end
end
-- }}}
Run Code Online (Sandbox Code Playgroud)

将“/home/user/Pictures”替换为您要存储壁纸的位置。它将使用文件“wallpaper1.png”作为第一个标签,“wallpaper2.png”作为第二个标签,等等。请注意,这里假设您有 9 个标签。如果您有不同的数字,请调整内部 for 循环。


awsetbg 要求您安装一些能够更改壁纸的程序。例如,'feh' 或 'imagemagick' 包。您可以在 awsetbg 脚本 (/usr/bin/awsetbg) 中找到受支持程序的列表:

wpsetters="${wpsetters:=Esetroot habak feh hsetroot chbg fvwm-root imlibsetroot display qiv xv xsri xli xsetbg wmsetbg xsetroot}"
Run Code Online (Sandbox Code Playgroud)

我的 Ubuntu 默认安装的唯一一个是 xsetroot,但我相信该程序只支持位图图像。我已经安装了 imagemagick(提供了“显示”命令),因此它可以处理您能想象到的大多数格式。;)


如果您使用的是 gnome/awesome 混合桌面(使用带有 awesome 作为窗口管理器的 gnome)并且没有禁用 nautilus 的桌面管理,您可能必须使用 gnome 设置墙纸的方法而不是 awsetbg。这是因为 nautilus 管理桌面并可能覆盖您的设置。对于 11.10,您需要将 awsetbg 命令更改为:

gsettings set org.gnome.desktop.background picture-uri file:///home/user/Pictures/wallpaper1.png
Run Code Online (Sandbox Code Playgroud)

gsettings 是一种新方法,对于较旧的 Ubuntu 版本(不确定它在多久之前更改过),您应该使用 gconftool-2:

gconftool-2 --set /desktop/gnome/background/picture_filename --type string file:///home/user/Pictures/wallpaper1.png
Run Code Online (Sandbox Code Playgroud)