diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:15:05 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:27:38 +0000 |
commit | c5d770d311841ea5230426cc4c868e8db27300a8 (patch) | |
tree | dd21f70127b4b8b5f109baefc8ecc5016f507c91 /src/nvim/os/input.c | |
parent | 9be89f131f87608f224f0ee06d199fcd09d32176 (diff) | |
parent | 081beb3659bd6d8efc3e977a160b1e72becbd8a2 (diff) | |
download | rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.gz rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.bz2 rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.zip |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/os/input.c')
-rw-r--r-- | src/nvim/os/input.c | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 7c5293a8b8..2d17581bac 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -289,9 +289,10 @@ size_t input_enqueue(String keys) unsigned new_size = trans_special(&ptr, (size_t)(end - ptr), (char *)buf, FSK_KEYCODE, true, NULL); - if (new_size) { - new_size = handle_mouse_event(&ptr, buf, new_size); - input_enqueue_raw((char *)buf, new_size); + if (new_size > 0) { + if ((new_size = handle_mouse_event(&ptr, buf, new_size)) > 0) { + input_enqueue_raw((char *)buf, new_size); + } continue; } @@ -326,7 +327,7 @@ size_t input_enqueue(String keys) return rv; } -static uint8_t check_multiclick(int code, int grid, int row, int col) +static uint8_t check_multiclick(int code, int grid, int row, int col, bool *skip_event) { static int orig_num_clicks = 0; static int orig_mouse_code = 0; @@ -335,24 +336,29 @@ static uint8_t check_multiclick(int code, int grid, int row, int col) static int orig_mouse_row = 0; static uint64_t orig_mouse_time = 0; // time of previous mouse click - if ((code >= KE_MOUSEDOWN && code <= KE_MOUSERIGHT) || code == KE_MOUSEMOVE) { + if (code >= KE_MOUSEDOWN && code <= KE_MOUSERIGHT) { return 0; } - // For click events the number of clicks is updated. - if (code == KE_LEFTMOUSE || code == KE_RIGHTMOUSE || code == KE_MIDDLEMOUSE - || code == KE_X1MOUSE || code == KE_X2MOUSE) { + bool no_move = orig_mouse_grid == grid && orig_mouse_col == col && orig_mouse_row == row; + + if (code == KE_MOUSEMOVE) { + if (no_move) { + *skip_event = true; + return 0; + } + } else if (code == KE_LEFTMOUSE || code == KE_RIGHTMOUSE || code == KE_MIDDLEMOUSE + || code == KE_X1MOUSE || code == KE_X2MOUSE) { + // For click events the number of clicks is updated. uint64_t mouse_time = os_hrtime(); // time of current mouse click (ns) - // compute the time elapsed since the previous mouse click and - // convert p_mouse from ms to ns + // Compute the time elapsed since the previous mouse click. uint64_t timediff = mouse_time - orig_mouse_time; + // Convert 'mousetime' from ms to ns. uint64_t mouset = (uint64_t)p_mouset * 1000000; if (code == orig_mouse_code + && no_move && timediff < mouset - && orig_num_clicks != 4 - && orig_mouse_grid == grid - && orig_mouse_col == col - && orig_mouse_row == row) { + && orig_num_clicks != 4) { orig_num_clicks++; } else { orig_num_clicks = 1; @@ -367,12 +373,14 @@ static uint8_t check_multiclick(int code, int grid, int row, int col) orig_mouse_row = row; uint8_t modifiers = 0; - if (orig_num_clicks == 2) { - modifiers |= MOD_MASK_2CLICK; - } else if (orig_num_clicks == 3) { - modifiers |= MOD_MASK_3CLICK; - } else if (orig_num_clicks == 4) { - modifiers |= MOD_MASK_4CLICK; + if (code != KE_MOUSEMOVE) { + if (orig_num_clicks == 2) { + modifiers |= MOD_MASK_2CLICK; + } else if (orig_num_clicks == 3) { + modifiers |= MOD_MASK_3CLICK; + } else if (orig_num_clicks == 4) { + modifiers |= MOD_MASK_4CLICK; + } } return modifiers; } @@ -399,7 +407,7 @@ static unsigned handle_mouse_event(const char **ptr, uint8_t *buf, unsigned bufs return bufsize; } - // a <[COL],[ROW]> sequence can follow and will set the mouse_row/mouse_col + // A <[COL],[ROW]> sequence can follow and will set the mouse_row/mouse_col // global variables. This is ugly but its how the rest of the code expects to // find mouse coordinates, and it would be too expensive to refactor this // now. @@ -421,8 +429,12 @@ static unsigned handle_mouse_event(const char **ptr, uint8_t *buf, unsigned bufs *ptr += advance; } + bool skip_event = false; uint8_t modifiers = check_multiclick(mouse_code, mouse_grid, - mouse_row, mouse_col); + mouse_row, mouse_col, &skip_event); + if (skip_event) { + return 0; + } if (modifiers) { if (buf[1] != KS_MODIFIER) { @@ -443,7 +455,11 @@ static unsigned handle_mouse_event(const char **ptr, uint8_t *buf, unsigned bufs void input_enqueue_mouse(int code, uint8_t modifier, int grid, int row, int col) { - modifier |= check_multiclick(code, grid, row, col); + bool skip_event = false; + modifier |= check_multiclick(code, grid, row, col, &skip_event); + if (skip_event) { + return; + } uint8_t buf[7]; uint8_t *p = buf; if (modifier) { |