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.
This commit is contained in:
Daniel Eklöf 2020-05-16 21:09:59 +02:00
parent 38c050746d
commit e4a2d41f51
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 25 additions and 29 deletions

View file

@ -24,6 +24,14 @@
### Deprecated ### Deprecated
### Removed ### Removed
### Fixed ### Fixed
* Do not stop an ongoing selection when `shift` is released. When the
client application is capturing mouse events, one must hold down
`shift` to start a selection. This selection is now finalized only
when the mouse button is released - not as soon as `shift` is
released.
### Security ### Security

31
input.c
View file

@ -1176,26 +1176,29 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
if (button == BTN_LEFT && wayl->mouse.count <= 3) { if (button == BTN_LEFT && wayl->mouse.count <= 3) {
selection_cancel(term); selection_cancel(term);
switch (wayl->mouse.count) { if (selection_enabled(term)) {
case 1: switch (wayl->mouse.count) {
selection_start( case 1:
term, wayl->mouse.col, wayl->mouse.row, selection_start(
wayl->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); term, wayl->mouse.col, wayl->mouse.row,
break; wayl->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL);
break;
case 2: case 2:
selection_mark_word(term, wayl->mouse.col, wayl->mouse.row, selection_mark_word(term, wayl->mouse.col, wayl->mouse.row,
wayl->kbd.ctrl, serial); wayl->kbd.ctrl, serial);
break; break;
case 3: case 3:
selection_mark_row(term, wayl->mouse.row, serial); selection_mark_row(term, wayl->mouse.row, serial);
break; break;
}
} }
} }
else if (button == BTN_RIGHT && wayl->mouse.count == 1) { 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 { else {

View file

@ -314,9 +314,6 @@ void
selection_start(struct terminal *term, int col, int row, selection_start(struct terminal *term, int col, int row,
enum selection_kind kind) enum selection_kind kind)
{ {
if (!selection_enabled(term))
return;
selection_cancel(term); selection_cancel(term);
LOG_DBG("%s selection started at %d,%d", LOG_DBG("%s selection started at %d,%d",
@ -367,7 +364,6 @@ mark_selected(struct terminal *term, struct row *row, struct cell *cell,
static void static void
selection_modify(struct terminal *term, struct coord start, struct coord end) selection_modify(struct terminal *term, struct coord start, struct coord end)
{ {
assert(selection_enabled(term));
assert(term->selection.start.row != -1); assert(term->selection.start.row != -1);
assert(start.row != -1 && start.col != -1); assert(start.row != -1 && start.col != -1);
assert(end.row != -1 && end.col != -1); assert(end.row != -1 && end.col != -1);
@ -393,7 +389,6 @@ selection_modify(struct terminal *term, struct coord start, struct coord end)
void void
selection_update(struct terminal *term, int col, int row) selection_update(struct terminal *term, int col, int row)
{ {
if (!selection_enabled(term))
return; return;
LOG_DBG("selection updated: start = %d,%d, end = %d,%d -> %d, %d", LOG_DBG("selection updated: start = %d,%d, end = %d,%d -> %d, %d",
@ -401,7 +396,6 @@ selection_update(struct terminal *term, int col, int row)
term->selection.end.row, term->selection.end.col, term->selection.end.row, term->selection.end.col,
row, col); row, col);
assert(term->selection.start.row != -1);
assert(term->grid->view + row != -1); assert(term->grid->view + row != -1);
struct coord new_end = {col, term->grid->view + row}; struct coord new_end = {col, term->grid->view + row};
@ -526,9 +520,6 @@ selection_extend_block(struct terminal *term, int col, int row, uint32_t serial)
void void
selection_extend(struct terminal *term, int col, int row, uint32_t serial) selection_extend(struct terminal *term, int col, int row, uint32_t serial)
{ {
if (!selection_enabled(term))
return;
if (term->selection.start.row == -1 || term->selection.end.row == -1) { if (term->selection.start.row == -1 || term->selection.end.row == -1) {
/* No existing selection */ /* No existing selection */
return; return;
@ -587,9 +578,6 @@ selection_finalize(struct terminal *term, uint32_t serial)
void void
selection_cancel(struct terminal *term) selection_cancel(struct terminal *term)
{ {
if (!selection_enabled(term))
return;
LOG_DBG("selection cancelled: start = %d,%d end = %d,%d", LOG_DBG("selection cancelled: start = %d,%d end = %d,%d",
term->selection.start.row, term->selection.start.col, term->selection.start.row, term->selection.start.col,
term->selection.end.row, term->selection.end.col); term->selection.end.row, term->selection.end.col);
@ -610,9 +598,6 @@ void
selection_mark_word(struct terminal *term, int col, int row, bool spaces_only, selection_mark_word(struct terminal *term, int col, int row, bool spaces_only,
uint32_t serial) uint32_t serial)
{ {
if (!selection_enabled(term))
return;
selection_cancel(term); selection_cancel(term);
struct coord start = {col, row}; struct coord start = {col, row};