Skip to content

Commit 16c188f

Browse files
committed
Fix "selection cancelled" with single touches
1 parent fc921b6 commit 16c188f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

main.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,23 @@ static void move_seat(struct slurp_seat *seat, wl_fixed_t surface_x,
7070
current_selection->y = y;
7171
}
7272

73-
static void seat_update_selection(struct slurp_seat *seat) {
74-
seat->pointer_selection.has_selection = false;
73+
static void seat_update_selection(struct slurp_seat *seat,
74+
struct slurp_selection *current_selection) {
75+
current_selection->has_selection = false;
7576

7677
// find smallest box intersecting the cursor
7778
struct slurp_box *box;
7879
wl_list_for_each(box, &seat->state->boxes, link) {
79-
if (in_box(box, seat->pointer_selection.x,
80-
seat->pointer_selection.y)) {
81-
if (seat->pointer_selection.has_selection &&
80+
if (in_box(box, current_selection->x,
81+
current_selection->y)) {
82+
if (current_selection->has_selection &&
8283
box_size(
83-
&seat->pointer_selection.selection) <
84+
&current_selection->selection) <
8485
box_size(box)) {
8586
continue;
8687
}
87-
seat->pointer_selection.selection = *box;
88-
seat->pointer_selection.has_selection = true;
88+
current_selection->selection = *box;
89+
current_selection->has_selection = true;
8990
}
9091
}
9192
}
@@ -147,7 +148,7 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
147148

148149
switch (seat->button_state) {
149150
case WL_POINTER_BUTTON_STATE_RELEASED:
150-
seat_update_selection(seat);
151+
seat_update_selection(seat, &seat->pointer_selection);
151152
break;
152153
case WL_POINTER_BUTTON_STATE_PRESSED:;
153154
handle_active_selection_motion(seat, &seat->pointer_selection);
@@ -194,7 +195,7 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
194195

195196
switch (seat->button_state) {
196197
case WL_POINTER_BUTTON_STATE_RELEASED:
197-
seat_update_selection(seat);
198+
seat_update_selection(seat, &seat->pointer_selection);
198199
break;
199200
case WL_POINTER_BUTTON_STATE_PRESSED:;
200201
handle_active_selection_motion(seat, &seat->pointer_selection);
@@ -376,6 +377,7 @@ static void touch_handle_down(void *data, struct wl_touch *touch,
376377
seat->touch_selection.current_output =
377378
output_from_surface(seat->state, surface);
378379
move_seat(seat, x, y, &seat->touch_selection);
380+
seat_update_selection(seat, &seat->touch_selection);
379381
handle_selection_start(seat, &seat->touch_selection);
380382
}
381383
}
@@ -388,6 +390,9 @@ static void touch_clear_state(struct slurp_seat *seat) {
388390
static void touch_handle_up(void *data, struct wl_touch *touch, uint32_t serial,
389391
uint32_t time, int32_t id) {
390392
struct slurp_seat *seat = data;
393+
if (!seat->touch_selection.has_selection) {
394+
seat_update_selection(seat, &seat->touch_selection);
395+
};
391396
handle_selection_end(seat, &seat->touch_selection);
392397
touch_clear_state(seat);
393398
}

0 commit comments

Comments
 (0)