Re: How to fixate a window on another window?




On Dec 30, 2005, at 11:07 AM, Jörn Reder wrote:

I like to have a child window on my application window which has a fixed
position relative to the button which opens it (somewhat like a Popup
menu). It should look like this:

    +-------------------------------------------------+
    | Main App Window                                 |
    |                                                 |
    |              +----------------------------------+
    |              | Child Window                     |
    |              |                                  |
    |              +-------------------------+--------+
    |                                        | Button |
    +----------------------------------------+--------+

The child window should overlap other widgets in the main window and can be closed again on user action. If the main window is resized, the child
window should keep attached at the right side and above the button.

What's the easiest way to accomplish that?


The most obvious option is to create a GTK_WINDOW_POPUP window with GDK_GRAVITY_SOUTH_EAST, float it above the main window, and use gtk_window_move() to track its location in the main window's configure-event. However, this doesn't really work out that well. My window manager refused to honor set_transient_for() for the popup window, so i had to call $popup->window->raise every time i relocated it. This resulted in some unpleasant flashing and move lagging.

A slightly sneakier solution is to use an actual widget as a fake popup, by using manual absolute position layout. We just tell the widget that its parent is the toplevel window, and then update the widget's position from the toplevel window's size-allocate as though we were implementing a fixed-position layout container. The advantage here is that the "popup" tracks the toplevel's position perfectly during moves because the X server moves the GdkWindow for us, removing all of the lag and z-order problems of the separate window solution. Also, using size-allocate is a little easier. ;-)

In both solutions, the keyboard focus is an interesting issue. The code i implemented ignores the "popup"'s keyboard focus altogether -- it doesn't get focus when toggled visible, and doesn't get inserted into the toplevel's focus chain. You didn't mention whether you wanted to have actual interactive widgets in your popup, or whether it was just for information display. I leave that as an exercise for you. ;-)

Attached is a 100-line prototype that implements the popup in a quick and dirty procedural style.

Attachment: popup-tracker.pl
Description: Text Data



--
Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we.
  -- President George W. Bush



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]