Computers are *fast*. It turns out that simply recursively walking
down all children is fast enough for most cases. It's a complicated
walk, but it's entirely doable. You can see the code for the walk
here:
https://git.gnome.org/browse/gtk+/tree/gdk/gdkwindow.c#n7247
More complex data structures, like a map of pixel to object, would
take up too much memory, or require too much effort to suitably parse.
The simple and brute force solution often works well, because you'll
never have more than 100 visible children in the worst case, and 100
is not a big enough number to optimize for.