diff options
-rw-r--r-- | xmu.go | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -13,23 +13,13 @@ import ( This change allows us to avoid as many round-trips as possible. */ -func tryChildren(c *xgob.Connection, parent xproto.Window) xproto.Window { +func tryChildren(c *xgob.Connection, children []xproto.Window) xproto.Window { queryCookies := make([]chan xproto.QueryTreeReply, 0) propCookies := make([]chan xproto.GetPropertyReply, 0) state := atom.Atom(c, "WM_STATE") - queryCookies = append(queryCookies, xproto.QueryTree(c, parent)) - c.Flush() - - children := make([]xproto.Window, 0) - for { - children = children[:0] - for _, cookie := range queryCookies { - children = append(children, (<-cookie).Children...) - } - if len(children) == 0 { break } @@ -49,17 +39,29 @@ func tryChildren(c *xgob.Connection, parent xproto.Window) xproto.Window { return children[i] } } + + children = children[:0] + for _, cookie := range queryCookies { + children = append(children, (<-cookie).Children...) + } + } - return parent + return 0 } func ClientWindow(c *xgob.Connection, win xproto.Window) xproto.Window { stateCookie := xproto.GetProperty(c, false, win, atom.Atom(c, "WM_STATE"), xproto.Atom(0), 0, 0) + treeCookie := xproto.QueryTree(c, win) c.Flush() state := <- stateCookie if state.Error != nil && state.Type != xproto.Atom(0) { return win } - - return tryChildren(c, win) + + tree := <- treeCookie + rv := tryChildren(c, tree.Children) + if rv == 0 { + return win + } + return rv } |