Run the function due to window state