From e853c7139e83f6ad6222abe232238f861d96e436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 12 Jan 2022 15:38:32 +0100 Subject: [PATCH] input: reset mouse button click counter when mouse moves MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As described in #883, creating a block selection (with ctrl+BTN_LEFT), then *quickly* (within 300ms from) creating a new one, will, in fact, _not_ create a new block selection, but a ‘select-word-whitespace’ selection (ctrl+BTN_LEFT-2). A similar effect can be seen with plain selections (BTN_LEFT). Click and drag to make a selection, but *release*, and make a new selection within 300ms from the initial button press, and the new selection is suddenly a word-based selection. This happens because triggering a binding does *not* reset the button click counter. So, shouldn’t we just do that? No, because we rely on this behavior to handle single-, double- and triple-click actions. If we were to reset the button click handler, then we’d have to instead delay triggering the first action with 300ms, which would make things appear laggy. If we don’t do this, it would be impossible to double- and triple-click, since the single-click action would keep resetting the click counter. This patch takes a slightly different approach; we reset the click counter when the mouse has moved “too much”. For now, “too much” is when the cursor has moved to a different cell. This way, single-, double- and triple-clicks continue to work as before. But, creating actual selections, and then quickly releasing and starting a new selection produces the expected results. Closes #883 --- CHANGELOG.md | 3 +++ input.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee5b8da1..85906524 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,9 @@ * Failure to launch when `exec(3)’:ed with an empty argv. * Pasting from the primary clipboard (mouse middle clicking) did not reset the scrollback view to the bottom. +* Wrong mouse binding triggered when doing two mouse selections in + very quick (< 300ms) succession + (https://codeberg.org/dnkl/foot/issues/883). ### Security diff --git a/input.c b/input.c index 6013634e..885ae02e 100644 --- a/input.c +++ b/input.c @@ -2046,6 +2046,13 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, bool cursor_is_on_new_cell = old_col != seat->mouse.col || old_row != seat->mouse.row; + if (cursor_is_on_new_cell) { + /* Prevent multiple/different mouse bindings from + * triggering if the mouse has moved “too much” (to + * another cell) */ + seat->mouse.count = 0; + } + /* Cursor is inside the grid, i.e. *not* in the margins */ const bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0;