;;=============================================================================
;; My mouse-frob stuff
;;=============================================================================

(defname 'mouse-frob.last-dir screen. 0) ; Last direction moved
(defname 'mouse-frob.velocity screen. 5) ; Current velocity

;;  Grab the necessary keys.
(setq grabs (+ grabs (list (key "Right" with-alt)
			   (key "Left" with-alt)
			   (key "Up" with-alt)
			   (key "Down" with-alt))))

;;  Mouse-move state machine.
(setq mouse-frob
      (state-make
       (on (key "Left" with-alt)  
	    (warp-mouse-move 'left))
       (on (key "Right" with-alt) 
	    (warp-mouse-move 'right))
       (on (key "Up" with-alt)    
	    (warp-mouse-move 'up))
       (on (key "Down" with-alt)  
	    (warp-mouse-move 'down))))

(defun warp-mouse-move (dir)
  (setq mouse-frob.velocity   ; Increment or reset the velocity
	(if (eq dir mouse-frob.last-dir)
	    (+ mouse-frob.velocity 5)
	    5))
  (setq mouse-frob.last-dir dir)
  (warp-pointer 
   (cond ((eq 'left dir)  (- 0 mouse-frob.velocity))
	 ((eq 'right dir) mouse-frob.velocity)
	 (t 0))
   (cond ((eq 'up dir) (- 0 mouse-frob.velocity))
	 ((eq 'down dir) mouse-frob.velocity)
	 (t 0))))

