Handling minimize window event

Hi,

I’d like to write a daemon (preferably in Python), which reacts to window being minimized and un-minimized. It would be enough to get a PID (if available), but the name would be nice as well.

Could you please point me to the right direction? So far I gathered, that most likely I should use d-bus for this, but I can’t find a proper path to attach to a signal.

Longer version, what I want to do (maybe someone already done it?): I have lots of running windows, which I don’t use much, but if I need them, I need them instantly, so I don’t want to kill them. Couple of them are badly written, so they use CPU and eat into my battery way too much. I’d like to send them STOP/CONT on minimize/unminimize. Kind of like Android apps work, if they are not allowed to run in the background.