首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用ccsm的多个工作区壁纸

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

Ask Ubuntu用户
提问于 2013-06-07 23:16:40
回答 1查看 542关注 0票数 4

不使用CCSM,每个工作区有什么不同的背景吗?我读过一些恐怖故事,如果可能的话,我宁愿避免。我用的是拉响环尾(13.04)

EN

回答 1

Ask Ubuntu用户

发布于 2014-12-12 20:55:25

在不同的工作区上有不同的壁纸而不使用ccsm

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

  • 安装了python3 (如果不通知我的话)
  • 安装了wmctrl (以获取工作区上的数据)。您可能需要安装它: sudo apt-get install wmctrl

无论工作区的数量如何,它都可以工作;它计算工作区的列数和当前工作区的行数,并为该(当前)工作区设置用户定义的壁纸。

脚本启动后,只需切换到不同的工作区,并以“普通”(GUI)方式设置壁纸即可。脚本在创建的小文件中跟踪每个工作区的壁纸(S)。这不应导致性能上的任何滞后,因为只有在脚本启动时,或者当用户更改每个工作区的壁纸时,才会读取文件。

脚本

代码语言:javascript
复制
#!/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

如何使用

只需将脚本复制到空文件中,将其保存为workspace_walls.py并通过命令运行:

代码语言:javascript
复制
python3 /path/to/workspace_walls.py

如果它按照您的意愿工作,那么将它添加到您的启动应用程序中:破折号>启动应用程序>添加

编辑:

下面是一个完全重写的脚本版本,用于这一个模型。

脚本(有一些细微的差异)+ GUI也可以作为ppa提供:

代码语言:javascript
复制
sudo add-apt-repository ppa:vlijm/wswitcher
sudo apt-get update
sudo apt-get install wswitcher
代码语言:javascript
复制
#!/usr/bin/env python3
import subprocess    
import os
import time

workspace_data = os.environ["HOME"]+"/.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():
    # get the current viewport
    res = get_res()
    vp_data = subprocess.check_output(
        ["wmctrl", "-d"]
        ).decode("utf-8").split()
    dt = [int(n) for n in vp_data[3].split("x")]
    cols = int(dt[0]/res[0])
    curr_vpdata = [int(n) for n in vp_data[5].split(",")]
    curr_col = int(curr_vpdata[0]/res[0])+1
    curr_row = int(curr_vpdata[1]/res[1])
    return str(curr_col+curr_row*cols)

curr_ws1 = current()
currwall1 = getwall()

while True:
    time.sleep(1)
    currwall2 = getwall()
    # print(currwall2)
    curr_ws2 = current()
    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()

Budgie现在支持

当从ppa安装时,在2017年7月21日增加了对Budgie的支持(见上文)

票数 5
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/305468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档