I think paulsm4’s advice applice more to individual processes than X11 applications.
In order to do what you want, your window manager must implement the
EWMH standard. From here use the X11 protocol to accomplish what you are trying to do. Otherwise, you will have to write into specific hooks provided by whatever window manager you use.
Since the standard is somewhat terse,
here is a minimal, commented example of a similar use. I suggest you look at the sourcecode of other utilities such as
xprop,
xwininfo, and
wmctrl to get started.