diff options
author | Peter Harris <pharris@opentext.com> | 2011-01-07 13:21:16 -0500 |
---|---|---|
committer | Peter Harris <pharris@opentext.com> | 2011-01-07 13:55:47 -0500 |
commit | 8db1d9a12e7ed59eca6a926464f7da9260e8eda5 (patch) | |
tree | 80ceb02874743ef85f7291846421055c5a87571d | |
parent | d0fc38da09ec5790bbbb34849e73e93830cf2df3 (diff) |
Trim one round-trip out of xmu.ClientWindow
-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 } |