Proper algorithm for XQueryTree to get in z order

雨燕双飞 提交于 2019-12-25 03:14:09

问题


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: []

  1. I start with root window lets call this A, I push this to start of array. So [A]
  2. XQueryTree gives me a list of a children lets call them B, C, D
  3. I push first child to start of array so it is now [B, A]
  4. It XQueryTree B and finds children B1, B2
  5. It pushes B1 to start so now: [B1, B, A]
  6. XQuertyTree on B1 shows no children so continues
  7. It pushes B2 so now [B2, B1, B, A]
  8. It XqueryTree B2 and it finds no children, so it continues
  9. It pushes C to start so now [C, B2, B1, B, A]
  10. It XQueryTree C and finds no children so continue
  11. It pushes D to start so now [D, C, B2, B1, B, A]
  12. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!