The code in question is similar to this SO topic: Get X11 window caption height. The link points to answer with Xlib code. The idea is to get window properties,
Xlib