diff --git a/types/wlr_box.c b/types/wlr_box.c index 0020b7a4..b43252b3 100644 --- a/types/wlr_box.c +++ b/types/wlr_box.c @@ -8,6 +8,13 @@ void wlr_box_closest_point(const struct wlr_box *box, double x, double y, double *dest_x, double *dest_y) { + // if box is empty, then it contains no points, so no closest point either + if (box->width <= 0 || box->height <= 0) { + *dest_x = NAN; + *dest_y = NAN; + return; + } + // find the closest x point if (x < box->x) { *dest_x = box->x; diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index 03660917..680e405c 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -278,6 +278,10 @@ void wlr_cursor_warp_closest(struct wlr_cursor *cur, struct wlr_box *mapping = get_mapping(cur, dev); if (mapping) { wlr_box_closest_point(mapping, lx, ly, &lx, &ly); + if (isnan(lx) || isnan(ly)) { + lx = 0; + ly = 0; + } } else { wlr_output_layout_closest_point(cur->state->layout, NULL, lx, ly, &lx, &ly); diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index b9882d28..64999fec 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -328,7 +328,7 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout, return; } - double min_x = DBL_MAX, min_y = DBL_MAX, min_distance = DBL_MAX; + double min_x = 0, min_y = 0, min_distance = DBL_MAX; struct wlr_output_layout_output *l_output; wl_list_for_each(l_output, &layout->outputs, link) { if (reference != NULL && reference != l_output->output) { @@ -347,7 +347,7 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout, output_distance = DBL_MAX; } - if (output_distance <= min_distance) { + if (output_distance < min_distance) { min_x = output_x; min_y = output_y; min_distance = output_distance;