summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Harris <pharris@opentext.com>2011-01-07 13:21:16 -0500
committerPeter Harris <pharris@opentext.com>2011-01-07 13:55:47 -0500
commit8db1d9a12e7ed59eca6a926464f7da9260e8eda5 (patch)
tree80ceb02874743ef85f7291846421055c5a87571d
parentd0fc38da09ec5790bbbb34849e73e93830cf2df3 (diff)
Trim one round-trip out of xmu.ClientWindow
-rw-r--r--xmu.go30
1 files 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
}