我正试图在我的X服务器上找到一个未映射的窗口,以便将它映射回来并发送一些EWMH提示。由于窗口未映射,所以不能使用EWMH直接询问窗口管理器。因此,我试图通过Xlib实现它,但我遇到了问题。整个API对我来说是非常混乱的。
我正在使用Python的Xlib包装器。现在让我们看看下面的Python脚本:
import subprocess
from time import sleep
from ewmh import EWMH
subprocess.Popen(['urxvt']) # Run some program, here it is URXVT terminal.
sleep(1) # Wait until the term is ready, 1 second is really enought time.
ewmh = EWMH() # Python has a lib for EWMH, I use it for simplicity here.
# Get all windows?
windows = ewmh.display.screen().root.query_tree().children
# Print WM_CLASS properties of all windows.
for w in windows: print(w.get_wm_class())脚本的输出是什么?其中一个开放了URXVT终端,如下所示:
None
None
None
None
('xscreensaver', 'XScreenSaver')
('firefox', 'Firefox')
('Toplevel', 'Firefox')
None
('Popup', 'Firefox')
None
('Popup', 'Firefox')
('VIM', 'Vim_xterm')但是,当我运行这个命令并单击打开的终端时:
$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "urxvt", "URxvt"WM_NAME属性也是如此。
最后一个问题是:为什么脚本的输出中没有"URxvt“字符串?
发布于 2015-02-07 19:09:59
没有字符串"urxvt“、"URxvt”的原因是XWindows处于混乱状态。出于某种原因,在我的桌面上,urxvt窗口并不在第一级。
所以我们必须像这样横穿整棵树:
from Xlib.display import Display
def printWindowHierrarchy(window, indent):
children = window.query_tree().children
for w in children:
print(indent, w.get_wm_class())
printWindowHierrarchy(w, indent+'-')
display = Display()
root = display.screen().root
printWindowHierrarchy(root, '-')然后,脚本输出的一行(可能相当长)是:
--- ('urxvt', 'URxvt')https://unix.stackexchange.com/questions/179769
复制相似问题