From e4a2d41f51785452ccb0bdb24ac5577203ff0da3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 16 May 2020 21:09:59 +0200 Subject: selection: don't automatically no-op operations if selection isn't enabled When the client is capturing the mouse, selection can only be done by holding done shift. This is why a lot of selection functions are no-ops if selection isn't currently enabled. However, there are many cases where we actually need to modify the selection. In particular, selection_cancel(). Thus, only check for enabled selection when we're dealing with user input. Bonus: this also fixes a bug where an ongoing selection were finalized as soon as the user released shift, even if he was still holding down the mouse button. --- input.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index f7d14f0f..b4816f86 100644 --- a/input.c +++ b/input.c @@ -1176,26 +1176,29 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, if (button == BTN_LEFT && wayl->mouse.count <= 3) { selection_cancel(term); - switch (wayl->mouse.count) { - case 1: - selection_start( - term, wayl->mouse.col, wayl->mouse.row, - wayl->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); - break; - - case 2: - selection_mark_word(term, wayl->mouse.col, wayl->mouse.row, - wayl->kbd.ctrl, serial); - break; - - case 3: - selection_mark_row(term, wayl->mouse.row, serial); - break; + if (selection_enabled(term)) { + switch (wayl->mouse.count) { + case 1: + selection_start( + term, wayl->mouse.col, wayl->mouse.row, + wayl->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); + break; + + case 2: + selection_mark_word(term, wayl->mouse.col, wayl->mouse.row, + wayl->kbd.ctrl, serial); + break; + + case 3: + selection_mark_row(term, wayl->mouse.row, serial); + break; + } } } else if (button == BTN_RIGHT && wayl->mouse.count == 1) { - selection_extend(term, wayl->mouse.col, wayl->mouse.row, serial); + if (selection_enabled(term)) + selection_extend(term, wayl->mouse.col, wayl->mouse.row, serial); } else { -- cgit v1.3