util/box.c: use 1/256 instead of 1/65536 in wlr_box_closest_point()

This fixes the issue that a scrollbar in a maximized GTK/Chromium window
cannot be dragged when cursor is on the right/bottom edge of the output.

The issue was caused by rounding in `wl_fixed_from_double()` ([1]); if
`wlr_cursor_move()` constrains the x-position of the cursor to
`(output width)-1/65536`, `wl_fixed_from_double()` converts it to just
`(output width)`, which is perceived as outside of the window by
GTK/Chromium.

Using 1/256 (minimal unit of `wl_fixed_t`) instead of 1/65536 avoids
this rounding issue.

[1]: f246e619d1
This commit is contained in:
tokyo4j 2025-09-23 23:44:52 +09:00 committed by Simon Ser
parent 06275103f2
commit 19c5d22beb

View file

@ -19,16 +19,15 @@ void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
// //
// In order to be consistent with e.g. wlr_box_contains_point(), // In order to be consistent with e.g. wlr_box_contains_point(),
// this function returns a point inside the bottom and right edges // this function returns a point inside the bottom and right edges
// of the box by at least 1/65536 of a unit (pixel). 1/65536 is // of the box by at least 1/256 of a unit (pixel). 1/256 is
// small enough to avoid a "dead zone" with high-resolution mice // small enough to avoid a "dead zone" with high-resolution mice
// but large enough to avoid rounding to zero (due to loss of // but large enough to avoid rounding to zero in wl_fixed_from_double().
// significant digits) in simple floating-point calculations.
// find the closest x point // find the closest x point
if (x < box->x) { if (x < box->x) {
*dest_x = box->x; *dest_x = box->x;
} else if (x > box->x + box->width - 1/65536.0) { } else if (x > box->x + box->width - 1/256.0) {
*dest_x = box->x + box->width - 1/65536.0; *dest_x = box->x + box->width - 1/256.0;
} else { } else {
*dest_x = x; *dest_x = x;
} }
@ -36,8 +35,8 @@ void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
// find closest y point // find closest y point
if (y < box->y) { if (y < box->y) {
*dest_y = box->y; *dest_y = box->y;
} else if (y > box->y + box->height - 1/65536.0) { } else if (y > box->y + box->height - 1/256.0) {
*dest_y = box->y + box->height - 1/65536.0; *dest_y = box->y + box->height - 1/256.0;
} else { } else {
*dest_y = y; *dest_y = y;
} }