Skip to content
Myr

wayland: don't ignore the mouse's X coordinate when selecting

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Before this patch, the mouse cursor's X coordinate was ignored when updating the currently selected item. This meant that you could change (and activate) items while the cursor was inside the left or right margins. It also fixes an issue where clicking *outside* the window could activate an item. This was only possible on compositors that allows sending mouse events to a client, even when the mouse is outside the window (and no buttons being held/dragged). Sounds buggy to me, but who am I to judge 🤷? Closes #606

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 5751a65 · Browse files · 5 files+37 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+37 added−22 removed

  • other:+37 added−22 removed

5 files+37 added−22 removed

modified:CHANGELOG.md+4 added
85 unmodified lines
86* Error out (with an appropriate error message) if the command line we87 attempt to execute has non-specification-compliant quoting.88* Input text now "scrolls" with the cursor, if the string is longer89 than the available space ([#378][378]).90* When using the mouse, the currently selected item is only changed91 when the mouse is over an item. Before this release, the X92 coordinate was ignored ([#606][606]).9394[560]: https://codeberg.org/dnkl/fuzzel/issues/56095[378]: https://codeberg.org/dnkl/fuzzel/issues/37896[606]: https://codeberg.org/dnkl/fuzzel/issues/606979899### Deprecated100### Removed
936 unmodified lines
modified:match.c+1 added-1 removed
695 unmodified lines
696697bool698matches_idx_select(struct matches *matches, size_t idx)699{700 if (idx == -1)700 if (idx == (size_t)-1)701 return false;702703 matches->selected = match_get_idx(matches, idx);704 return true;
961 unmodified lines
modified:render.c+9 added-8 removed
1814 unmodified lines
1815 fcft_destroy(render->font);1816 free(render);1817}18181819size_t1820render_get_row_num(const struct render *render, int y,1819ssize_t1820render_get_row_num(const struct render *render, int width, int x, int y,1821 const struct matches *matches)1822{1823 const float scale = render->scale;1823 const int y_margin = render->y_margin;1824 const int inner_pad = render->inner_pad;1825 const int border_size = render->border_size;1826 const int row_height = render->row_height;18271828 const int min_x = render->border_size + render->x_margin - render->x_margin / 3;1829 const int max_x = width - (min_x);18301831 const int first_row = 1 * border_size + y_margin +1832 (render->conf->hide_prompt ? 0 : row_height) +1833 (render->conf->hide_prompt ? 0 : inner_pad);18341835 const size_t match_count = matches_get_count(matches);1836 const size_t last_row = first_row + match_count * row_height;18371834 y = floor(scale * y);1838 ssize_t row = -1;18391836 size_t row = -1;18371838 if (y >= first_row && y < last_row) {1840 if (y >= first_row && y < last_row && x >= min_x && x < max_x)1841 row = (y - first_row) / row_height;1840 }18421843 return row;1844}1845
8 unmodified lines
modified:render.h+3 added-3 removed
35 unmodified lines
36 const struct prompt *prompt, const struct matches *matches);3738int render_icon_size(const struct render *render);3940size_t render_get_row_num(41 const struct render *render, int y,42 const struct matches *matches);40ssize_t render_get_row_num(41 const struct render *render, int window_width, int x, int y,42 const struct matches *matches);
modified:wayland.c+20 added-10 removed
1074 unmodified lines
1075static void1076select_hovered_match(struct seat *seat, bool refresh_always)1077{1078 struct wayland *wayl = seat->wayl;10791080 bool refresh = false;10811081 size_t hovered_row = render_get_row_num(1082 wayl->render, seat->pointer.y, wayl->matches);1082 ssize_t hovered_row = render_get_row_num(1083 wayl->render, wayl->width, seat->pointer.x, seat->pointer.y,1084 wayl->matches);10851086 if (hovered_row < 0)1087 return;10881089 if (hovered_row != seat->pointer.hovered_row_idx) {1090 seat->pointer.hovered_row_idx = hovered_row;1091 refresh = matches_idx_select(wayl->matches,hovered_row);1092 }
52 unmodified lines
11451146 const int old_x = seat->pointer.x;1147 const int old_y = seat->pointer.y;11481144 seat->pointer.x = x;1145 seat->pointer.y = y;1149 seat->pointer.x = round(seat->wayl->scale * x);1150 seat->pointer.y = round(seat->wayl->scale * y);11511152 if (old_x != 0 && old_y != 0)1153 select_hovered_match(seat, false);1154}
6 unmodified lines
1161 struct wayland *wayl = seat->wayl;11621163 if (state == WL_POINTER_BUTTON_STATE_RELEASED) {1164 if (button == BTN_LEFT && seat->pointer.hovered_row_idx != -1) {1165 ssize_t clicked_row = render_get_row_num(1166 wayl->render, wayl->width, seat->pointer.x, seat->pointer.y,1167 wayl->matches);11681169 if (clicked_row == seat->pointer.hovered_row_idx)1160 execute_selected(seat, false, -1);1170 execute_selected(seat, false, -1);1171 }11721173 else if (button == BTN_RIGHT) {1174 // Same as pressing ESC
103 unmodified lines
12781279 /* Tap threshold: less than 10 pixels movement and under 500ms */1280 if (distance < 10.0 && duration < 500) {1281 /* Convert touch coordinates to match selection */1282 int touch_x = (int)seat->touch.active_touch.start_x;1283 int touch_y = (int)seat->touch.active_touch.start_y;1273 size_t tapped_row = render_get_row_num(wayl->render, touch_y, wayl->matches);12841285 ssize_t tapped_row = render_get_row_num(1286 wayl->render, wayl->width, touch_x, touch_y, wayl->matches);12871288 /* If user tapped on a valid row, select and execute it */1276 if (matches_idx_select(wayl->matches, tapped_row)) {1289 if (tapped_row >= 0 && matches_idx_select(wayl->matches, tapped_row)) {1290 execute_selected(seat, false, -1);1278 } else {1279 /* Tapped on empty area or input field - focus input */1280 wayl_refresh(wayl);1291 }1292 }1293 }1294
1740 unmodified lines