Skip to content

Commit

Permalink
update selection on pointer enter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan Pigott authored and emersion committed Aug 3, 2020
1 parent 809cf0a commit 24d30b7
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ static void move_seat(struct slurp_seat *seat, wl_fixed_t surface_x,
current_selection->y = y;
}

static void seat_update_selection(struct slurp_seat *seat) {
seat->pointer_selection.has_selection = false;

// find smallest box intersecting the cursor
struct slurp_box *box;
wl_list_for_each(box, &seat->state->boxes, link) {
if (in_box(box, seat->pointer_selection.x,
seat->pointer_selection.y)) {
if (seat->pointer_selection.has_selection &&
box_size(
&seat->pointer_selection.selection) <
box_size(box)) {
continue;
}
seat->pointer_selection.selection = *box;
seat->pointer_selection.has_selection = true;
}
}
}

static void seat_set_outputs_dirty(struct slurp_seat *seat) {
struct slurp_output *output;
wl_list_for_each(output, &seat->state->outputs, link) {
Expand All @@ -88,6 +108,8 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
seat->pointer_selection.current_output = output;

move_seat(seat, surface_x, surface_y, &seat->pointer_selection);
seat_update_selection(seat);
seat_set_outputs_dirty(seat);

wl_surface_set_buffer_scale(seat->cursor_surface, output->scale);
wl_surface_attach(seat->cursor_surface,
Expand Down Expand Up @@ -130,23 +152,7 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,

switch (seat->button_state) {
case WL_POINTER_BUTTON_STATE_RELEASED:
seat->pointer_selection.has_selection = false;

// find smallest box intersecting the cursor
struct slurp_box *box;
wl_list_for_each(box, &seat->state->boxes, link) {
if (in_box(box, seat->pointer_selection.x,
seat->pointer_selection.y)) {
if (seat->pointer_selection.has_selection &&
box_size(
&seat->pointer_selection.selection) <
box_size(box)) {
continue;
}
seat->pointer_selection.selection = *box;
seat->pointer_selection.has_selection = true;
}
}
seat_update_selection(seat);
break;
case WL_POINTER_BUTTON_STATE_PRESSED:;
handle_active_selection_motion(seat, &seat->pointer_selection);
Expand Down

0 comments on commit 24d30b7

Please sign in to comment.