diff --git a/include/slurp.h b/include/slurp.h index 17d4321..94bcf2f 100644 --- a/include/slurp.h +++ b/include/slurp.h @@ -107,5 +107,4 @@ struct slurp_seat { }; bool box_intersect(const struct slurp_box *a, const struct slurp_box *b); -struct slurp_selection* seat_get_current_selection(struct slurp_seat *seat); #endif diff --git a/main.c b/main.c index 4dacfca..83a6171 100644 --- a/main.c +++ b/main.c @@ -26,26 +26,12 @@ bool box_intersect(const struct slurp_box *a, const struct slurp_box *b) { a->height + a->y > b->y; } -struct slurp_selection *seat_get_current_selection(struct slurp_seat *seat) { - if (seat->pointer_selection.has_selection) { - return &seat->pointer_selection; - } else if (seat->touch_selection.has_selection) { - return &seat->touch_selection; - } else { - return NULL; - } -} - static struct slurp_output *output_from_surface(struct slurp_state *state, struct wl_surface *surface); static void move_seat(struct slurp_seat *seat, wl_fixed_t surface_x, - wl_fixed_t surface_y) { - struct slurp_selection *current_selection = - seat_get_current_selection(seat); - if (current_selection == NULL) { - current_selection = &seat->pointer_selection; - } + wl_fixed_t surface_y, + struct slurp_selection *current_selection) { int x = wl_fixed_to_int(surface_x) + current_selection->current_output->logical_geometry.x; int y = wl_fixed_to_int(surface_y) + current_selection->current_output->logical_geometry.y; @@ -70,7 +56,7 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, // TODO: handle multiple overlapping outputs seat->pointer_selection.current_output = output; - move_seat(seat, surface_x, surface_y); + move_seat(seat, surface_x, surface_y, &seat->pointer_selection); wl_surface_set_buffer_scale(seat->cursor_surface, output->scale); wl_surface_attach(seat->cursor_surface, @@ -120,15 +106,9 @@ static int max(int a, int b) { return (a > b) ? a : b; } -static void handle_active_selection_motion(struct slurp_seat *seat) { - struct slurp_selection *current_selection = - seat_get_current_selection(seat); - if (current_selection == NULL) { - return; - } +static void handle_active_selection_motion(struct slurp_seat *seat, struct slurp_selection *current_selection) { int32_t anchor_x = max(0, current_selection->anchor_x); int32_t anchor_y = max(0, current_selection->anchor_y); - //current_selection->has_selection = true; current_selection->selection.x = min(anchor_x, current_selection->x); current_selection->selection.y = min(anchor_y, current_selection->y); // selection includes the seat and anchor positions @@ -146,7 +126,7 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, seat_set_outputs_dirty(seat); } - move_seat(seat, surface_x, surface_y); + move_seat(seat, surface_x, surface_y, &seat->pointer_selection); switch (seat->button_state) { case WL_POINTER_BUTTON_STATE_RELEASED: @@ -169,7 +149,7 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, } break; case WL_POINTER_BUTTON_STATE_PRESSED:; - handle_active_selection_motion(seat); + handle_active_selection_motion(seat, &seat->pointer_selection); break; } @@ -178,12 +158,11 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, } } -static void handle_selection_start(struct slurp_seat *seat) { +static void handle_selection_start(struct slurp_seat *seat, + struct slurp_selection *current_selection) { struct slurp_state *state = seat->state; - struct slurp_selection *current_selection = seat_get_current_selection(seat); - if (current_selection == NULL) { - return; - } + current_selection->has_selection = true; + if (state->single_point) { state->result.x = current_selection->x; state->result.y = current_selection->y; @@ -195,8 +174,8 @@ static void handle_selection_start(struct slurp_seat *seat) { } } -static void handle_selection_end(struct slurp_seat *seat) { - struct slurp_selection *current_selection = seat_get_current_selection(seat); +static void handle_selection_end(struct slurp_seat *seat, + struct slurp_selection *current_selection) { struct slurp_state *state = seat->state; if (state->single_point) { return; @@ -219,11 +198,10 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, switch (button_state) { case WL_POINTER_BUTTON_STATE_PRESSED: - seat->pointer_selection.has_selection = true; - handle_selection_start(seat); + handle_selection_start(seat, &seat->pointer_selection); break; case WL_POINTER_BUTTON_STATE_RELEASED: - handle_selection_end(seat); + handle_selection_end(seat, &seat->pointer_selection); break; } } @@ -326,9 +304,8 @@ static void touch_handle_down(void *data, struct wl_touch *touch, seat->touch_id = id; seat->touch_selection.current_output = output_from_surface(seat->state, surface); - seat->touch_selection.has_selection = true; - move_seat(seat, x, y); - handle_selection_start(seat); + move_seat(seat, x, y, &seat->touch_selection); + handle_selection_start(seat, &seat->touch_selection); } } @@ -340,7 +317,7 @@ static void touch_clear_state(struct slurp_seat *seat) { static void touch_handle_up(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time, int32_t id) { struct slurp_seat *seat = data; - handle_selection_end(seat); + handle_selection_end(seat, &seat->touch_selection); touch_clear_state(seat); } @@ -349,8 +326,8 @@ static void touch_handle_motion(void *data, struct wl_touch *touch, wl_fixed_t y) { struct slurp_seat *seat = data; if (seat->touch_id == id) { - move_seat(seat, x, y); - handle_active_selection_motion(seat); + move_seat(seat, x, y, &seat->touch_selection); + handle_active_selection_motion(seat, &seat->touch_selection); seat_set_outputs_dirty(seat); } } diff --git a/render.c b/render.c index b8df0da..bf0afe7 100644 --- a/render.c +++ b/render.c @@ -27,17 +27,14 @@ void render(struct slurp_output *output) { struct slurp_seat *seat; wl_list_for_each(seat, &state->seats, link) { struct slurp_selection *current_selection = - seat_get_current_selection(seat); - if (current_selection == NULL) { - continue; - } + (seat->touch_selection.has_selection) ? + (&seat->touch_selection) : + (&seat->pointer_selection); + if (!seat->wl_pointer) { continue; } - if (!current_selection->has_selection) { - continue; - } - + if (!box_intersect(&output->logical_geometry, ¤t_selection->selection)) { continue;