code that detects changed current window