font: initialize DPI from monitor's PPI, if available
Before adoption: this commit came in with the history the project adopted, so no landing records it.
If the user specified an output, use it's PPI value to configure the font DPI. This makes --font=name:size=12 work as expected on HiDPI monitors.
authored by Daniel Eklöf · committed by Daniel Eklöf · parent 6a3ea33 · Browse files · 3 files·+80 added−42 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+80 added−42 removed
- other:+80 added−42 removed
Provenance
- Commit
537148c- Tree
22cbeed- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
6a3ea33
3 files changed+80 added−42 removed
modified:main.c+14 added-9 removed
346 unmodified lines347 struct render *render = NULL;348 struct wayland *wayl = NULL;349 struct font *font = NULL;350 351- if ((font = font_from_name(&(const char *){font_name}, 1, NULL)) == NULL)351+ if ((fdm = fdm_init()) == NULL)352 goto out;353 354+ if ((wayl = wayl_init(355+ fdm, render_options.width, render_options.height,356+ output_name)) == NULL)357+ goto out;358+359+ char font_attrs[128];360+ snprintf(font_attrs, sizeof(font_attrs), "dpi=%d", wayl_ppi(wayl));361+362+ if ((font = font_from_name(&(const char *){font_name}, 1, font_attrs)) == NULL)363+ goto out;364+365 LOG_DBG(366 "font: height: %d, ascent: %d, descent: %d",367 font->height, font->ascent, font->descent);368 18 unmodified lines387 388 if ((render = render_init(font, &render_options)) == NULL)389 goto out;390 380- if ((fdm = fdm_init()) == NULL)381- goto out;382-391 if ((prompt = prompt_init(L"> ")) == NULL)392 goto out;393 394 if ((matches = matches_init(apps, max_matches)) == NULL)395 goto out;396 397 matches_update(matches, prompt);398+ wayl_configure(wayl, render, prompt, matches, dmenu_mode);399+ wayl_refresh(wayl);400 391- if ((wayl = wayl_init(392- fdm, render, prompt, matches, render_options.width,393- render_options.height, output_name, dmenu_mode)) == NULL)394- goto out;395-401 while (true) {402 wayl_flush(wayl);403 if (!fdm_poll(fdm))404 break;20 unmodified linesmodified:wayland.c+59 added-30 removed
41 unmodified lines42 43 int width_px;44 int height_px;45 46+ int x_ppi;47+ int y_ppi;48+49 int scale;50 };51 52 struct repeat {41 unmodified lines94 struct xkb_keymap *xkb_keymap;95 struct xkb_state *xkb_state;96 };97 95-static void refresh(struct wayland *wayl);96-98 bool99 repeat_start(struct repeat *repeat, uint32_t key)100 {101 if (repeat->dont_re_repeat)131 unmodified lines233 sym, mods, consumed, significant, effective_mods);234 235 if (sym == XKB_KEY_Home || (sym == XKB_KEY_a && effective_mods == ctrl)) {236 if (prompt_cursor_home(wayl->prompt))236- refresh(wayl);237+ wayl_refresh(wayl);238 }239 240 else if (sym == XKB_KEY_End || (sym == XKB_KEY_e && effective_mods == ctrl)) {241 if (prompt_cursor_end(wayl->prompt))241- refresh(wayl);242+ wayl_refresh(wayl);243 }244 245 else if ((sym == XKB_KEY_b && effective_mods == alt) ||246 (sym == XKB_KEY_Left && effective_mods == ctrl)) {247 if (prompt_cursor_prev_word(wayl->prompt))247- refresh(wayl);248+ wayl_refresh(wayl);249 }250 251 else if ((sym == XKB_KEY_f && effective_mods == alt) ||252 (sym == XKB_KEY_Right && effective_mods == ctrl)) {253 254 if (prompt_cursor_next_word(wayl->prompt))254- refresh(wayl);255+ wayl_refresh(wayl);256 }257 258 else if ((sym == XKB_KEY_Escape && effective_mods == 0) ||259 (sym == XKB_KEY_g && effective_mods == ctrl)) {2 unmodified lines262 263 else if ((sym == XKB_KEY_p && effective_mods == ctrl) ||264 (sym == XKB_KEY_Up && effective_mods == 0)) {265 if (matches_selected_prev(wayl->matches, false))265- refresh(wayl);266+ wayl_refresh(wayl);267 }268 269 else if ((sym == XKB_KEY_n && effective_mods == ctrl) ||270 (sym == XKB_KEY_Down && effective_mods == 0)) {271 if (matches_selected_next(wayl->matches, false))271- refresh(wayl);272+ wayl_refresh(wayl);273 }274 275 else if (sym == XKB_KEY_Tab && effective_mods == 0) {276 if (matches_selected_next(wayl->matches, true))276- refresh(wayl);277+ wayl_refresh(wayl);278 }279 280 else if (sym == XKB_KEY_ISO_Left_Tab && effective_mods == 0) {281 if (matches_selected_prev(wayl->matches, true))281- refresh(wayl);282+ wayl_refresh(wayl);283 }284 285 else if ((sym == XKB_KEY_b && effective_mods == ctrl) ||286 (sym == XKB_KEY_Left && effective_mods == 0)) {287 if (prompt_cursor_prev_char(wayl->prompt))287- refresh(wayl);288+ wayl_refresh(wayl);289 }290 291 else if ((sym == XKB_KEY_f && effective_mods == ctrl) ||292 (sym == XKB_KEY_Right && effective_mods == 0)) {293 if (prompt_cursor_next_char(wayl->prompt))293- refresh(wayl);294+ wayl_refresh(wayl);295 }296 297 else if ((sym == XKB_KEY_d && effective_mods == ctrl) ||298 (sym == XKB_KEY_Delete && effective_mods == 0)) {299 if (prompt_erase_next_char(wayl->prompt)) {300 matches_update(wayl->matches, wayl->prompt);300- refresh(wayl);301+ wayl_refresh(wayl);302 }303 }304 305 else if (sym == XKB_KEY_BackSpace && effective_mods == 0) {306 if (prompt_erase_prev_char(wayl->prompt)) {307 matches_update(wayl->matches, wayl->prompt);307- refresh(wayl);308+ wayl_refresh(wayl);309 }310 }311 312 else if (sym == XKB_KEY_BackSpace && (effective_mods == ctrl ||313 effective_mods == alt)) {314 if (prompt_erase_prev_word(wayl->prompt)) {315 matches_update(wayl->matches, wayl->prompt);315- refresh(wayl);316+ wayl_refresh(wayl);317 }318 }319 320 else if ((sym == XKB_KEY_d && effective_mods == alt) ||321 (sym == XKB_KEY_Delete && effective_mods == ctrl)) {322 if (prompt_erase_next_word(wayl->prompt)) {323 matches_update(wayl->matches, wayl->prompt);323- refresh(wayl);324+ wayl_refresh(wayl);325 }326 }327 328 else if (sym == XKB_KEY_k && effective_mods == ctrl) {329 if (prompt_erase_after_cursor(wayl->prompt)) {330 matches_update(wayl->matches, wayl->prompt);330- refresh(wayl);331+ wayl_refresh(wayl);332 }333 }334 335 else if (sym == XKB_KEY_Return && effective_mods == 0) {30 unmodified lines366 if (!prompt_insert_chars(wayl->prompt, buf, count))367 return;368 369 matches_update(wayl->matches, wayl->prompt);369- refresh(wayl);370+ wayl_refresh(wayl);371 }372 373 if (should_repeat)374 repeat_start(&wayl->repeat, key - 8);59 unmodified lines434 .name = seat_handle_name,435 };436 437 static void438+output_update_ppi(struct monitor *mon)439+{440+ int x_inches = mon->width_mm * 0.03937008;441+ int y_inches = mon->height_mm * 0.03937008;442+ mon->x_ppi = mon->width_px / x_inches;443+ mon->y_ppi = mon->height_px / y_inches;444+}445+446+static void447 output_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y,448 int32_t physical_width, int32_t physical_height,449 int32_t subpixel, const char *make, const char *model,450 int32_t transform)451 {452 struct monitor *mon = data;453 mon->width_mm = physical_width;454 mon->height_mm = physical_height;455+ output_update_ppi(mon);456 }457 458 static void459 output_mode(void *data, struct wl_output *wl_output, uint32_t flags,35 unmodified lines495 {496 struct monitor *mon = data;497 mon->width_px = width;498 mon->height_px = height;499+ output_update_ppi(mon);500 }501 502 static void503 xdg_output_handle_done(void *data, struct zxdg_output_v1 *xdg_output)177 unmodified lines681 wayl->pending = NULL;682 }683 }684 673-static void674-refresh(struct wayland *wayl)685+void686+wayl_refresh(struct wayland *wayl)687 {688 struct buffer *buf = shm_get_buffer(wayl->shm, wayl->width, wayl->height);689 690 /* Background + border */73 unmodified lines764 return true;765 }766 767 struct wayland *756-wayl_init(struct fdm *fdm, struct render *render, struct prompt *prompt,757- struct matches *matches, int width, int height,758- const char *output_name, bool dmenu_mode)768+wayl_init(struct fdm *fdm, int width, int height, const char *output_name)769 {770 struct wayland *wayl = calloc(1, sizeof(*wayl));771 772 wayl->fdm = fdm;763- wayl->render = render;764- wayl->prompt = prompt;765- wayl->matches = matches;773+ //wayl->render = render;774+ //wayl->prompt = prompt;775+ //wayl->matches = matches;776 wayl->status = KEEP_RUNNING;777 wayl->exit_code = EXIT_FAILURE;768- wayl->dmenu_mode = dmenu_mode;778+ //wayl->dmenu_mode = dmenu_mode;779 780 wayl->repeat.fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);781 if (wayl->repeat.fd == -1) {782 LOG_ERRNO("failed to create keyboard repeat timer FD");35 unmodified lines818 819 tll_foreach(wayl->monitors, it) {820 const struct monitor *mon = &it->item;821 812- LOG_INFO("monitor: %s: %dx%d+%d+%d (%dx%dmm)",822+ LOG_INFO("monitor: %s: %dx%d+%d+%d (%dx%dmm, PPI=%dx%d)",823 mon->name, mon->width_px, mon->height_px,814- mon->x, mon->y, mon->width_mm, mon->height_mm);824+ mon->x, mon->y, mon->width_mm, mon->height_mm,825+ mon->x_ppi, mon->y_ppi);826 827 if (output_name != NULL && strcmp(output_name, mon->name) == 0) {828 wayl->monitor = mon;829 break;65 unmodified lines895 LOG_ERR("failed to register keyboard repeat timer FD with FDM");896 goto out;897 }898 888- refresh(wayl);899+ //wayl_refresh(wayl);900 return wayl;901 902 out:903 wayl_destroy(wayl);904 return NULL;905 }906 907 void908+wayl_configure(909+ struct wayland *wayl, struct render *render, struct prompt *prompt,910+ struct matches *matches, bool dmenu_mode)911+{912+ wayl->render = render;913+ wayl->prompt = prompt;914+ wayl->matches = matches;915+ wayl->status = KEEP_RUNNING;916+ wayl->dmenu_mode = dmenu_mode;917+}918+919+void920 wayl_destroy(struct wayland *wayl)921 {922 if (wayl == NULL)923 return;49 unmodified lines973 {974 wl_display_flush(wayl->display);975 }976 977+int978+wayl_ppi(const struct wayland *wayl)979+{980+ return wayl->monitor != NULL ? wayl->monitor->x_ppi : 96;981+}982+983 bool984 wayl_exit_code(const struct wayland *wayl)985 {986 return wayl->exit_code;7 unmodified linesmodified:wayland.h+7 added-3 removed
6 unmodified lines7 #include "render.h"8 9 struct wayland;10 struct wayland *wayl_init(11- struct fdm *fdm, struct render *render, struct prompt *prompt,12- struct matches *matches, int width, int height, const char *output_name,13- bool dmenu_mode);11+ struct fdm *fdm, int width, int height, const char *output_name);12 void wayl_destroy(struct wayland *wayl);13 14+void wayl_configure(15+ struct wayland *wayl, struct render *render, struct prompt *prompt,16+ struct matches *matches, bool dmenu_mode);17+18+void wayl_refresh(struct wayland *wayl);19 void wayl_flush(struct wayland *wayl);20 21+int wayl_ppi(const struct wayland *wayl);22 bool wayl_exit_code(const struct wayland *wayl);23 bool wayl_update_cache(const struct wayland *wayl);