changeset 81072:ecb305fe2f17

(xterm-mouse-truncate-wrap): New function. (xterm-mouse-event): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 25 May 2007 14:34:35 +0000
parents 5b3b1e543897
children 12cb550b10e4
files lisp/ChangeLog lisp/xt-mouse.el
diffstat 2 files changed, 27 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Fri May 25 10:14:51 2007 +0000
+++ b/lisp/ChangeLog	Fri May 25 14:34:35 2007 +0000
@@ -1,3 +1,8 @@
+2007-05-25  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* xt-mouse.el (xterm-mouse-truncate-wrap): New function.
+	(xterm-mouse-event): Use it.
+
 2007-05-25  Juanma Barranquero  <lekktu@gmail.com>
 
 	* bs.el (bs-cycle-previous): Don't modify the cycle list until
--- a/lisp/xt-mouse.el	Fri May 25 10:14:51 2007 +0000
+++ b/lisp/xt-mouse.el	Fri May 25 14:34:35 2007 +0000
@@ -126,6 +126,21 @@
         (+ 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))
@@ -133,12 +148,12 @@
 	 (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
-		     (* 1000
-			(- (float-time)
-			   (or xt-mouse-epoch
-			       (setq xt-mouse-epoch (float-time)))))))
-	 (mouse (intern
+	 (timestamp (xterm-mouse-truncate-wrap
+                     (* 1000
+                        (- (float-time)
+                           (or xt-mouse-epoch
+                               (setq xt-mouse-epoch (float-time)))))))
+         (mouse (intern
 		 ;; For buttons > 3, the release-event looks
 		 ;; differently (see xc/programs/xterm/button.c,
 		 ;; function EditorButton), and there seems to come in
@@ -210,5 +225,5 @@
 
 (provide 'xt-mouse)
 
-;;; arch-tag: 84962d4e-fae9-4c13-a9d7-ef4925a4ac03
+;; arch-tag: 84962d4e-fae9-4c13-a9d7-ef4925a4ac03
 ;;; xt-mouse.el ends here