From 8db1d9a12e7ed59eca6a926464f7da9260e8eda5 Mon Sep 17 00:00:00 2001 From: Peter Harris Date: Fri, 7 Jan 2011 13:21:16 -0500 Subject: Trim one round-trip out of xmu.ClientWindow --- xmu.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/xmu.go b/xmu.go index bc2bf3e..d7a6a13 100644 --- a/xmu.go +++ b/xmu.go @@ -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 } -- cgit v1.2.3