diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2007-05-25 15:05:39 +0000 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2007-05-25 15:05:39 +0000 |
commit | 816718041b1c49a78ed2e6dfeb983283023bb793 (patch) | |
tree | 116e367505c1be709bc64a8966c28f5cbe705dcf /lisp/xt-mouse.el | |
parent | 4b880ac1245e10e1ae80502dd58b174ffceea878 (diff) | |
download | emacs-816718041b1c49a78ed2e6dfeb983283023bb793.tar.gz |
(xterm-mouse-truncate-wrap): New function.
(xterm-mouse-event): Use it.
Diffstat (limited to 'lisp/xt-mouse.el')
-rw-r--r-- | lisp/xt-mouse.el | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el index 8ae79903d51..a4779053937 100644 --- a/lisp/xt-mouse.el +++ b/lisp/xt-mouse.el @@ -122,6 +122,22 @@ (+ c #x8000000 128) c))) +(defun xterm-mouse-truncate-wrap (f) + "Truncate with wrap-around." + (condition-case nil + ;; First try the built-in truncate, in case there's no overflow. + (truncate f) + ;; In case of overflow, do wraparound by hand. + (range-error + ;; In our case, we wrap around every 3 days or so, so if we assume + ;; a maximum of 65536 wraparounds, we're safe for a couple years. + ;; Using a power of 2 makes rounding errors less likely. + (let* ((maxwrap (* 65536 2048)) + (dbig (truncate (/ f maxwrap))) + (fdiff (- f (* 1.0 maxwrap dbig)))) + (+ (truncate fdiff) (* maxwrap dbig)))))) + + (defun xterm-mouse-event () "Convert XTerm mouse event to Emacs mouse event." (let* ((type (- (xterm-mouse-event-read) #o40)) @@ -129,7 +145,7 @@ (y (- (xterm-mouse-event-read) #o40 1)) ;; Emulate timestamp information. This is accurate enough ;; for default value of mouse-1-click-follows-link (450msec). - (timestamp (truncate + (timestamp (xterm-mouse-truncate-wrap (* 1000 (- (float-time) (or xt-mouse-epoch @@ -206,5 +222,5 @@ down the SHIFT key while pressing the mouse button." (provide 'xt-mouse) -;;; arch-tag: 84962d4e-fae9-4c13-a9d7-ef4925a4ac03 +;; arch-tag: 84962d4e-fae9-4c13-a9d7-ef4925a4ac03 ;;; xt-mouse.el ends here |