Run a script when an app maximizes or goes full-screen

I’m not sure if it’s the right section to write this, feel free to tell me if it’s not so I can post this where it belongs.

I’m currently trying to replicate the behavior of Wallpaper Engine from Windows and the last piece I need is a way to play or pause the wallpaper whenever an app maximizes or goes full-screen.
I already have the command, but I don’t know how to make it run by itself.
Is there something like a trigger to run the command when those conditions are met?
Or should I write a program to evaluate periodically if the conditions are met? If so, which software is responsible for that? X11, Xorg server, gtk? Is there an api which I should use?