[comp.windows.x] Reparenting, and Save sets

carroll@cs.uiuc.edu (Alan M. Carroll) (04/18/91)

I have an application that is reparenting Epoch screens, and I'm
having some problems with it.

I'm running mwm, Motif 1.1, X11R4, on a Sparc IPC with SunOS 4.1.1.

The first problem is that if the target window is mapped, I can't
reparent it. If I make sure that it is unmapped before my application
tries to reparent it, it works. The target window is a toplevel window
before the reparenting. Also, if it's mapped and I try to reparent it,
it gets unmapped, but not reparented. Doing an unmap right before the
reparent doesn't work either, although it also unmaps the target
window.

Second, when my application exits, the target window is destroyed.
I've tried using XAddToSaveSet() and XChangeSaveSet(), but they don't
seem to have any effect. Do save sets actually work? This happens with
both XCloseDisplay() and XtCloseDisplay().

-- 
Alan M. Carroll          <-- Another victim of applied metaphysics
Epoch Development Team   
Urbana Il.               "I hate shopping with the reality-impaired" - Susan

Stuart.Marks@eng.sun.COM (Stuart Marks) (04/18/91)

    I'm running mwm, Motif 1.1, X11R4, on a Sparc IPC with SunOS 4.1.1.

    The first problem is that if the target window is mapped, I can't
    reparent it. If I make sure that it is unmapped before my application
    tries to reparent it, it works. The target window is a toplevel window
    before the reparenting. Also, if it's mapped and I try to reparent it,
    it gets unmapped, but not reparented. Doing an unmap right before the
    reparent doesn't work either, although it also unmaps the target
    window.

I suspect you're getting into a fight with the window manager.  This is a
bad idea, as window managers generally win. :-)

When you reparent a mapped window, the semantics are that it is first
unmapped (as if by an UnmapWindow request), reparented, and then remapped.
The initial unmapping generates an UnmapNotify event to the window manager,
which probably thinks that the window is going away.  In response to this,
the window manager reparents the window back to the root.  This happens
after you've reparented the target window, so it ends up as a child of the
root window.

If you unmap and then reparent right away, the same thing happens.  The
window manager gets in after the fact and reparents the target window back
to the root.

(I'm basing these comments on my general knowledge of reparenting window
managers.  I haven't looked at the mwm specifically, but I suspect it
behaves as I'm describing.  You will probably also get similar behavior
under olwm.)

You might argue that window managers should handle the case where a window
is reparented away from them.  The ICCCM states that "clients that want to
reparent their top-level windows should do so only when they have their
original parents."  This means that you shouldn't try reparenting the
window until it's been reparented back to the root.  One way to do this is
to select for StructureNotify on the target window, unmap it [actually, use
XWithdrawWindow()], wait the ReparentNotify indicating it's back on the
root, and then reparent it to your application.  You need only do this if
the target window's parent is not the root, of course.  You should make
sure to use XWithdrawWindow().  The target window might be iconic, and
XWithdrawWindow() is the proper way to inform the window manager that the
window no longer needs to be managed.

    Second, when my application exits, the target window is destroyed.
    I've tried using XAddToSaveSet() and XChangeSaveSet(), but they don't
    seem to have any effect. Do save sets actually work? This happens with
    both XCloseDisplay() and XtCloseDisplay().

Sorry, I can't help with this one.  Save-sets generally do work; I'm not
aware of any problems with them that might cause the behavior you're
seeing.

s'marks

Stuart W. Marks			ARPA: smarks@eng.sun.com
Windows & Graphics Software	UUCP: sun!smarks
Sun Microsystems, Inc.