aboutsummaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-10 18:57:09 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-11 15:38:01 +0000
commit632790d5d8686be00ce3e0134b940992c99f0df4 (patch)
tree68a93d71faa269f672d6946ee7e12c102054926d /input.c
parentgrid: prefetch cells in grid_row() (diff)
selection: selections can be made, and are rendered
* Start selection on mouse button down * Update selection on motion * Button release cancels selection if there were no motion after start * Renderer detects cells inside the selection and inverts their colors
Diffstat (limited to 'input.c')
-rw-r--r--input.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/input.c b/input.c
index 33547fcd..5032c748 100644
--- a/input.c
+++ b/input.c
@@ -312,6 +312,14 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
term->mouse.col = col;
term->mouse.row = row;
+ if (term->mouse.button != 0) {
+ /* Update selection */
+ term->selection.end = (struct coord){col, term->grid->view + row};
+ term_damage_view(term);
+ if (term->frame_callback == NULL)
+ grid_render(term);
+ }
+
term_mouse_motion(
term, term->mouse.button, term->mouse.row, term->mouse.col,
term->kbd.shift, term->kbd.alt, term->kbd.ctrl);
@@ -327,12 +335,25 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
switch (state) {
case WL_POINTER_BUTTON_STATE_PRESSED:
+ /* Start selection */
+ term->selection.start = (struct coord){
+ term->mouse.col, term->grid->view + term->mouse.row};
+ term->selection.end = (struct coord){-1, -1};
+
term->mouse.button = button; /* For motion events */
term_mouse_down(term, button, term->mouse.row, term->mouse.col,
term->kbd.shift, term->kbd.alt, term->kbd.ctrl);
break;
case WL_POINTER_BUTTON_STATE_RELEASED:
+ if (term->selection.end.col == -1) {
+ /* No selection made - cancel */
+ term->selection.start = (struct coord){-1, -1};
+ term_damage_view(term);
+ if (term->frame_callback == NULL)
+ grid_render(term);
+ }
+
term->mouse.button = 0; /* For motion events */
term_mouse_up(term, button, term->mouse.row, term->mouse.col,
term->kbd.shift, term->kbd.alt, term->kbd.ctrl);