如何在 MATE 中为每个工作区设置不同的背景

如何在 MATE 中为每个工作区设置不同的背景

I know this has been answered before but that solution doesn't work on Ubuntu MATE. Anyway to achieve this on MATE?

Output of wmctrl -d:

$ wmctrl -d
0  * DG: 1366x768  VP: 0,0  WA: 0,25 1366x719  Workspace 1
1  - DG: 1366x768  VP: N/A  WA: 0,25 1366x719  Workspace 2
2  - DG: 1366x768  VP: N/A  WA: 0,25 1366x719  Workspace 3
3  - DG: 1366x768  VP: N/A  WA: 0,25 1366x719  Workspace 4

Output of $ echo $DESKTOP_SESSION:

$ echo $DESKTOP_SESSION
mate

Original solution that I tried and that didn't work for me:
Is it possible to have a different background for each workspace?

答案1

Although I could not test it, due to the fact that I don't have Mate avaialble atm, looking at the output of wmctrl -d, and given the fact that wallpapers on Mate are obviously set with the same gsettings command, I see no reason why it should not work.

The script

下面的脚本是这个,以及其中一段摘录我推送到了 Launchpad。事实上,这个不适用于 Mate,因为我在其中添加了会话检查,无论是针对 Unity 还是 Budgie。

如果您能确认下面的脚本在 Mate 上运行,我可能会编辑 ppa 版本以包含 Mate。

剧本

#!/usr/bin/env python3
import subprocess    
import os
import time

try:
    os.mkdir(os.path.join(os.environ["HOME"], ".config/wswitcher"))
except FileExistsError:
    pass

workspace_data = os.environ["HOME"]+"/.config/wswitcher/wallpaper_data_"
key = [
    "gsettings get ",
    "gsettings set ",
    "org.gnome.desktop.background picture-uri",
    ]

def getwall():
    return subprocess.check_output(
        ["/bin/bash", "-c", key[0]+key[2]]
        ).decode("utf-8").strip()

def get_res():
    # get resolution
    xr = subprocess.check_output(["xrandr"]).decode("utf-8").split()
    pos = xr.index("current")
    return [int(xr[pos+1]), int(xr[pos+3].replace(",", "") )]

def current_ws():
    # get the current workspace
    wsdata = subprocess.check_output(["wmctrl", "-d"]).decode("utf-8").splitlines()
    return [l.split()[0] for l in wsdata if "*" in l][0]

def wswitcher(curr_ws1, currwall1):
    while True:
        time.sleep(1)
        currwall2 = getwall()
        curr_ws2 = current_ws()
        datafile = workspace_data+curr_ws2
        if curr_ws2 == curr_ws1:
            if currwall2 != currwall1:
                open(datafile, "wt").write(currwall2)
        else:
            if not os.path.exists(datafile):
                open(datafile, "wt").write(currwall2)
            else:
                curr_set = open(datafile).read()
                command = key[1]+key[2]+' "'+str(curr_set)+'"'
                subprocess.Popen(["/bin/bash", "-c", command])
        curr_ws1 = curr_ws2
        currwall1 = getwall()

curr_ws1 = current_ws(); currwall1 = getwall()
wswitcher(curr_ws1, currwall1)

如何使用

  1. 将脚本复制到空文件中
  2. 另存为wallswitcher.py
  3. 通过命令测试运行:

    python3 /path/to/wallswitcher.py
    
  4. 然后按照演示开始设置壁纸这里
  5. 如果一切正常,将其添加到启动应用程序:

    /bin/bash -c "sleep 10 && /path/to/wallswitcher.py
    

答案2

Jacob Vlijm 提出的解决方案在我的 Mate 上运行良好,只要我在脚本中更改org.gnome.desktop.background picture-uri为(找到的信息org.mate.background picture-filename这里)。

相关内容