diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-08-06 17:32:06 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-08-06 17:32:06 +0000 |
| commit | 481a1cd6780233888fa1132242cb96f20ab14b73 (patch) | |
| tree | bf508e829195de989fc44871767b8019804cd35d | |
| parent | main: make all polled FDs non-blocking (diff) | |
selection/input: triple click selects an entire row
| -rw-r--r-- | input.c | 34 | ||||
| -rw-r--r-- | selection.c | 8 | ||||
| -rw-r--r-- | selection.h | 1 | ||||
| -rw-r--r-- | terminal.h | 1 |
4 files changed, 32 insertions, 12 deletions
@@ -403,27 +403,37 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, switch (state) { case WL_POINTER_BUTTON_STATE_PRESSED: { - bool double_click = false; - - struct timeval now; + /* Time since last click */ + struct timeval now, since_last; gettimeofday(&now, NULL); - - struct timeval since_last; timersub(&now, &term->mouse.last_time, &since_last); + + /* Double- or triple click? */ if (button == term->mouse.last_button && - since_last.tv_sec == 0 && since_last.tv_usec <= 300 * 1000) + since_last.tv_sec == 0 && + since_last.tv_usec <= 300 * 1000) { - double_click = true; - } + term->mouse.count++; + } else + term->mouse.count = 1; if (button == BTN_LEFT) { - if (double_click) + switch (term->mouse.count) { + case 1: + selection_start(term, term->mouse.col, term->mouse.row); + break; + + case 2: selection_mark_word(term, term->mouse.col, term->mouse.row, term->kbd.ctrl, serial); - else - selection_start(term, term->mouse.col, term->mouse.row); + break; + + case 3: + selection_mark_row(term, term->mouse.row, serial); + break; + } } else { - if (button == BTN_MIDDLE) + if (term->mouse.count == 1 && button == BTN_MIDDLE) selection_from_primary(term); selection_cancel(term); } diff --git a/selection.c b/selection.c index f69338a4..7c3d4826 100644 --- a/selection.c +++ b/selection.c @@ -333,6 +333,14 @@ selection_mark_word(struct terminal *term, int col, int row, bool spaces_only, selection_finalize(term, serial); } +void +selection_mark_row(struct terminal *term, int row, uint32_t serial) +{ + selection_start(term, 0, row); + selection_update(term, term->cols - 1, row); + selection_finalize(term, serial); +} + static void target(void *data, struct wl_data_source *wl_data_source, const char *mime_type) { diff --git a/selection.h b/selection.h index 2e574b0b..8622c04a 100644 --- a/selection.h +++ b/selection.h @@ -14,6 +14,7 @@ void selection_finalize(struct terminal *term, uint32_t serial); void selection_cancel(struct terminal *term); void selection_mark_word(struct terminal *term, int col, int row, bool spaces_only, uint32_t serial); +void selection_mark_row(struct terminal *term, int row, uint32_t serial); void selection_to_clipboard(struct terminal *term, uint32_t serial); void selection_from_clipboard(struct terminal *term, uint32_t serial); @@ -273,6 +273,7 @@ struct terminal { int row; int button; + int count; int last_button; struct timeval last_time; |
