Tk Source Code

View Ticket
Login
Ticket UUID: 928527
Title: determining if a window has been raised or lowered
Type: RFE Version: None
Submitter: tomdunne Created on: 2004-04-02 20:43:59
Subsystem: 65. Generic Window Operations Assigned To: dkf
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2004-04-05 21:31:24
Resolution: Out of Date Closed By: dkf
    Closed on: 2004-04-05 14:31:24
Description:
I just spent a day try to figure out the following:
I have a main window and multiple other smaller
configuration windows that are open in parallel to the
main window. The following behaviour of the main window
would be good:
* iconize main window -> all config windows disappear
* de-iconize window -> config windows reappear
* move main window -> config windows move also
* lower main window -> config windows lower themselves also
* raise main window -> config windows also raise

The points 1 and 2 can be done (e.g. using the wm group
command). The 3rd point can be done with the help of
the binding to the Configure-event.
But it seems there is no direct way of determining if a
window has explicitly been raised or lowered. (It seems
no explicit event is sent for the event of changing the
stacking order on the X winow system. I verified this
with using /usr/X11R6/bin/xev). 
Two events are sent, though: VisibilityNotify and
Expose. But they are sent in other cases also. 

It seems the only way to determine if a window has been
raised or lowered is to know its index and/or
neighbouring windows in the stacking level list. This
list is attained by (recursively) calling the
XQueryTree function.

I tested the idea and it works well.

my suggestion:

adding a funtion to the winfo command:
  winfo stacklevel $windowid
returns the stacklevel of a window

and
  winfo stacklevel $windowid -get prevneighbour
  winfo stacklevel $windowid -get nextneighbour
returns the window ids of the previous and next neighbours

(calling winfo stacklevel without a windowid could
return the complete list of all window ids...)

I could supply a patch.
User Comments: dkf added on 2004-04-05 21:31:24:
Logged In: YES 
user_id=79902

If you look at the State header in the online version of any
TIP, you can see whether it's in the core or not.  (If it is
Final, it made it!)  I've no idea how PEPs work though.

Glad you're happy that the feature's there though.

tomdunne added on 2004-04-05 18:36:10:
Logged In: YES 
user_id=1005553

of course! sorry
I didn't find wm stackorder in any of my (older)
documentation and I confused the Tk TIP with a Python PEP.
PEPs are just suggestions that don't always make it ...
the wm stackorder is exactly what I requested, nice to know
it's already implemented, a bit annoying that I didn't know
this before hand :-/ my fault sorry, thanks for the comments!

dkf added on 2004-04-05 17:06:02:
Logged In: YES 
user_id=79902

OK, so notification of circulation doesn't work (and not
through any fault of Tk.)  Looks like you'll just have to
examine the output of [wm stackorder], which is defined from
8.4 onwards.

In fact, given that exists, why should this FRQ stay open?

tomdunne added on 2004-04-05 16:25:13:
Logged In: YES 
user_id=1005553

before I posted that's what I thought also. I used the
xevent debugger xev, it didn't register any events except
Expose and VisibilityNotify, no Circulates.
The WM I use is fvwm2. Which has been around for a long time
and behaves well. I can't imagine it not passing/generating
the expected events...

I did some searching concerning the Circulate event.
http://tronche.com/gui/x/xlib/events/window-state-change/circulate.html
To recieve the event the respective StructureNotifyMask bit
has to be set in the  event mask of the window ... I looked
around in the code, seems like  it's always being set ....

I though maybe this has to do with xev, so I tried an xevent
logger written in Python/Tkinter, I got the same results:
only Expose and VisibilityNotify

I don't know why this event isn't "there"...

I just found an older TIP #74 proposing a similar command:
wm stackorder

reading through the tip the following shows up: 
>> ... This would imply binding to the <Circulate> event
under X. While the <Circulate> event is defined in Tk, it
does not seem to actually be delivered by the window
manager. ... <<

oddly the WM was blamed then also, which I just can't really
believe.... well the problem has been around and there is
still no way to get around this difficulty...

The suggestion would unify the different ways of getting
around the difficulty to a single tk call, making it
possible for this to be used on other systems as well
(Windows and Macs).

additional -isabove $wndid and -isbelow $wndid would be easy
to add ...

dkf added on 2004-04-03 04:00:54:
Logged In: YES 
user_id=79902

Wouldn't a Circulate event give you this sort of info?  And
is your WM delivering those correctly?!