On Mon, 12 Jul 2004 11:02:05 +0300 Eugen Andronic <[EMAIL PROTECTED]>
babbled:

>  Hello all,
> I'm new to X window programming, so maybe my problem is very simple for many 
> of you. The problem is:
> I have a "stack" of apps running on top of the X. None of them are "stay on 
> top". Let's say the following windows are on the system:
> 
> desktop, x1, x2, ....., xn
> 
> >From the xi window I want to find the main window of the app bellow xi (
> >let's 
> say xi-1) and to give it the focus.
> 
> My attempt was:
>         int root;
>         int parent;
>         unsigned int nchildren;
>         int* children;
>         Display* d;
> 
>         d = XOpenDisplay("");
>         int w = XDefaultRootWindow(d); //w should be the desktop
>         int ret = XQueryTree(d, w, (Window*)&root, (Window*)&parent, 
> (Window**)&children, &nchildren );
> 
> I have the ID of my window and I want to find which is the window imediately 
> bellow it. Following the man of XQueryTree I thought the IDs are from bottom 
> to top but I'm not sure the list is "sorted" from the point of view of "Z" 
> order. 
>       so, my need is ID_bellow_me = Some_Func_To_Find_The_ID();
> 
> and then,
>       XSetInputFocus( d, ID_bellow_me, RevertToNone, CurrentTime );
>         XFree( children );
>         XCloseDisplay(d);    
> 
> Thanks for your help,
> Eugen

first... you are likely running a window manager... this makes your window tree
look different. you don't want to set focus to the window manager BORDER window
- u want to set focus to the client window. remember most window managers
reparent a client window. they may even reparent these "containers" several
times. ie client window in a container, that window in the frame, that frame
(and all frames) in a virtual root and several virtual roots a child of a single
window that is a child of root... this si all possible - and legal. just because
your wm does one thing and has a particular window heirachy does not mean the
next wm will be the same. you should really try and account for ALL possible
setups. let me do a diagram of what you'd see in a simple wm:

        root
       /    \
  wm_frame   \
    /       wm_frame
app_1          \
               app_2


a more complex wm:

        root
       /    \
  wm_frame   \
    /       wm_frame
wm_container    \
  /             wm_container
app_1              \
                  app_2


or a complex wm with a complex virtual root system:

       root
        |
    wm_root_container
    /                \
wm_virtual_root_1    wm_virtual_root_2
 /          \             |        \
wm_frame_1   \        wm_frame_3    \
   /       wm_frame_2      \      wm_frame_4
wm_container    \       wm_container     \
 /             wm_container   \        wm_container
app_1             \         app_3          \
                 app_2                    app4

all these are valid. when you change focus u want to set the focus on the app
windows, not the wm frames, containers and virtual roots. remember also some
apps may be in virtual roots that are off the screen, or not mapped too (the wm
may choose to implement virtual desktops this way).  also remember the wm may
have any number of levels of containering between an app window and the root
window. now what YOU need to do is scan the entire window tree (down to app
window levels only though - not any further down branches there) looking for
client windows (and then common parents - these may be the root window, or
virtual roots). now that you have found common ancestors you now can use the
stacking of the immediate children of these common ancestors to find which
window is immediately below (you may want to use geometry too). you now have to
walk back down the chosen branch of this tree to find the app window and then
set focus to THAT window.

you can determine is something is an app window if it has a WM_STATE property.
also you may want to check if that window is mapped (or its parents) if any
window in this list is unmapped you might want to skip it as its not visible,
also maybe check its geometry to see if its on the screen or not (account for
parent geometry too as the virtual roots may not be positioned at 0,0 and may
not be the full screen in size).

welcome to the can of worms you opened by trying to do things OUTSIDE the set of
windows your app created and controls :)

-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler)    [EMAIL PROTECTED]
熊耳 - 車君 (数田)                  [EMAIL PROTECTED]
Tokyo, Japan (東京 日本)
_______________________________________________
Devel mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/devel

Reply via email to