val motionSlot = fun(motion: PointerMotion) { if (grab.isPresent && surfaceViews.contains(grab.get())) { //there is pointer motion pointerGrabMotion.motion(motion) } else { //another surface has the grab, stop listening for pointer motion. motionSignal.disconnect(this) } } //listen for pointer motion motionSignal.connect(motionSlot)