mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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.
This commit is contained in:
parent
8ec0aef307
commit
fb5a786bdb
@ -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 held_button = MOUSE_RELEASE;
|
||||||
static int orig_num_clicks = 1;
|
static int orig_num_clicks = 1;
|
||||||
static int orig_mouse_code = 0x0;
|
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;
|
int cpo_koffset;
|
||||||
|
|
||||||
cpo_koffset = (vim_strchr(p_cpo, CPO_KOFFSET) != NULL);
|
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) {
|
} else if (wheel_code == 0) {
|
||||||
# ifdef CHECK_DOUBLE_CLICK
|
# ifdef CHECK_DOUBLE_CLICK
|
||||||
{
|
{
|
||||||
/*
|
static int orig_mouse_col = 0;
|
||||||
* Compute the time elapsed since the previous mouse click.
|
static int orig_mouse_row = 0;
|
||||||
*/
|
|
||||||
gettimeofday(&mouse_time, NULL);
|
static uint64_t orig_mouse_time = 0; // time of previous mouse click
|
||||||
timediff = (mouse_time.tv_usec
|
uint64_t mouse_time = os_hrtime(); // time of current mouse click
|
||||||
- orig_mouse_time.tv_usec) / 1000;
|
|
||||||
if (timediff < 0)
|
// compute the time elapsed since the previous mouse click and
|
||||||
--orig_mouse_time.tv_sec;
|
// convert it from ns to ms because p_mouset is stored as ms
|
||||||
timediff += (mouse_time.tv_sec
|
long timediff = (long) (mouse_time - orig_mouse_time) / 1E6;
|
||||||
- orig_mouse_time.tv_sec) * 1000;
|
|
||||||
orig_mouse_time = mouse_time;
|
orig_mouse_time = mouse_time;
|
||||||
|
|
||||||
if (mouse_code == orig_mouse_code
|
if (mouse_code == orig_mouse_code
|
||||||
&& timediff < p_mouset
|
&& timediff < p_mouset
|
||||||
&& orig_num_clicks != 4
|
&& orig_num_clicks != 4
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
* 128 = 16384 columns, now it's reduced to 10000. */
|
* 128 = 16384 columns, now it's reduced to 10000. */
|
||||||
#define MOUSE_COLOFF 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. */
|
# define CHECK_DOUBLE_CLICK 1 /* Checking for double clicks ourselves. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user