'X11 application to capture textfield focus

I am trying to write an application to show a popup whenever a user clicks on a textfield in any window. With the FocusIn event I was able to capture window focus, but not the textfield focus. Is it feasible to capture textfield focus with X11? If no, what alternates do I have, to capture textfield focus and maybe get properties of the textfield if possible?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source