diff --git a/flake.lock b/flake.lock index 454da7a..b67d177 100644 --- a/flake.lock +++ b/flake.lock @@ -86,11 +86,11 @@ "base16-helix": { "flake": false, "locked": { - "lastModified": 1720809814, - "narHash": "sha256-numb3xigRGnr/deF7wdjBwVg7fpbTH7reFDkJ75AJkY=", + "lastModified": 1725860795, + "narHash": "sha256-Z2o8VBPW3I+KKTSfe25kskz0EUj7MpUh8u355Z1nVsU=", "owner": "tinted-theming", "repo": "base16-helix", - "rev": "34f41987bec14c0f3f6b2155c19787b1f6489625", + "rev": "7f795bf75d38e0eea9fed287264067ca187b88a9", "type": "github" }, "original": { @@ -150,11 +150,11 @@ "blocklist-hosts": { "flake": false, "locked": { - "lastModified": 1726250228, - "narHash": "sha256-2YJRNkIDqU5ruMNPiU1PvfURBE93WGPJuwBmyUJw5Ho=", + "lastModified": 1726880464, + "narHash": "sha256-xF0wgVbbL/ESCuGeXUB8W0qqZm6OJQfPmf22Ie9EMTE=", "owner": "StevenBlack", "repo": "hosts", - "rev": "c388521f8786b76abcd5d7a129aba877ac09160a", + "rev": "e7237a0bc6877ec61ec823aca830195d42b09979", "type": "github" }, "original": { @@ -538,11 +538,11 @@ ] }, "locked": { - "lastModified": 1725703823, - "narHash": "sha256-tDgM4d8mLK0Hd6YMB2w1BqMto1XBXADOzPEaLl10VI4=", + "lastModified": 1726818100, + "narHash": "sha256-z2V74f5vXqkN5Q+goFlhbFXY/dNaBAyeLpr2bxu4Eic=", "owner": "nix-community", "repo": "home-manager", - "rev": "208df2e558b73b6a1f0faec98493cb59a25f62ba", + "rev": "1bbc1a5a1f4de7401c92db85b2119ed21bb4139d", "type": "github" }, "original": { @@ -559,11 +559,11 @@ ] }, "locked": { - "lastModified": 1726308872, - "narHash": "sha256-d4vwO5N4RsLnCY7k5tY9xbdYDWQsY3RDMeUoIa4ms2A=", + "lastModified": 1726902823, + "narHash": "sha256-Gkc7pwTVLKj4HSvRt8tXNvosl8RS9hrBAEhOjAE0Tt4=", "owner": "nix-community", "repo": "home-manager", - "rev": "6c1a461a444e6ccb3f3e42bb627b510c3a722a57", + "rev": "14929f7089268481d86b83ed31ffd88713dcd415", "type": "github" }, "original": { @@ -639,7 +639,6 @@ "locked": { "lastModified": 1725814101, "narHash": "sha256-+wE97utoDfhQP6AMdZHUmBeL8grbce/Jv2i5M+6AbaE=", - "ref": "refs/heads/main", "rev": "0f594732b063a90d44df8c5d402d658f27471dfe", "revCount": 5196, "submodules": true, @@ -1068,11 +1067,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726062873, - "narHash": "sha256-IiA3jfbR7K/B5+9byVi9BZGWTD4VSbWe8VLpp9B/iYk=", + "lastModified": 1726755586, + "narHash": "sha256-PmUr/2GQGvFTIJ6/Tvsins7Q43KTMvMFhvG6oaYK+Wk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4f807e8940284ad7925ebd0a0993d2a1791acb2f", + "rev": "c04d5652cfa9742b1d519688f65d1bbccea9eb7e", "type": "github" }, "original": { @@ -1115,11 +1114,11 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1726062281, - "narHash": "sha256-PyFVySdGj3enKqm8RQuo4v1KLJLmNLOq2yYOHsI6e2Q=", + "lastModified": 1726838390, + "narHash": "sha256-NmcVhGElxDbmEWzgXsyAjlRhUus/nEqPC5So7BOJLUM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e65aa8301ba4f0ab8cb98f944c14aa9da07394f8", + "rev": "944b2aea7f0a2d7c79f72468106bc5510cbf5101", "type": "github" }, "original": { @@ -1525,11 +1524,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1726280639, - "narHash": "sha256-YfLRPlFZWrT2oRLNAoqf7G3+NnUTDdlIJk6tmBU7kXM=", + "lastModified": 1726885519, + "narHash": "sha256-wrXknshJMRLv91KQD5d7ovUqJ70FlDM7XeG/upSsKgM=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "e9f8641c92f26fd1e076e705edb12147c384171d", + "rev": "a66e16cb21e4428224925dbf1b66238c727dda0a", "type": "github" }, "original": { @@ -1587,11 +1586,11 @@ "systems": "systems_5" }, "locked": { - "lastModified": 1726170940, - "narHash": "sha256-sobkRkGBaMX9pD0bwU1iVPWi0WtQvZqlHyl1YtvNDio=", + "lastModified": 1726828291, + "narHash": "sha256-pGRPVVm7UXf+fx2NVpH6FFSWR9AynG6eoVlagaqH9i4=", "owner": "danth", "repo": "stylix", - "rev": "35233f929629c8eb64e939e35260fc8347f94df9", + "rev": "53bcceb4e46d0b3e8ae6434a7a6bcc3463092093", "type": "github" }, "original": { diff --git a/user/wm/hyprland/hyprland.nix b/user/wm/hyprland/hyprland.nix index 4df342e..f5fdd4e 100644 --- a/user/wm/hyprland/hyprland.nix +++ b/user/wm/hyprland/hyprland.nix @@ -1323,9 +1323,7 @@ in services.udiskie.enable = true; services.udiskie.tray = "always"; programs.fuzzel.enable = true; - programs.fuzzel.package = pkgs.fuzzel.overrideAttrs (oldAttrs: { - patches = ./patches/fuzzelmouseinput.patch; - }); + programs.fuzzel.package = pkgs.fuzzel; programs.fuzzel.settings = { main = { font = userSettings.font + ":size=20"; diff --git a/user/wm/hyprland/patches/fuzzelmouseinput.patch b/user/wm/hyprland/patches/fuzzelmouseinput.patch deleted file mode 100644 index 0264ac1..0000000 --- a/user/wm/hyprland/patches/fuzzelmouseinput.patch +++ /dev/null @@ -1,1053 +0,0 @@ -From 7cc9f3147438fe7dd0062172f46aed415f024464 Mon Sep 17 00:00:00 2001 -From: alz -Date: Mon, 22 Jul 2024 00:43:56 -0400 -Subject: [PATCH 1/7] implemented left click, right click and scroll wheel - listeners - ---- - match.c | 24 ++++++++++++++++++++++++ - match.h | 1 + - render.c | 19 +++++++++++++++++++ - render.h | 2 ++ - wayland.c | 38 ++++++++++++++++++++++++++++++++++++++ - 5 files changed, 84 insertions(+) - -diff --git a/match.c b/match.c -index 5a26000..7d5efaf 100644 ---- a/match.c -+++ b/match.c -@@ -359,6 +359,30 @@ matches_selected_select(struct matches *matches, const char *_string) - return false; - } - -+bool -+matches_selected_select_idx(struct matches *matches, size_t idx) -+{ -+ const size_t page_no = matches_get_page(matches); -+ const size_t items_on_page __attribute__((unused)) = matches_get_count(matches); -+ -+ LOG_DBG( -+ "page-count: %zu, page-no: %zu, items-on-page: %zu, idx: %zu, max: %zu, " -+ "match-count: %zu", -+ matches->page_count, page_no, items_on_page, idx, -+ matches->max_matches_per_page, matches->match_count); -+ -+ if (idx >= items_on_page) -+ return false; -+ -+ idx += page_no * matches->max_matches_per_page; -+ -+ if (idx >= matches->match_count) -+ return false; -+ -+ matches->selected = idx; -+ return true; -+} -+ - bool - matches_selected_first(struct matches *matches) - { -diff --git a/match.h b/match.h -index 4100881..871635b 100644 ---- a/match.h -+++ b/match.h -@@ -53,6 +53,7 @@ size_t matches_get_total_count(const struct matches *matches); - size_t matches_get_match_index(const struct matches *matches); - - bool matches_selected_select(struct matches *matches, const char *string); -+bool matches_selected_select_idx(struct matches *matches, size_t idx); - - bool matches_selected_first(struct matches *matches); - bool matches_selected_last(struct matches *matches); -diff --git a/render.c b/render.c -index 403d7c9..3bc507c 100644 ---- a/render.c -+++ b/render.c -@@ -873,3 +873,22 @@ render_destroy(struct render *render) - fcft_destroy(render->font); - free(render); - } -+ -+int render_get_row_num(const struct render *render, int y) -+{ -+ const float scale = render->scale; -+ const int y_margin = render->y_margin; -+ const int inner_pad = render->inner_pad; -+ const int border_size = render->border_size; -+ const int row_height = render->row_height; -+ const int first_row = 1 * border_size + y_margin + row_height + inner_pad; -+ -+ y = floor(scale * y); -+ -+ if (y <= first_row) { -+ return -1; -+ } else { -+ y -= first_row; -+ return y / row_height; -+ } -+} -diff --git a/render.h b/render.h -index c097882..1f934f5 100644 ---- a/render.h -+++ b/render.h -@@ -30,3 +30,5 @@ void render_match_list( - const struct prompt *prompt, const struct matches *matches); - - int render_icon_size(const struct render *render); -+ -+int render_get_row_num(const struct render *render, int y); -diff --git a/wayland.c b/wayland.c -index 15f9e05..c2cf6a6 100644 ---- a/wayland.c -+++ b/wayland.c -@@ -1062,18 +1062,56 @@ static void - wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, - uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) - { -+ struct seat *seat = data; -+ struct wayland *wayl = seat->wayl; -+ bool refresh = false; -+ -+ refresh = matches_selected_select_idx(wayl->matches, -+ render_get_row_num(wayl->render, wl_fixed_to_int(surface_y))); -+ -+ if (refresh) { -+ wayl_refresh(wayl); -+ } - } - - static void - wl_pointer_button(void *data, struct wl_pointer *wl_pointer, - uint32_t serial, uint32_t time, uint32_t button, uint32_t state) - { -+ struct seat *seat = data; -+ struct wayland *wayl = seat->wayl; -+ -+ // Button release -+ if (state == 0) { -+ // Left click -+ if (button == 272) { -+ execute_selected(seat, false, -1); -+ // Right click -+ } else if (button == 273) { -+ wayl->status = EXIT; -+ if (wayl->conf->dmenu.enabled) -+ wayl->exit_code = 2; -+ } -+ } - } - - static void - wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, - uint32_t time, uint32_t axis, wl_fixed_t value) - { -+ struct seat *seat = data; -+ struct wayland *wayl = seat->wayl; -+ -+ bool refresh = false; -+ if (value < 0) { -+ refresh = matches_selected_prev_page(wayl->matches); -+ } else if (value > 0) { -+ refresh = matches_selected_next_page(wayl->matches); -+ } -+ -+ if (refresh) { -+ wayl_refresh(wayl); -+ } - } - - static void --- -2.39.2 - - -From e023c4f6ceb8bd0fa9b5b1ed2b23af123c2811ed Mon Sep 17 00:00:00 2001 -From: alz -Date: Mon, 22 Jul 2024 01:07:56 -0400 -Subject: [PATCH 2/7] put the mouse stuff behind a config - ---- - config.c | 4 ++++ - config.h | 2 ++ - doc/fuzzel.1.scd | 4 ++++ - doc/fuzzel.ini.5.scd | 3 +++ - main.c | 10 ++++++++ - match.c | 4 ++++ - wayland.c | 54 +++++++++++++++++++++++++------------------- - 7 files changed, 58 insertions(+), 23 deletions(-) - -diff --git a/config.c b/config.c -index e236142..21aab3a 100644 ---- a/config.c -+++ b/config.c -@@ -778,6 +778,9 @@ parse_section_main(struct context *ctx) - else if (strcmp(key, "list-executables-in-path") == 0) - return value_to_bool(ctx, &conf->list_executables_in_path); - -+ else if (strcmp(key, "mouse-listener") == 0) -+ return value_to_bool(ctx, &conf->mouse_listener); -+ - else if (strcmp(key, "fields") == 0) { - _Static_assert(sizeof(conf->match_fields) == sizeof(int), - "enum is not 32-bit"); -@@ -1572,6 +1575,7 @@ config_load(struct config *conf, const char *conf_path, - .layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP, - .exit_on_kb_focus_loss = true, - .list_executables_in_path = false, -+ .mouse_listener = false, - }; - - add_default_key_bindings(conf); -diff --git a/config.h b/config.h -index a52976c..99d3a52 100644 ---- a/config.h -+++ b/config.h -@@ -170,6 +170,8 @@ struct config { - bool exit_on_kb_focus_loss; - - bool list_executables_in_path; -+ -+ bool mouse_listener; - }; - - typedef tll(char *) config_override_t; -diff --git a/doc/fuzzel.1.scd b/doc/fuzzel.1.scd -index c46d9af..791a5e6 100644 ---- a/doc/fuzzel.1.scd -+++ b/doc/fuzzel.1.scd -@@ -302,6 +302,10 @@ or command line options: - *--log-no-syslog* - Disables syslog logging. Logging is only done on stderr. - -+*--mouse* -+ Allows choosing items with mouse left click, and cancelling fuzzel with -+ right click. -+ - *-v*,*--version* - Show the version number and quit - -diff --git a/doc/fuzzel.ini.5.scd b/doc/fuzzel.ini.5.scd -index e3dfc05..ee6a2c5 100644 ---- a/doc/fuzzel.ini.5.scd -+++ b/doc/fuzzel.ini.5.scd -@@ -411,6 +411,9 @@ done by setting _action=none_; e.g. *delete-line-forward=none*. - *last* - Select the last entry, on the last page. Default: _Control+End_. - -+*mouse-listener* -+ Allows selecting elements with the mouse -+ - *custom-1*, *custom-2*, ..., *custom-19* - Execute the currently selected entry, then exit with a non-zero - exit code. *custom-1* exits with exit code 10, *custom-2* with 11, -diff --git a/match.c b/match.c -index 7d5efaf..fe3903a 100644 ---- a/match.c -+++ b/match.c -@@ -362,6 +362,9 @@ matches_selected_select(struct matches *matches, const char *_string) - bool - matches_selected_select_idx(struct matches *matches, size_t idx) - { -+ if (idx < 0) -+ return false; -+ - const size_t page_no = matches_get_page(matches); - const size_t items_on_page __attribute__((unused)) = matches_get_count(matches); - -@@ -371,6 +374,7 @@ matches_selected_select_idx(struct matches *matches, size_t idx) - matches->page_count, page_no, items_on_page, idx, - matches->max_matches_per_page, matches->match_count); - -+ - if (idx >= items_on_page) - return false; - -diff --git a/wayland.c b/wayland.c -index c2cf6a6..8fff785 100644 ---- a/wayland.c -+++ b/wayland.c -@@ -1064,13 +1064,16 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, - { - struct seat *seat = data; - struct wayland *wayl = seat->wayl; -- bool refresh = false; - -- refresh = matches_selected_select_idx(wayl->matches, -- render_get_row_num(wayl->render, wl_fixed_to_int(surface_y))); -+ if (wayl->conf->mouse_listener) { -+ bool refresh = false; - -- if (refresh) { -- wayl_refresh(wayl); -+ refresh = matches_selected_select_idx(wayl->matches, -+ render_get_row_num(wayl->render, wl_fixed_to_int(surface_y))); -+ -+ if (refresh) { -+ wayl_refresh(wayl); -+ } - } - } - -@@ -1081,16 +1084,18 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, - struct seat *seat = data; - struct wayland *wayl = seat->wayl; - -- // Button release -- if (state == 0) { -- // Left click -- if (button == 272) { -- execute_selected(seat, false, -1); -- // Right click -- } else if (button == 273) { -- wayl->status = EXIT; -- if (wayl->conf->dmenu.enabled) -- wayl->exit_code = 2; -+ if (wayl->conf->mouse_listener) { -+ // Button release -+ if (state == 0) { -+ // Left click -+ if (button == 0x110) { -+ execute_selected(seat, false, -1); -+ // Right click -+ } else if (button == 0x111) { -+ wayl->status = EXIT; -+ if (wayl->conf->dmenu.enabled) -+ wayl->exit_code = 2; -+ } - } - } - } -@@ -1102,15 +1107,18 @@ wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, - struct seat *seat = data; - struct wayland *wayl = seat->wayl; - -- bool refresh = false; -- if (value < 0) { -- refresh = matches_selected_prev_page(wayl->matches); -- } else if (value > 0) { -- refresh = matches_selected_next_page(wayl->matches); -- } -+ if (wayl->conf->mouse_listener) { -+ bool refresh = false; - -- if (refresh) { -- wayl_refresh(wayl); -+ if (value < 0) { -+ refresh = matches_selected_prev_page(wayl->matches); -+ } else if (value > 0) { -+ refresh = matches_selected_next_page(wayl->matches); -+ } -+ -+ if (refresh) { -+ wayl_refresh(wayl); -+ } - } - } - --- -2.39.2 - - -From 9e04a13fa2a6b442faaa1451700e04000f24734b Mon Sep 17 00:00:00 2001 -From: alz -Date: Mon, 22 Jul 2024 12:00:43 -0400 -Subject: [PATCH 3/7] Ignoring left clicks if they're in the prompt row - ---- - wayland.c | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/wayland.c b/wayland.c -index 8fff785..e7c0c2c 100644 ---- a/wayland.c -+++ b/wayland.c -@@ -1068,6 +1068,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, - if (wayl->conf->mouse_listener) { - bool refresh = false; - -+ seat->pointer.y = wl_fixed_to_int(surface_y); -+ - refresh = matches_selected_select_idx(wayl->matches, - render_get_row_num(wayl->render, wl_fixed_to_int(surface_y))); - -@@ -1088,7 +1090,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, - // Button release - if (state == 0) { - // Left click -- if (button == 0x110) { -+ if (button == 0x110 && render_get_row_num(wayl->render, seat->pointer.y) >= 0) { - execute_selected(seat, false, -1); - // Right click - } else if (button == 0x111) { --- -2.39.2 - - -From 607edc371b7ee48ec194ec2ce561d8e10d49923a Mon Sep 17 00:00:00 2001 -From: alz -Date: Mon, 22 Jul 2024 13:18:43 -0400 -Subject: [PATCH 4/7] Refactored so the data types are correct - ---- - match.c | 36 ++++++++++++------------------------ - render.c | 14 +++++++++----- - render.h | 2 +- - wayland.c | 28 +++++++++++++++++----------- - 4 files changed, 39 insertions(+), 41 deletions(-) - -diff --git a/match.c b/match.c -index fe3903a..a16f903 100644 ---- a/match.c -+++ b/match.c -@@ -278,8 +278,8 @@ matches_get_page(const struct matches *matches) - : matches->selected; - } - --const struct match * --matches_get(const struct matches *matches, size_t idx) -+size_t -+match_get_idx(const struct matches *matches, size_t idx) - { - const size_t page_no = matches_get_page(matches); - const size_t items_on_page __attribute__((unused)) = matches_get_count(matches); -@@ -290,11 +290,17 @@ matches_get(const struct matches *matches, size_t idx) - matches->page_count, page_no, items_on_page, idx, - matches->max_matches_per_page, matches->match_count); - -- assert(idx < items_on_page); -+ assert(idx >= 0 && idx < items_on_page); - idx += page_no * matches->max_matches_per_page; - - assert(idx < matches->match_count); -- return &matches->matches[idx]; -+ return idx; -+} -+ -+const struct match * -+matches_get(const struct matches *matches, size_t idx) -+{ -+ return &matches->matches[match_get_idx(matches, idx)]; - } - - const struct match * -@@ -362,28 +368,10 @@ matches_selected_select(struct matches *matches, const char *_string) - bool - matches_selected_select_idx(struct matches *matches, size_t idx) - { -- if (idx < 0) -+ if (idx == -1) - return false; - -- const size_t page_no = matches_get_page(matches); -- const size_t items_on_page __attribute__((unused)) = matches_get_count(matches); -- -- LOG_DBG( -- "page-count: %zu, page-no: %zu, items-on-page: %zu, idx: %zu, max: %zu, " -- "match-count: %zu", -- matches->page_count, page_no, items_on_page, idx, -- matches->max_matches_per_page, matches->match_count); -- -- -- if (idx >= items_on_page) -- return false; -- -- idx += page_no * matches->max_matches_per_page; -- -- if (idx >= matches->match_count) -- return false; -- -- matches->selected = idx; -+ matches->selected = match_get_idx(matches, idx); - return true; - } - -diff --git a/render.c b/render.c -index 3bc507c..1dcefc9 100644 ---- a/render.c -+++ b/render.c -@@ -874,7 +874,8 @@ render_destroy(struct render *render) - free(render); - } - --int render_get_row_num(const struct render *render, int y) -+size_t -+render_get_row_num(const struct render *render, int y, size_t match_count) - { - const float scale = render->scale; - const int y_margin = render->y_margin; -@@ -882,13 +883,16 @@ int render_get_row_num(const struct render *render, int y) - const int border_size = render->border_size; - const int row_height = render->row_height; - const int first_row = 1 * border_size + y_margin + row_height + inner_pad; -+ const int last_row = first_row + match_count*row_height; - - y = floor(scale * y); - -- if (y <= first_row) { -- return -1; -- } else { -+ size_t row = -1; -+ -+ if (y >= first_row && y < last_row) { - y -= first_row; -- return y / row_height; -+ row = y / row_height; - } -+ -+ return row; - } -diff --git a/render.h b/render.h -index 1f934f5..c257004 100644 ---- a/render.h -+++ b/render.h -@@ -31,4 +31,4 @@ void render_match_list( - - int render_icon_size(const struct render *render); - --int render_get_row_num(const struct render *render, int y); -+size_t render_get_row_num(const struct render *render, int y, size_t match_count); -diff --git a/wayland.c b/wayland.c -index e7c0c2c..56ff829 100644 ---- a/wayland.c -+++ b/wayland.c -@@ -1058,6 +1058,19 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, - seat->pointer.serial = serial; - } - -+static void -+select_hovered_match(struct wayland *wayl, int y) -+{ -+ bool refresh = false; -+ -+ refresh = matches_selected_select_idx(wayl->matches, -+ render_get_row_num(wayl->render, y, matches_get_count(wayl->matches))); -+ -+ if (refresh) { -+ wayl_refresh(wayl); -+ } -+} -+ - static void - wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, - uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) -@@ -1066,16 +1079,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, - struct wayland *wayl = seat->wayl; - - if (wayl->conf->mouse_listener) { -- bool refresh = false; -- - seat->pointer.y = wl_fixed_to_int(surface_y); -- -- refresh = matches_selected_select_idx(wayl->matches, -- render_get_row_num(wayl->render, wl_fixed_to_int(surface_y))); -- -- if (refresh) { -- wayl_refresh(wayl); -- } -+ select_hovered_match(wayl, seat->pointer.y); - } - } - -@@ -1090,7 +1095,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, - // Button release - if (state == 0) { - // Left click -- if (button == 0x110 && render_get_row_num(wayl->render, seat->pointer.y) >= 0) { -+ if (button == 0x110 && -+ render_get_row_num(wayl->render, seat->pointer.y, matches_get_count(wayl->matches)) != -1) { - execute_selected(seat, false, -1); - // Right click - } else if (button == 0x111) { -@@ -1119,7 +1125,7 @@ wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, - } - - if (refresh) { -- wayl_refresh(wayl); -+ select_hovered_match(wayl, seat->pointer.y); - } - } - } --- -2.39.2 - - -From f4d4918ebd6b996deff617c2750000904d1f2d29 Mon Sep 17 00:00:00 2001 -From: alz -Date: Mon, 22 Jul 2024 13:37:03 -0400 -Subject: [PATCH 5/7] made the hovered row index an attribute of the seat - pointer - ---- - wayland.c | 20 +++++++++++--------- - 1 file changed, 11 insertions(+), 9 deletions(-) - -diff --git a/wayland.c b/wayland.c -index 56ff829..ab88598 100644 ---- a/wayland.c -+++ b/wayland.c -@@ -148,6 +148,8 @@ struct seat { - struct wl_cursor_theme *theme; - struct wl_cursor *cursor; - float scale; -+ -+ size_t hovered_row_idx; - } pointer; - }; - -@@ -1059,12 +1061,10 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, - } - - static void --select_hovered_match(struct wayland *wayl, int y) -+select_hovered_match(struct wayland *wayl, size_t idx) - { - bool refresh = false; -- -- refresh = matches_selected_select_idx(wayl->matches, -- render_get_row_num(wayl->render, y, matches_get_count(wayl->matches))); -+ refresh = matches_selected_select_idx(wayl->matches,idx); - - if (refresh) { - wayl_refresh(wayl); -@@ -1079,8 +1079,11 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, - struct wayland *wayl = seat->wayl; - - if (wayl->conf->mouse_listener) { -- seat->pointer.y = wl_fixed_to_int(surface_y); -- select_hovered_match(wayl, seat->pointer.y); -+ seat->pointer.hovered_row_idx = -+ render_get_row_num(wayl->render, -+ wl_fixed_to_int(surface_y), -+ matches_get_count(wayl->matches)); -+ select_hovered_match(wayl, seat->pointer.hovered_row_idx); - } - } - -@@ -1095,8 +1098,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, - // Button release - if (state == 0) { - // Left click -- if (button == 0x110 && -- render_get_row_num(wayl->render, seat->pointer.y, matches_get_count(wayl->matches)) != -1) { -+ if (button == 0x110 && seat->pointer.hovered_row_idx != -1) { - execute_selected(seat, false, -1); - // Right click - } else if (button == 0x111) { -@@ -1125,7 +1127,7 @@ wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, - } - - if (refresh) { -- select_hovered_match(wayl, seat->pointer.y); -+ select_hovered_match(wayl, seat->pointer.hovered_row_idx); - } - } - } --- -2.39.2 - - -From ef4b0160b3c6e04da7b4bf6a0e6b7d0ac06b54ef Mon Sep 17 00:00:00 2001 -From: alz -Date: Tue, 23 Jul 2024 16:35:44 -0400 -Subject: [PATCH 6/7] Refreshing display less often - ---- - render.c | 2 +- - wayland.c | 7 +++++-- - 2 files changed, 6 insertions(+), 3 deletions(-) - -diff --git a/render.c b/render.c -index 1dcefc9..505f570 100644 ---- a/render.c -+++ b/render.c -@@ -839,7 +839,7 @@ render_set_font(struct render *render, struct fcft_font *font, - border_size; - - LOG_DBG("x-margin: %d, y-margin: %d, border: %d, row-height: %d, " -- "icon-height: %d, height: %d, width: %d, scale: %d", -+ "icon-height: %d, height: %d, width: %d, scale: %f", - x_margin, y_margin, border_size, row_height, icon_height, - height, width, scale); - -diff --git a/wayland.c b/wayland.c -index ab88598..19e902a 100644 ---- a/wayland.c -+++ b/wayland.c -@@ -1079,11 +1079,14 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, - struct wayland *wayl = seat->wayl; - - if (wayl->conf->mouse_listener) { -- seat->pointer.hovered_row_idx = -+ size_t hovered_row = - render_get_row_num(wayl->render, - wl_fixed_to_int(surface_y), - matches_get_count(wayl->matches)); -- select_hovered_match(wayl, seat->pointer.hovered_row_idx); -+ if (hovered_row != seat->pointer.hovered_row_idx) { -+ seat->pointer.hovered_row_idx = hovered_row; -+ select_hovered_match(wayl, seat->pointer.hovered_row_idx); -+ } - } - } - --- -2.39.2 - - -From 761aabf6b7fc55203e23be76a044bbea3e8d99be Mon Sep 17 00:00:00 2001 -From: alz -Date: Mon, 29 Jul 2024 13:01:12 -0400 -Subject: [PATCH 7/7] Removed config, refactored hovered row selection - ---- - config.c | 4 --- - config.h | 2 -- - doc/fuzzel.1.scd | 4 --- - doc/fuzzel.ini.5.scd | 3 -- - main.c | 10 ------ - match.c | 12 +++---- - match.h | 6 ++-- - render.c | 9 ++--- - render.h | 4 ++- - wayland.c | 78 +++++++++++++++++++++----------------------- - 10 files changed, 54 insertions(+), 78 deletions(-) - -diff --git a/config.c b/config.c -index 21aab3a..e236142 100644 ---- a/config.c -+++ b/config.c -@@ -778,9 +778,6 @@ parse_section_main(struct context *ctx) - else if (strcmp(key, "list-executables-in-path") == 0) - return value_to_bool(ctx, &conf->list_executables_in_path); - -- else if (strcmp(key, "mouse-listener") == 0) -- return value_to_bool(ctx, &conf->mouse_listener); -- - else if (strcmp(key, "fields") == 0) { - _Static_assert(sizeof(conf->match_fields) == sizeof(int), - "enum is not 32-bit"); -@@ -1575,7 +1572,6 @@ config_load(struct config *conf, const char *conf_path, - .layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP, - .exit_on_kb_focus_loss = true, - .list_executables_in_path = false, -- .mouse_listener = false, - }; - - add_default_key_bindings(conf); -diff --git a/config.h b/config.h -index 99d3a52..a52976c 100644 ---- a/config.h -+++ b/config.h -@@ -170,8 +170,6 @@ struct config { - bool exit_on_kb_focus_loss; - - bool list_executables_in_path; -- -- bool mouse_listener; - }; - - typedef tll(char *) config_override_t; -diff --git a/doc/fuzzel.1.scd b/doc/fuzzel.1.scd -index 791a5e6..c46d9af 100644 ---- a/doc/fuzzel.1.scd -+++ b/doc/fuzzel.1.scd -@@ -302,10 +302,6 @@ or command line options: - *--log-no-syslog* - Disables syslog logging. Logging is only done on stderr. - --*--mouse* -- Allows choosing items with mouse left click, and cancelling fuzzel with -- right click. -- - *-v*,*--version* - Show the version number and quit - -diff --git a/doc/fuzzel.ini.5.scd b/doc/fuzzel.ini.5.scd -index ee6a2c5..e3dfc05 100644 ---- a/doc/fuzzel.ini.5.scd -+++ b/doc/fuzzel.ini.5.scd -@@ -411,9 +411,6 @@ done by setting _action=none_; e.g. *delete-line-forward=none*. - *last* - Select the last entry, on the last page. Default: _Control+End_. - --*mouse-listener* -- Allows selecting elements with the mouse -- - *custom-1*, *custom-2*, ..., *custom-19* - Execute the currently selected entry, then exit with a non-zero - exit code. *custom-1* exits with exit code 10, *custom-2* with 11, -diff --git a/match.c b/match.c -index a16f903..48c6e4f 100644 ---- a/match.c -+++ b/match.c -@@ -290,7 +290,7 @@ match_get_idx(const struct matches *matches, size_t idx) - matches->page_count, page_no, items_on_page, idx, - matches->max_matches_per_page, matches->match_count); - -- assert(idx >= 0 && idx < items_on_page); -+ assert(idx < items_on_page); - idx += page_no * matches->max_matches_per_page; - - assert(idx < matches->match_count); -@@ -366,7 +366,7 @@ matches_selected_select(struct matches *matches, const char *_string) - } - - bool --matches_selected_select_idx(struct matches *matches, size_t idx) -+matches_idx_select(struct matches *matches, size_t idx) - { - if (idx == -1) - return false; -@@ -427,14 +427,14 @@ matches_selected_next(struct matches *matches, bool wrap) - } - - bool --matches_selected_prev_page(struct matches *matches) -+matches_selected_prev_page(struct matches *matches, bool scrolling) - { - const size_t page_no = matches_get_page(matches); - if (page_no > 0) { - assert(matches->selected >= matches->max_matches_per_page); - matches->selected -= matches->max_matches_per_page; - return true; -- } else if (matches->selected > 0) { -+ } else if (!scrolling && matches->selected > 0) { - matches->selected = 0; - return true; - } -@@ -443,7 +443,7 @@ matches_selected_prev_page(struct matches *matches) - } - - bool --matches_selected_next_page(struct matches *matches) -+matches_selected_next_page(struct matches *matches, bool scrolling) - { - const size_t page_no = matches_get_page(matches); - if (page_no + 1 < matches->page_count) { -@@ -451,7 +451,7 @@ matches_selected_next_page(struct matches *matches) - matches->selected + matches->max_matches_per_page, - matches->match_count - 1); - return true; -- } else if (matches->selected < matches->match_count - 1) { -+ } else if (!scrolling && matches->selected < matches->match_count - 1) { - matches->selected = matches->match_count - 1; - return true; - } -diff --git a/match.h b/match.h -index 871635b..35c5d5e 100644 ---- a/match.h -+++ b/match.h -@@ -53,7 +53,7 @@ size_t matches_get_total_count(const struct matches *matches); - size_t matches_get_match_index(const struct matches *matches); - - bool matches_selected_select(struct matches *matches, const char *string); --bool matches_selected_select_idx(struct matches *matches, size_t idx); -+bool matches_idx_select(struct matches *matches, size_t idx); - - bool matches_selected_first(struct matches *matches); - bool matches_selected_last(struct matches *matches); -@@ -61,5 +61,5 @@ bool matches_selected_last(struct matches *matches); - bool matches_selected_prev(struct matches *matches, bool wrap); - bool matches_selected_next(struct matches *matches, bool wrap); - --bool matches_selected_prev_page(struct matches *matches); --bool matches_selected_next_page(struct matches *matches); -+bool matches_selected_prev_page(struct matches *matches, bool scrolling); -+bool matches_selected_next_page(struct matches *matches, bool scrolling); -diff --git a/render.c b/render.c -index 505f570..ef9aaad 100644 ---- a/render.c -+++ b/render.c -@@ -875,7 +875,8 @@ render_destroy(struct render *render) - } - - size_t --render_get_row_num(const struct render *render, int y, size_t match_count) -+render_get_row_num(const struct render *render, int y, -+ const struct matches *matches) - { - const float scale = render->scale; - const int y_margin = render->y_margin; -@@ -883,15 +884,15 @@ render_get_row_num(const struct render *render, int y, size_t match_count) - const int border_size = render->border_size; - const int row_height = render->row_height; - const int first_row = 1 * border_size + y_margin + row_height + inner_pad; -- const int last_row = first_row + match_count*row_height; -+ const size_t match_count = matches_get_count(matches); -+ const size_t last_row = first_row + match_count*row_height; - - y = floor(scale * y); - - size_t row = -1; - - if (y >= first_row && y < last_row) { -- y -= first_row; -- row = y / row_height; -+ row = (y - first_row) / row_height; - } - - return row; -diff --git a/render.h b/render.h -index c257004..16887f3 100644 ---- a/render.h -+++ b/render.h -@@ -31,4 +31,6 @@ void render_match_list( - - int render_icon_size(const struct render *render); - --size_t render_get_row_num(const struct render *render, int y, size_t match_count); -+size_t render_get_row_num( -+ const struct render *render, int y, -+ const struct matches *matches); -diff --git a/wayland.c b/wayland.c -index 19e902a..541496d 100644 ---- a/wayland.c -+++ b/wayland.c -@@ -16,6 +16,7 @@ - #include - #include - -+#include - #include - #include - #include -@@ -142,14 +143,13 @@ struct seat { - - int x; - int y; -+ size_t hovered_row_idx; - - struct wl_surface *surface; - struct wp_viewport *viewport; - struct wl_cursor_theme *theme; - struct wl_cursor *cursor; - float scale; -- -- size_t hovered_row_idx; - } pointer; - }; - -@@ -706,7 +706,7 @@ execute_binding(struct seat *seat, const struct key_binding *binding, bool *refr - return true; - - case BIND_ACTION_MATCHES_PREV_PAGE: -- *refresh = matches_selected_prev_page(wayl->matches); -+ *refresh = matches_selected_prev_page(wayl->matches, false); - return true; - - case BIND_ACTION_MATCHES_NEXT: -@@ -718,7 +718,7 @@ execute_binding(struct seat *seat, const struct key_binding *binding, bool *refr - return true; - - case BIND_ACTION_MATCHES_NEXT_PAGE: -- *refresh = matches_selected_next_page(wayl->matches); -+ *refresh = matches_selected_next_page(wayl->matches, false); - return true; - - case BIND_ACTION_MATCHES_FIRST: -@@ -1061,12 +1061,22 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, - } - - static void --select_hovered_match(struct wayland *wayl, size_t idx) -+select_hovered_match(struct seat *seat, bool refresh_always) - { -+ struct wayland *wayl = seat->wayl; - bool refresh = false; -- refresh = matches_selected_select_idx(wayl->matches,idx); - -- if (refresh) { -+ size_t hovered_row = -+ render_get_row_num(wayl->render, -+ seat->pointer.y, -+ wayl->matches); -+ -+ if (hovered_row != seat->pointer.hovered_row_idx) { -+ seat->pointer.hovered_row_idx = hovered_row; -+ refresh = matches_idx_select(wayl->matches,hovered_row); -+ } -+ -+ if (refresh_always || refresh) { - wayl_refresh(wayl); - } - } -@@ -1076,18 +1086,11 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, - uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) - { - struct seat *seat = data; -- struct wayland *wayl = seat->wayl; - -- if (wayl->conf->mouse_listener) { -- size_t hovered_row = -- render_get_row_num(wayl->render, -- wl_fixed_to_int(surface_y), -- matches_get_count(wayl->matches)); -- if (hovered_row != seat->pointer.hovered_row_idx) { -- seat->pointer.hovered_row_idx = hovered_row; -- select_hovered_match(wayl, seat->pointer.hovered_row_idx); -- } -- } -+ seat->pointer.x = wl_fixed_to_int(surface_x); -+ seat->pointer.y = wl_fixed_to_int(surface_y); -+ -+ select_hovered_match(seat, false); - } - - static void -@@ -1097,18 +1100,14 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, - struct seat *seat = data; - struct wayland *wayl = seat->wayl; - -- if (wayl->conf->mouse_listener) { -- // Button release -- if (state == 0) { -- // Left click -- if (button == 0x110 && seat->pointer.hovered_row_idx != -1) { -- execute_selected(seat, false, -1); -- // Right click -- } else if (button == 0x111) { -- wayl->status = EXIT; -- if (wayl->conf->dmenu.enabled) -- wayl->exit_code = 2; -- } -+ if (state == WL_POINTER_BUTTON_STATE_RELEASED) { -+ if (button == BTN_LEFT && seat->pointer.hovered_row_idx != -1) { -+ execute_selected(seat, false, -1); -+ } else if (button == BTN_RIGHT) { -+ // Same as pressing ESC -+ wayl->status = EXIT; -+ if (wayl->conf->dmenu.enabled) -+ wayl->exit_code = 2; - } - } - } -@@ -1119,19 +1118,16 @@ wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, - { - struct seat *seat = data; - struct wayland *wayl = seat->wayl; -+ bool refresh = false; - -- if (wayl->conf->mouse_listener) { -- bool refresh = false; -+ if (value < 0) { -+ refresh = matches_selected_prev_page(wayl->matches, true); -+ } else if (value > 0) { -+ refresh = matches_selected_next_page(wayl->matches, true); -+ } - -- if (value < 0) { -- refresh = matches_selected_prev_page(wayl->matches); -- } else if (value > 0) { -- refresh = matches_selected_next_page(wayl->matches); -- } -- -- if (refresh) { -- select_hovered_match(wayl, seat->pointer.hovered_row_idx); -- } -+ if (refresh) { -+ select_hovered_match(seat, true); - } - } - --- -2.39.2