render: make sure scale is updated on scale changes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Before this change, render_set_font() was only called when the *font* had been reloaded. With dpi-aware=yes, that doesn't happen on scale changes. This caused the cached scale value (in the renderer) to be wrong. This meant mouse selection didn't work correctly, since the logic that calculates which row the cursor is on depends on the *render's* scale value be correct. Another issue was that UI elements that _do_ depend on the scale factor also wasn't updated.
authored by Daniel Eklöf · committed by Daniel Eklöf · parent 179fbfd · Browse files · 4 files·+47 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+47 added−39 removed
- other:+47 added−39 removed
Provenance
- Commit
98db6ee- Tree
27a733d- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
179fbfd
4 files changed+47 added−39 removed
modified:CHANGELOG.md+5 added
74 unmodified lines75 * Rounding of window size when fractional scaling is used.76 * Dmenu mode failing with _"failed to read from stdin: Resource77 temporarily unavailable"_.78 * First frame flickers when fractional scaling is used.79+* Borders, padding etc not updated on scale changes when80+ `dpi-aware=yes`. This mostly affected setups using fractional81+ scaling, but all setups were affected in one way or another.82+* Mouse selection not working correctly (wrong item selected) when83+ `dpi-aware=yes` and desktop scaling was enabled.84 85 [348]: https://codeberg.org/dnkl/fuzzel/issues/34886 [356]: https://codeberg.org/dnkl/fuzzel/issues/35687 651 unmodified linesmodified:render.c+5 added-5 removed
786 unmodified lines787 render->subpixel = subpixel;788 }789 790 bool791-render_set_font(struct render *render, struct fcft_font *font,792- float scale, float dpi, bool size_font_by_dpi,793- int *new_width, int *new_height)791+render_set_font_and_update_sizes(struct render *render, struct fcft_font *font,792+ float scale, float dpi, bool size_font_by_dpi,793+ int *new_width, int *new_height)794 {795 if (font != NULL) {796 fcft_destroy(render->font);797 render->font = font;25 unmodified lines823 border_size + /* Top border */824 y_margin +825 row_height + /* The prompt */826 inner_pad + /* Padding between prompt and matches */827- render->conf->lines * row_height + /* Matches */827+ render->conf->lines * row_height + /* Matches */828 y_margin +829 border_size; /* Bottom border */830 831 const unsigned width =52 unmodified lines884 const int border_size = render->border_size;885 const int row_height = render->row_height;886 const int first_row = 1 * border_size + y_margin + row_height + inner_pad;887 const size_t match_count = matches_get_count(matches);888- const size_t last_row = first_row + match_count*row_height;888+ const size_t last_row = first_row + match_count * row_height;889 890 y = floor(scale * y);891 892 size_t row = -1;7 unmodified linesmodified:render.h+4 added-3 removed
13 unmodified lines14 struct render *render_init(const struct config *conf, mtx_t *icon_lock);15 void render_destroy(struct render *render);16 17 void render_set_subpixel(struct render *render, enum fcft_subpixel subpixel);18+bool render_set_font_and_update_sizes(18-bool render_set_font(struct render *render, struct fcft_font *font,19- float scale, float dpi, bool size_font_by_dpi,20- int *new_width, int *new_height);19+ struct render *render, struct fcft_font *font,20+ float scale, float dpi, bool size_font_by_dpi,21+ int *new_width, int *new_height);22 23 void render_background(const struct render *render, struct buffer *buf);24 25 void render_prompt(12 unmodified linesmodified:wayland.c+33 added-31 removed
1037 unmodified lines1038 return false;1039 }1040 1041 static void1042+select_hovered_match(struct seat *seat, bool refresh_always)1043+{1044+ struct wayland *wayl = seat->wayl;1045+ bool refresh = false;1046+1047+ size_t hovered_row =1048+ render_get_row_num(wayl->render,1049+ seat->pointer.y,1050+ wayl->matches);1051+ 1052+ if (hovered_row != seat->pointer.hovered_row_idx) {1053+ seat->pointer.hovered_row_idx = hovered_row;1054+ refresh = matches_idx_select(wayl->matches,hovered_row);1055+ }1056+1057+ if (refresh_always || refresh) {1058+ wayl_refresh(wayl);1059+ }1060+}1061+1062+static void1063 wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,1064 uint32_t serial, struct wl_surface *surface,1065 wl_fixed_t surface_x, wl_fixed_t surface_y)1066 {1067 struct seat *seat = data;1068 seat->pointer.serial = serial;1069 1070+ seat->pointer.x = wl_fixed_to_int(surface_x);1071+ seat->pointer.y = wl_fixed_to_int(surface_y);1072+1073 if (!attempt_cursor_shape(seat->wayl, wl_pointer, serial)) {1074 reload_cursor_theme(seat, seat->wayl->scale);1075 update_cursor_surface(seat);1076 }1077+1078+ select_hovered_match(seat, false);1079 }1080 1081 static void1082 wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,3 unmodified lines1086 seat->pointer.serial = serial;1087 }1088 1089 static void1064-select_hovered_match(struct seat *seat, bool refresh_always)1065-{1066- struct wayland *wayl = seat->wayl;1067- bool refresh = false;1068-1069- size_t hovered_row =1070- render_get_row_num(wayl->render,1071- seat->pointer.y,1072- wayl->matches);1073- 1074- if (hovered_row != seat->pointer.hovered_row_idx) {1075- seat->pointer.hovered_row_idx = hovered_row;1076- refresh = matches_idx_select(wayl->matches,hovered_row);1077- }1078-1079- if (refresh_always || refresh) {1080- wayl_refresh(wayl);1081- }1082-}1083-1084-static void1090 wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,1091 uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)1092 {1093 struct seat *seat = data;271 unmodified lines1365 free(names);1366 1367 if (font == NULL)1368 return false;1364-1365- bool ret = render_set_font(1366- wayl->render, font, new_scale, new_dpi,1367- wayl->font_is_sized_by_dpi, &wayl->width, &wayl->height);1368-1369- if (wayl->font_reloaded.cb != NULL)1370- wayl->font_reloaded.cb(wayl, font, wayl->font_reloaded.data);1371-1372- return ret;1369 }1370 1375- return true;1371+ bool ret = render_set_font_and_update_sizes(1372+ wayl->render, font, new_scale, new_dpi,1373+ wayl->font_is_sized_by_dpi, &wayl->width, &wayl->height);1374 1375+ if (wayl->font_reloaded.cb != NULL)1376+ wayl->font_reloaded.cb(wayl, font, wayl->font_reloaded.data);1377+1378+ return ret;1379 }1380 1381 static float1382 wayl_ppi(const struct wayland *wayl)1059 unmodified lines