不使用 ccsm 的多个工作区壁纸

use*_*340 4 wallpaper unity workspaces ccsm budgie

有没有办法在不使用 CCSM 的情况下为每个工作区设置不同的背景?我读过一些恐怖故事,如果可能的话,我宁愿避免它。我正在使用 Raring Ringtail (13.04)

Jac*_*ijm 5

在不使用 ccsm 的情况下在不同的工作区拥有不同的壁纸

下面的脚本使用 compiz 设置管理器,但它假定:

  • python3 已安装(如果没有让我知道)
  • wmctrl已安装(以获取工作区上的数据)。您可能需要安装它:sudo apt-get install wmctrl

无论工作区的数量如何,它都可以工作;它计算工作区的列数和当前工作区的行数,并为该(当前)工作区设置用户定义的墙纸。
脚本启动后,只需切换到不同的工作区并以“正常”(GUI)方式设置壁纸。该脚本在它创建的一个小文件中跟踪每个工作区的墙纸。这不会导致任何性能延迟,因为文件仅在脚本启动时或用户更改每个工作区的壁纸时才会读取。

在此处输入图片说明

剧本

#!/usr/bin/env python3

import subprocess
import time
import os

key1 = "gsettings set org.gnome.desktop.background picture-uri "
key2 = "gsettings get org.gnome.desktop.background picture-uri"

def write_wspaces(file, current):
    with open(file, "wt") as wt:
        wt.write(current)

def read_wspaces(file):
    with open(file) as src:
        return src.read().strip()

def get_info(command):
    return subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")

def get_currwallpaper():
    return get_info(key2).replace("file://", "").strip()

# get resolution
output = get_info("xrandr").split(); idf = output.index("current")
res = (int(output[idf+1]), int(output[idf+3].replace(",", "")))

def calculate_geometry():
    # get viewport data
    vp = get_info("wmctrl -d").split(" ")
    span = vp[4].split("x"), vp[7].split(",")
    # calculate number of (horizontal) viewports
    n_vps_hor = int(int(span[0][0])/int(res[0]))
    n_vps_vert = int(int(span[0][2])/int(res[1]))
    n_wspaces = int(n_vps_hor)*int(n_vps_vert)
    # calculate current viewport
    curr_vp_hor = int((int(span[1][0])/int(res[0]))+1)
    curr_vp_vert = int((int(span[1][3])/int(res[1]))+1)
    return ((curr_vp_vert-1)*n_vps_hor)+curr_vp_hor, n_wspaces

home = os.environ["HOME"]
wspaces = home+"/"+".config/wall_wspaces"
if not os.path.exists(wspaces):
    os.makedirs(wspaces)
if not os.path.exists(wspaces+"/wspaces.txt"):
    current = get_currwallpaper().replace("'", "")
    writelist = []; [writelist.append(current) for i in range(calculate_geometry()[1])]
    write_wspaces(wspaces+"/wspaces.txt", str(writelist))
wall_list = eval(read_wspaces(wspaces+"/wspaces.txt"))

while True:
    curr_vp1 = calculate_geometry()[0]; currwallpaper1 = get_currwallpaper()
    time.sleep(2)
    curr_vp2 = calculate_geometry()[0]; currwallpaper2 = get_currwallpaper()
    if curr_vp1 != curr_vp2:
        command = key1+"file://"+str(wall_list[curr_vp2-1])
        subprocess.Popen(["/bin/bash", "-c", command])
    elif currwallpaper1 != currwallpaper2:
        wall_list = eval(read_wspaces(wspaces+"/wspaces.txt"))
        wall_list[int(curr_vp2)-1] = currwallpaper2
        write_wspaces(wspaces+"/wspaces.txt", str(wall_list))
    else:
        pass
Run Code Online (Sandbox Code Playgroud)

如何使用

只需将脚本复制到一个空文件中,将其另存为workspace_walls.py并通过以下命令运行它:

python3 /path/to/workspace_walls.py
Run Code Online (Sandbox Code Playgroud)

如果它如您所愿,请将其添加到您的启动应用程序中:Dash > Startup Applications > Add


编辑:

下面的脚本的完全重写版,模型这一块

脚本(有一些细微差别)+ GUI 也可用作ppa

在此处输入图片说明

sudo add-apt-repository ppa:vlijm/wswitcher
sudo apt-get update
sudo apt-get install wswitcher
Run Code Online (Sandbox Code Playgroud)
python3 /path/to/workspace_walls.py
Run Code Online (Sandbox Code Playgroud)

现在支持 Budgie

从 ppa 安装时,于 2017 年 7 月 21 日为 Zesty 添加了对 Budgie 的支持(见上文)

在此处输入图片说明