-(defun mouse-avoidance-banish-hook ()
- (if (and (not executing-kbd-macro) ; don't check inside macro
- (cadr (mouse-position)) ; don't move unless in an Emacs frame
- ;; Don't do anything if last event was a mouse event.
- (not (and (consp last-input-event)
- (symbolp (car last-input-event))
- (let ((modifiers (event-modifiers (car last-input-event))))
- (or (memq (car last-input-event)
- '(mouse-movement scroll-bar-movement))
- (memq 'click modifiers)
- (memq 'drag modifiers)
- (memq 'down modifiers))))))
+(defun mouse-avoidance-ignore-p ()
+ (let ((mp (mouse-position)))
+ (or executing-kbd-macro ; don't check inside macro
+ (null (cadr mp)) ; don't move unless in an Emacs frame
+ (not (eq (car mp) (selected-frame)))
+ ;; Don't do anything if last event was a mouse event.
+ ;; FIXME: this code fails in the case where the mouse was moved
+ ;; since the last key-press but without generating any event.
+ (and (consp last-input-event)
+ (symbolp (car last-input-event))
+ (let ((modifiers (event-modifiers (car last-input-event))))
+ (or (memq (car last-input-event)
+ '(mouse-movement scroll-bar-movement
+ select-window switch-frame))
+ (memq 'click modifiers)
+ (memq 'double modifiers)
+ (memq 'triple modifiers)
+ (memq 'drag modifiers)
+ (memq 'down modifiers)))))))
+
+(defun mouse-avoidance-banish ()
+ (if (not (mouse-avoidance-ignore-p))