问题
I was trying to get all the windows in z order but the algorithm for XQueryTree is confusing me. This is what I did:
my collection array: []
- I start with root window lets call this
A
, I push this to start of array. So[A]
- XQueryTree gives me a list of a children lets call them B, C, D
- I push first child to start of array so it is now
[B, A]
- It XQueryTree
B
and finds childrenB1, B2
- It pushes B1 to start so now:
[B1, B, A]
- XQuertyTree on B1 shows no children so continues
- It pushes
B2
so now[B2, B1, B, A]
- It XqueryTree B2 and it finds no children, so it continues
- It pushes
C
to start so now[C, B2, B1, B, A]
- It XQueryTree
C
and finds no children so continue - It pushes
D
to start so now[D, C, B2, B1, B, A]
- It XquertyTree
D
and finds no children
I was debating this myself as I was writing the algo, is this the right algorigthm in z order from top most to bottom most? Its not seeming right when I implement it with my code below. D
should be the top most in z order and A
the bottom most.
This is my code right now:
var rezWinArr = [];
var processWin = function(w) {
rezWinArr.splice(0, 0, thisWin); // puts the win into the array at position 0
var rez_XQ = ostypes.API('XQueryTree')(ostypes.HELPER.cachedXOpenDisplay(), w, xqRoot.address(), xqParent.address(), xqChildArr.address(), nChilds.address()); // interesting note about XQueryTree and workspaces: "The problem with this approach is that it will only return windows on the same virtual desktop. In the case of multiple virtual desktops, windows on other virtual desktops will be ignored." source: http://www.experts-exchange.com/Programming/System/Q_21443252.html
var jsNC = parseInt(cutils.jscGetDeepest(nChilds));
if (jsNC > 0) {
var jsChildArr = ctypes.cast(xqChildArr, ostypes.TYPE.Window.array(jsNC).ptr).contents;
for (var i = 0; i < jsNC; i++) {
var wChild = jsChildArr[i];
processWin(wChild);
}
ostypes.API('XFree')(xqChildArr);
}
}
processWin(ostypes.HELPER.cachedDefaultRootWindow());
Thanks!
来源:https://stackoverflow.com/questions/31888887/proper-algorithm-for-xquerytree-to-get-in-z-order