有没有办法不使用 CCSM 为每个工作区设置不同的背景?我读过一些恐怖故事,如果可能的话,我宁愿避免这样做。我正在使用 Raring Ringtail (13.04)
答案1
不使用 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
如何使用
只需将脚本复制到一个空文件中,将其保存为workspace_walls.py
并通过以下命令运行它:
python3 /path/to/workspace_walls.py
如果它按你喜欢的方式工作,请将其添加到你的启动应用程序中:Dash > 启动应用程序 > 添加
编辑:
下面是完全重写的脚本版本,以这个。
该脚本(有一些细微的差别)+ GUI 也可以作为以下形式使用ppa
:
sudo add-apt-repository ppa:vlijm/wswitcher
sudo apt-get update
sudo apt-get install wswitcher
#!/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
2017 年 7 月 21 日,Zesty 从 ppa 安装时添加了对 Budgie 的支持(见上文)