It turns out we really have to ignore grab/ungrab events or we'll
report double crossing events when we grab or ungrab.
However, we also can't ignore crossing events from grabs from other clients
as that leads to missed enter/leave events on e.g. alt-tab in metacity.
Fortunately we now track grabs very precisely, so we know with certainty
whether we have a grab at the time (serial) of the native crossing events,
and only if we do we ignore them.
If we get crossing events with subwindow unexpectedly being NULL
that means there is a native subwindow that gdk doesn't know about.
We track these and forward them, with the correct virtual window
events inbetween.
This is important to get right, as metacity uses gdk for the frame
windows, but gdk doesn't know about the client windows reparented
into the frame.
For instance if we grab the pointer and then check if its grabbed
so that we know to ungrab we don't care that the grab is not
yet active, so report the steady state (i.e. the last grab)
Having GDK_WINDOW_CHILD windows with root as the parent apparently works,
and metacity uses it. The current gdk_window_get_toplevel() returns the
root window for that, which is wrong, so we check that explicitly.
This causes all sorts of weirdness with pointer_over_window
being the rootwindow and then crashing gdk_window_get_toplevel() later.
With this metacity stops crashing madly.
To avoid drawing the window background of other windows in the area
where the window was we set the bg to none recursively. However, this
is quite costly it the moved window has many siblings. Furthermore, it
is uncommon that siblings overlap, so this cost has little gain.
So, we only set bg None on the parent, which means that there will
be some more flicker in the uncommon case of overlapping siblings.
These are sent when someone else grabs the pointer, and we don't
want to miss these expose events. For instance, we missed enter
and leave events on alt-tab.
There were some issues with these wrt out-of-sync grab information
in the client, but that should now be handled. So, it should work
or at least be fixable if we find some bug.
After a successful grab/ungrab we wait for an xserver
roundtrip until we change the tracked grab in GdkDisplay.
This way that data is always up-to-date wrt events comming in.