Answers:
如果您正在使用Compiz的,这将是一个有点困难。
编辑:这现在无论有没有compiz都可以使用,最后...
我编写了一个“小” python脚本来做到这一点:
#!/usr/bin/python
from subprocess import Popen, PIPE
getoutput = lambda x: Popen(x, stdout=PIPE).communicate()[0]
compiz_running = list(i for i in getoutput(("ps", "-aef", )).split("\n")
if "compiz --replace" in i and not "grep" in i) != []
if compiz_running:
# 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/general/screen0/options/hsize", )))
vsize = int(getoutput(("gconftool",
"--get", "/apps/compiz/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
print list(i for i in workspaces if i[1] == ws)[0][0]
# if compiz is not running
else: # this code via @DoR
print getoutput(("xdotool", "get_desktop", )).strip()
将其保存在某处并将其标记为可执行文件。这只会输出介于0
和之间的数量的工作区。
这是枚举的样子:
+---+---+
| 0 | 1 |
+---+---+
| 2 | 3 |
+---+---+
您必须安装xdotool 才能在compiz被禁用的情况下正常工作。
无需安装任何工具,如果您正在使用metacity,则可以使用以下命令:
python -c "import wnck; s=wnck.screen_get_default(); s.force_update(); w=s.get_active_workspace(); w_num=w.get_number(); print(w_num);" 2>/dev/null