Dynamic recalculation of width and height of the window