Detecting mouse entry/exit... again
Hi, It seems like this is almost a FAQ, but one that doesn't (as far as I can tell) have a satisfactory answer: how to detect entry/exit of the mouse pointer from a pane or window. Googling the topic has led me toward the idea of running a timer which is scheduled when entering the pane and whose expiry function checks if the pointer is inside the pane and unschedules the timer when not (I think this is how Allegro's CG does it). I've implemented this using a :motion input-model - (defparameter *timer* nil) (defun mouse-timer-test (self x y) (declare (ignore x y)) (unless *timer* (setf *timer* (mp:make-timer 'mp:process-run-function "Mouse Timer" nil #'(lambda () (unless (inside-box-p self) (destroy-timer))))) (mp:schedule-timer-relative-milliseconds *timer* 10 10))) (defun destroy-timer () (when *timer* ; Occasional error without this test! (mp:unschedule-timer *timer*)) (setf *timer* nil)) (defun inside-box-p (self) ; Check is we are within bounding-box of self. (capi:with-geometry self (multiple-value-bind (x y) (capi:current-pointer-position :relative-to self) (and (>= x 0) (<= x capi:%width%) (>= y 0) (<= y capi:%height%))))) (capi:contain (make-instance 'capi:output-pane :visible-min-width 400 :visible-min-height 400 :input-model '((:motion mouse-timer-test)))) I occasionally get an error with this approach, when the expiry function attempts to unschedule the timer AFTER it has been destroyed (*timer* set to nil). Presumably this is because of the inherent unpredictability associated with timers. This can be avoided by checking if the timer still exists before unscheduling it. Is there a more elegant solution to this problem, though? What other approaches have people come up with? Is there any chance that support for this feature will be added to CAPI any time soon? TIA, Chris