Change the way to check whether window has focus