3

我将创建一个 Python 脚本来搜索具有特定标题的窗口并将其置于顶部。我在当前工作区找到了如何做到这一点: http ://ubuntuforums.org/showthread.php?t=1254376

但我想在所有工作区都这样做。我该怎么做?

4

2 回答 2

1

老问题,但我遇到了同样的问题。答案是要获取所有工作区上的窗口列表,您不应该测试窗口是否可见(删除“attrs.map_state == X.IsViewable”部分)。

display = Display()
root = display.screen().root
winid_list = root.get_full_property(self.NET_CLIENT_LIST_ATOM,
                                            X.AnyPropertyType).value
for winid in winid_list:
    win = self.display.create_resource_object('window', winid)
    transient_for = win.get_wm_transient_for()
    wmname = win.get_wm_name()
    if transient_for == None:
        if wmname != None and name in wmname:
            break
于 2013-11-15T17:02:47.847 回答
0

代码在查询树中搜索窗口并获取窗口对象,该对象稍后可用于获取查询所需的属性:

disp = Display() 
root = disp.screen().root    
children = root.query_tree().children    
for win in children:
    try:
        WinName = getProp(disp,win,'NAME') # or win.get_wm_name()
        PIDs = getProp(disp,win,'PID')
        WinPID = newPIDs[0]

        if WinName and WinName == DESIRED_NAME:
            print("found the window with pid: {} winName: {}  winId: {}".format(pid, newWinName,win.id))
            # Code to bringToTop
        print

    except Xlib.error.BadWindow:
        print("BadWindow error")


def getProp(disp,win, prop):
    p = win.get_full_property(disp.intern_atom('_NET_WM_' + prop), 0)
    return [None] if (p is None) else p.value
于 2019-01-03T08:23:13.657 回答