summaryrefslogtreecommitdiff
path: root/src/term.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-06-22 14:17:42 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2012-06-22 14:17:42 -0700
commitd35af63cd671563fd188c3b0a1ef30067027c7aa (patch)
treec9e01847ccf788e23794684da9331c3e0defd0d3 /src/term.c
parentf143bfe38b43ad0a9d817f05c25e418982dca06f (diff)
Support higher-resolution time stamps.
Fixes: debbugs:9000
Diffstat (limited to 'src/term.c')
-rw-r--r--src/term.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/term.c b/src/term.c
index 5f80718119..1a2524fd29 100644
--- a/src/term.c
+++ b/src/term.c
@@ -24,6 +24,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <ctype.h>
#include <errno.h>
#include <sys/file.h>
+#include <sys/time.h>
#include <unistd.h>
#include <signal.h>
#include <setjmp.h>
@@ -2611,6 +2612,18 @@ term_mouse_movement (FRAME_PTR frame, Gpm_Event *event)
return 0;
}
+/* Return the Time that corresponds to T. Wrap around on overflow. */
+static Time
+timeval_to_Time (struct timeval const *t)
+{
+ Time s_1000, ms;
+
+ s_1000 = t->tv_sec;
+ s_1000 *= 1000;
+ ms = t->tv_usec / 1000;
+ return s_1000 + ms;
+}
+
/* Return the current position of the mouse.
Set *f to the frame the mouse is in, or zero if the mouse is in no
@@ -2630,7 +2643,6 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
Lisp_Object *y, Time *timeptr)
{
struct timeval now;
- Time sec, usec;
*fp = SELECTED_FRAME ();
(*fp)->mouse_moved = 0;
@@ -2641,9 +2653,7 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
XSETINT (*x, last_mouse_x);
XSETINT (*y, last_mouse_y);
gettimeofday(&now, 0);
- sec = now.tv_sec;
- usec = now.tv_usec;
- *timeptr = (sec * 1000) + (usec / 1000);
+ *timeptr = timeval_to_Time (&now);
}
/* Prepare a mouse-event in *RESULT for placement in the input queue.
@@ -2667,7 +2677,7 @@ term_mouse_click (struct input_event *result, Gpm_Event *event,
}
}
gettimeofday(&now, 0);
- result->timestamp = (now.tv_sec * 1000) + (now.tv_usec / 1000);
+ result->timestamp = timeval_to_Time (&now);
if (event->type & GPM_UP)
result->modifiers = up_modifier;