input: cleanup

This commit is contained in:
Daniel Eklöf 2020-02-29 15:29:00 +01:00
parent e496d81f4d
commit 73133c10ee
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 71 additions and 73 deletions

140
input.c
View file

@ -689,10 +689,6 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
int y = wl_fixed_to_int(surface_y) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale;
switch ((term->active_surface = term_surface_kind(term, surface))) { switch ((term->active_surface = term_surface_kind(term, surface))) {
case TERM_SURF_NONE:
assert(false);
break;
case TERM_SURF_GRID: case TERM_SURF_GRID:
wayl->mouse.col = x / term->cell_width; wayl->mouse.col = x / term->cell_width;
wayl->mouse.row = y / term->cell_height; wayl->mouse.row = y / term->cell_height;
@ -700,7 +696,9 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
break; break;
case TERM_SURF_SEARCH: case TERM_SURF_SEARCH:
term_xcursor_update(term); case TERM_SURF_TITLE:
term->xcursor = "left_ptr";
render_xcursor_set(term);
break; break;
case TERM_SURF_BORDER_LEFT: case TERM_SURF_BORDER_LEFT:
@ -711,13 +709,10 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
render_xcursor_set(term); render_xcursor_set(term);
break; break;
case TERM_SURF_TITLE: case TERM_SURF_NONE:
term->xcursor = "left_ptr"; assert(false);
render_xcursor_set(term);
break; break;
} }
} }
static void static void
@ -785,12 +780,11 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
int x = wl_fixed_to_int(surface_x) * term->scale; int x = wl_fixed_to_int(surface_x) * term->scale;
int y = wl_fixed_to_int(surface_y) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale;
term->window->csd.x = x; wayl->mouse.x = x;
term->window->csd.y = y; wayl->mouse.y = y;
switch (term->active_surface) { switch (term->active_surface) {
case TERM_SURF_NONE: case TERM_SURF_NONE:
case TERM_SURF_GRID:
case TERM_SURF_SEARCH: case TERM_SURF_SEARCH:
case TERM_SURF_TITLE: case TERM_SURF_TITLE:
break; break;
@ -802,34 +796,34 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
term->xcursor = xcursor_for_csd_border(term, x, y); term->xcursor = xcursor_for_csd_border(term, x, y);
render_xcursor_set(term); render_xcursor_set(term);
break; break;
}
if (term->active_surface != TERM_SURF_GRID) case TERM_SURF_GRID: {
return; int col = (x - term->margins.left) / term->cell_width;
int row = (y - term->margins.top) / term->cell_height;
int col = (x - term->margins.left) / term->cell_width; if (col < 0 || row < 0 || col >= term->cols || row >= term->rows)
int row = (y - term->margins.top) / term->cell_height; return;
if (col < 0 || row < 0 || col >= term->cols || row >= term->rows) bool update_selection = wayl->mouse.button == BTN_LEFT;
return; bool update_selection_early = term->selection.end.row == -1;
bool update_selection = wayl->mouse.button == BTN_LEFT; if (update_selection && update_selection_early)
bool update_selection_early = term->selection.end.row == -1; selection_update(term, col, row);
if (update_selection && update_selection_early) if (col == wayl->mouse.col && row == wayl->mouse.row)
selection_update(term, col, row); break;
if (col == wayl->mouse.col && row == wayl->mouse.row) wayl->mouse.col = col;
return; wayl->mouse.row = row;
wayl->mouse.col = col; if (update_selection && !update_selection_early)
wayl->mouse.row = row; selection_update(term, col, row);
if (update_selection && !update_selection_early) term_mouse_motion(
selection_update(term, col, row);
term_mouse_motion(
term, wayl->mouse.button, wayl->mouse.row, wayl->mouse.col); term, wayl->mouse.button, wayl->mouse.row, wayl->mouse.col);
break;
}
}
} }
static bool static bool
@ -896,10 +890,6 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
wayl->mouse.button = 0; /* For motion events */ wayl->mouse.button = 0; /* For motion events */
switch (term->active_surface) { switch (term->active_surface) {
case TERM_SURF_NONE:
assert(false);
break;
case TERM_SURF_TITLE: case TERM_SURF_TITLE:
if (state == WL_POINTER_BUTTON_STATE_PRESSED) { if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
@ -947,8 +937,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) { if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) {
int resize_type; int resize_type;
int x = term->window->csd.x; int x = wayl->mouse.x;
int y = term->window->csd.y; int y = wayl->mouse.y;
if (is_top_left(term, x, y)) if (is_top_left(term, x, y))
resize_type = XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT; resize_type = XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT;
@ -967,52 +957,60 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
return; return;
} }
case TERM_SURF_GRID:
case TERM_SURF_SEARCH: case TERM_SURF_SEARCH:
break; break;
}
assert(term->active_surface == TERM_SURF_GRID); case TERM_SURF_GRID: {
search_cancel(term);
search_cancel(term); switch (state) {
case WL_POINTER_BUTTON_STATE_PRESSED: {
if (button == BTN_LEFT) {
switch (wayl->mouse.count) {
case 1:
selection_start(
term, wayl->mouse.col, wayl->mouse.row,
wayl->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL);
break;
switch (state) { case 2:
case WL_POINTER_BUTTON_STATE_PRESSED: { selection_mark_word(term, wayl->mouse.col, wayl->mouse.row,
if (button == BTN_LEFT) { wayl->kbd.ctrl, serial);
switch (wayl->mouse.count) { break;
case 1:
selection_start(
term, wayl->mouse.col, wayl->mouse.row,
wayl->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL);
break;
case 2: case 3:
selection_mark_word(term, wayl->mouse.col, wayl->mouse.row, selection_mark_row(term, wayl->mouse.row, serial);
wayl->kbd.ctrl, serial); break;
break; }
} else {
case 3: if (wayl->mouse.count == 1 && button == BTN_MIDDLE &&
selection_mark_row(term, wayl->mouse.row, serial); selection_enabled(term))
break; {
selection_from_primary(term);
}
selection_cancel(term);
} }
} else {
if (wayl->mouse.count == 1 && button == BTN_MIDDLE && selection_enabled(term)) term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col);
selection_from_primary(term); break;
selection_cancel(term);
} }
term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col); case WL_POINTER_BUTTON_STATE_RELEASED:
if (button != BTN_LEFT || term->selection.end.col == -1)
selection_cancel(term);
else
selection_finalize(term, serial);
term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col);
break;
}
break; break;
} }
case WL_POINTER_BUTTON_STATE_RELEASED: case TERM_SURF_NONE:
if (button != BTN_LEFT || term->selection.end.col == -1) assert(false);
selection_cancel(term);
else
selection_finalize(term, serial);
term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col);
break; break;
} }
} }

View file

@ -105,8 +105,6 @@ struct wl_window {
struct { struct {
struct wl_surface *surface[5]; struct wl_surface *surface[5];
struct wl_subsurface *sub_surface[5]; struct wl_subsurface *sub_surface[5];
int x, y;
int move_timeout_fd; int move_timeout_fd;
uint32_t serial; uint32_t serial;
} csd; } csd;
@ -182,6 +180,8 @@ struct wayland {
} pointer; } pointer;
struct { struct {
int x;
int y;
int col; int col;
int row; int row;
int button; int button;