aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas Hillegeer <nicolas@hillegeer.com>2014-07-21 15:51:17 +0200
committerNicolas Hillegeer <nicolas@hillegeer.com>2014-07-21 19:29:29 +0200
commitfb5a786bdb5b7b52b9c36b3eb8b6d2cc002aa8f3 (patch)
tree53af7c169a81413d5dee46128174b3d7b82073ff /src
parent8ec0aef307f64353c4d21377f6482df238ef7764 (diff)
downloadrneovim-fb5a786bdb5b7b52b9c36b3eb8b6d2cc002aa8f3.tar.gz
rneovim-fb5a786bdb5b7b52b9c36b3eb8b6d2cc002aa8f3.tar.bz2
rneovim-fb5a786bdb5b7b52b9c36b3eb8b6d2cc002aa8f3.zip
term: replace gettimeofday()
gettimeofday() is not portable, replace with os_hrtime() wherever possible. The new code should behave equivalently to the old implementation. Because of this, HAVE_GETTIMEOFDAY is no longer necessary To be able to handle double clicks.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/term.c28
-rw-r--r--src/nvim/term.h2
2 files changed, 11 insertions, 19 deletions
diff --git a/src/nvim/term.c b/src/nvim/term.c
index 4ed438b282..f4bc2df2fb 100644
--- a/src/nvim/term.c
+++ b/src/nvim/term.c
@@ -3179,14 +3179,6 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen)
static int held_button = MOUSE_RELEASE;
static int orig_num_clicks = 1;
static int orig_mouse_code = 0x0;
-# ifdef CHECK_DOUBLE_CLICK
- static int orig_mouse_col = 0;
- static int orig_mouse_row = 0;
- static struct timeval orig_mouse_time = {0, 0};
- /* time of previous mouse click */
- struct timeval mouse_time; /* time of current mouse click */
- long timediff; /* elapsed time in msec */
-# endif
int cpo_koffset;
cpo_koffset = (vim_strchr(p_cpo, CPO_KOFFSET) != NULL);
@@ -3955,17 +3947,17 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen)
} else if (wheel_code == 0) {
# ifdef CHECK_DOUBLE_CLICK
{
- /*
- * Compute the time elapsed since the previous mouse click.
- */
- gettimeofday(&mouse_time, NULL);
- timediff = (mouse_time.tv_usec
- - orig_mouse_time.tv_usec) / 1000;
- if (timediff < 0)
- --orig_mouse_time.tv_sec;
- timediff += (mouse_time.tv_sec
- - orig_mouse_time.tv_sec) * 1000;
+ static int orig_mouse_col = 0;
+ static int orig_mouse_row = 0;
+
+ static uint64_t orig_mouse_time = 0; // time of previous mouse click
+ uint64_t mouse_time = os_hrtime(); // time of current mouse click
+
+ // compute the time elapsed since the previous mouse click and
+ // convert it from ns to ms because p_mouset is stored as ms
+ long timediff = (long) (mouse_time - orig_mouse_time) / 1E6;
orig_mouse_time = mouse_time;
+
if (mouse_code == orig_mouse_code
&& timediff < p_mouset
&& orig_num_clicks != 4
diff --git a/src/nvim/term.h b/src/nvim/term.h
index 52c3efcac5..17154b8c26 100644
--- a/src/nvim/term.h
+++ b/src/nvim/term.h
@@ -52,7 +52,7 @@
* 128 = 16384 columns, now it's reduced to 10000. */
#define MOUSE_COLOFF 10000
-#if defined(UNIX) && defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)
+#if defined(UNIX)
# define CHECK_DOUBLE_CLICK 1 /* Checking for double clicks ourselves. */
#endif