emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/xt-mouse.el,v


From: Stefan Monnier
Subject: [Emacs-diffs] Changes to emacs/lisp/xt-mouse.el,v
Date: Fri, 25 May 2007 14:34:37 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Stefan Monnier <monnier>        07/05/25 14:34:36

Index: xt-mouse.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/xt-mouse.el,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -b -r1.40 -r1.41
--- xt-mouse.el 12 May 2007 09:39:06 -0000      1.40
+++ xt-mouse.el 25 May 2007 14:34:34 -0000      1.41
@@ -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,7 +148,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
@@ -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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]