Fix motion recorder being activated erroneously

We need to check which window is under the pointer after having changed
the z-order of windows.