Save and Restore window layout when monitor sleeps and wakes up

I have two monitors connected to my M4 Mac Mini. The problem is that one of them (my main monitor) is much slower than the other to wake up, and because of this all my open windows jump from it to the secondary monitor and then all -- including the ones that were actually on the secondary monitor -- jump back to to the main one, ruining my layout.

I would like to save the layout for both screens when the monitor goes into power save mode, and restore it when both monitors are finally powered back on.

Is there a system event trigger to detect when power saving kicks in, and one to detect when it ends?

Thanks