Skip to content

Commit

Permalink
got rid of checking active selection
Browse files Browse the repository at this point in the history
  • Loading branch information
gg-rewrite committed Apr 14, 2020
1 parent d03a8ef commit b3be2eb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 51 deletions.
1 change: 0 additions & 1 deletion include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 19 additions & 42 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
13 changes: 5 additions & 8 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
&current_selection->selection)) {
continue;
Expand Down

0 comments on commit b3be2eb

Please sign in to comment.