PySide compatibility + small bugs

PySide have a bug for windowStateChanged, so added workaround. Might
just make it the same for PyQt too, but then it is less reusable. Maybe
find a better, common way.