首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从命令行更改Compiz工作区名称?

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

Ask Ubuntu用户
提问于 2014-05-22 19:57:32
回答 1查看 871关注 0票数 2

我正在使用命名插件,现在我可以通过ccsm更改工作区名称。但是,我希望能够从命令行更改活动工作区的名称,而不必启动ccsm并导航菜单。

我以前可以使用wnck来完成这个任务,而这个函数在bashrc中是:

代码语言:javascript
复制
function wsname {
  python -c "import wnck; s = wnck.screen_get_default(); s.force_update();\
    s.get_active_workspace().change_name('$*')"
}
EN

回答 1

Ask Ubuntu用户

发布于 2014-05-23 14:32:36

我想出了可以用

代码语言:javascript
复制
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脚本来做我想做的事情:

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

我遇到的一个警告是

代码语言:javascript
复制
gconftool --get /apps/compiz-1/general/screen0/options/hsize # and vsize

没有返回我在ccsm中设置的正确值,所以我必须手动分别设置它们,这样脚本才能工作。

代码语言:javascript
复制
gconftool --set /apps/compiz-1/general/screen0/options/hsize #
gconftool --set /apps/compiz-1/general/screen0/options/vsize #
票数 2
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/470782

复制
相关文章

相似问题

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