fix a bug when minimizing a maximized window

When minimizing a maximized window and using the ANY_WINDOW_MAXIMIZED mode, calculation of visibility of buttons is not done properly, resulting in button visible when maximized AND minimized window exists.

This fix the problem. Also, some code duplication exists and a refactoring seems necessary to me or the whole stuff will become unmaintable soon.