comparison lisp/xt-mouse.el @ 77809:20f40276359e

(xterm-mouse-truncate-wrap): New function. (xterm-mouse-event): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 25 May 2007 15:00:41 +0000
parents 44b6d7a1ef55
children 9355f9b7bbff
comparison
equal deleted inserted replaced
77808:c97a9221b6b8 77809:20f40276359e
120 (let ((c (read-char))) 120 (let ((c (read-char)))
121 (if (< c 0) 121 (if (< c 0)
122 (+ c #x8000000 128) 122 (+ c #x8000000 128)
123 c))) 123 c)))
124 124
125 (defun xterm-mouse-truncate-wrap (f)
126 "Truncate with wrap-around."
127 (condition-case nil
128 ;; First try the built-in truncate, in case there's no overflow.
129 (truncate f)
130 ;; In case of overflow, do wraparound by hand.
131 (range-error
132 ;; In our case, we wrap around every 3 days or so, so if we assume
133 ;; a maximum of 65536 wraparounds, we're safe for a couple years.
134 ;; Using a power of 2 makes rounding errors less likely.
135 (let* ((maxwrap (* 65536 2048))
136 (dbig (truncate (/ f maxwrap)))
137 (fdiff (- f (* 1.0 maxwrap dbig))))
138 (+ (truncate fdiff) (* maxwrap dbig))))))
139
140
125 (defun xterm-mouse-event () 141 (defun xterm-mouse-event ()
126 "Convert XTerm mouse event to Emacs mouse event." 142 "Convert XTerm mouse event to Emacs mouse event."
127 (let* ((type (- (xterm-mouse-event-read) #o40)) 143 (let* ((type (- (xterm-mouse-event-read) #o40))
128 (x (- (xterm-mouse-event-read) #o40 1)) 144 (x (- (xterm-mouse-event-read) #o40 1))
129 (y (- (xterm-mouse-event-read) #o40 1)) 145 (y (- (xterm-mouse-event-read) #o40 1))
130 ;; Emulate timestamp information. This is accurate enough 146 ;; Emulate timestamp information. This is accurate enough
131 ;; for default value of mouse-1-click-follows-link (450msec). 147 ;; for default value of mouse-1-click-follows-link (450msec).
132 (timestamp (truncate 148 (timestamp (xterm-mouse-truncate-wrap
133 (* 1000 149 (* 1000
134 (- (float-time) 150 (- (float-time)
135 (or xt-mouse-epoch 151 (or xt-mouse-epoch
136 (setq xt-mouse-epoch (float-time))))))) 152 (setq xt-mouse-epoch (float-time)))))))
137 (mouse (intern 153 (mouse (intern
204 (add-hook 'suspend-resume-hook 'turn-on-xterm-mouse-tracking) 220 (add-hook 'suspend-resume-hook 'turn-on-xterm-mouse-tracking)
205 (add-hook 'kill-emacs-hook 'turn-off-xterm-mouse-tracking) 221 (add-hook 'kill-emacs-hook 'turn-off-xterm-mouse-tracking)
206 222
207 (provide 'xt-mouse) 223 (provide 'xt-mouse)
208 224
209 ;;; arch-tag: 84962d4e-fae9-4c13-a9d7-ef4925a4ac03 225 ;; arch-tag: 84962d4e-fae9-4c13-a9d7-ef4925a4ac03
210 ;;; xt-mouse.el ends here 226 ;;; xt-mouse.el ends here