如何从命令行更改 Compiz 工作区名称?

如何从命令行更改 Compiz 工作区名称?

我正在使用 Compiz Workspace Naming 插件,现在我可以通过 ccsm 更改工作区名称。但是,我希望能够从命令行更改活动工作区的名称,而无需启动 ccsm 并浏览菜单。

我以前能够使用 wnck 和我的 bashrc 中的这个函数来做到这一点:

function wsname {
  python -c "import wnck; s = wnck.screen_get_default(); s.force_update();\
    s.get_active_workspace().change_name('$*')"
}

答案1

我发现可以使用以下方法设置名称

gsettings set org.compiz.workspacenames:/org/compiz/profiles/unity/plugins/workspacenames/ names [\"Name1\",\"Name3\"]
gsettings set org.compiz.workspacenames:/org/compiz/profiles/unity/plugins/workspacenames/ viewports [1,3]

所以我编写了一个 Python 脚本来实现我想要的功能:

#!/usr/bin/python
import sys
from subprocess import Popen, PIPE

getoutput = lambda x: Popen(x, stdout=PIPE).communicate()[0]
listIntOutput = lambda x: "[%s]" % ",".join([str(i) for i in x])
listStrOutput = lambda x: "[%s]" % ",".join(["\"%s\"" % s for s in x])
SCHEMA = \
  "org.compiz.workspacenames:/org/compiz/profiles/unity/plugins/workspacenames/"

if len(sys.argv) < 2:
  name = ""
else:
  name = " ".join(sys.argv[1:])

# get the position of the current workspace
ws = list(int(i.strip(",")) for i in  getoutput(("xprop", "-root",
    "-notype", "_NET_DESKTOP_VIEWPORT")).split()[-2:])
# get the number of horizontal and vertical workspaces
hsize = int(getoutput(("gconftool",
    "--get", "/apps/compiz-1/general/screen0/options/hsize")))
vsize = int(getoutput(("gconftool",
    "--get", "/apps/compiz-1/general/screen0/options/vsize")))
# get the dimentions of a single workspace
x, y = list(int(i) for i in getoutput(("xwininfo", "-root",
    "-stats", )).split("geometry ")[1].split("+")[0].split("x"))
# enumerate workspaces
workspaces, n = [], 0
for j in range(vsize):
    for i in range(hsize):
        workspaces.append([n, [x*i, y*j, ], ])
        n += 1
# Get the (1-indexed) viewport #
vp = list(i for i in workspaces if i[1] == ws)[0][0] + 1

# Get the current named viewports
vps = eval(getoutput(("gsettings", "get", SCHEMA, "viewports")));
names = eval(getoutput(("gsettings", "get", SCHEMA, "names")));

if vp not in vps:
  # If this viewport is not yet named, then just append it.
  vps.append(vp)
  names.append(name)
  getoutput(("gsettings", "set", SCHEMA, "viewports", listIntOutput(vps)));
  getoutput(("gsettings", "set", SCHEMA, "names", listStrOutput(names)));
else:
  # Rename the viewport.
  index = vps.index(vp)
  names[index] = name
  getoutput(("gsettings", "set", SCHEMA, "names", listStrOutput(names)));

根据此脚本:https://askubuntu.com/a/17492/284331

我遇到的一个警告是

gconftool --get /apps/compiz-1/general/screen0/options/hsize # and vsize

没有返回我在 ccsm 中设置的正确值,因此我必须手动单独设置它们才能使脚本正常工作。

gconftool --set /apps/compiz-1/general/screen0/options/hsize #
gconftool --set /apps/compiz-1/general/screen0/options/vsize #

相关内容