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

56
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,11 +796,8 @@ 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)
return;
case TERM_SURF_GRID: {
int col = (x - term->margins.left) / term->cell_width; int col = (x - term->margins.left) / term->cell_width;
int row = (y - term->margins.top) / term->cell_height; int row = (y - term->margins.top) / term->cell_height;
@ -820,7 +811,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
selection_update(term, col, row); selection_update(term, col, row);
if (col == wayl->mouse.col && row == wayl->mouse.row) if (col == wayl->mouse.col && row == wayl->mouse.row)
return; break;
wayl->mouse.col = col; wayl->mouse.col = col;
wayl->mouse.row = row; wayl->mouse.row = row;
@ -830,6 +821,9 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
term_mouse_motion( 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,13 +957,10 @@ 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) { switch (state) {
@ -996,8 +983,11 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
break; break;
} }
} else { } else {
if (wayl->mouse.count == 1 && button == BTN_MIDDLE && selection_enabled(term)) if (wayl->mouse.count == 1 && button == BTN_MIDDLE &&
selection_enabled(term))
{
selection_from_primary(term); selection_from_primary(term);
}
selection_cancel(term); selection_cancel(term);
} }
@ -1014,6 +1004,14 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col); term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col);
break; break;
} }
break;
}
case TERM_SURF_NONE:
assert(false);
break;
}
} }
static void static void

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;