Skip to content
Myr

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

3 files+80 added−42 removed

modified:main.c+14 added-9 removed
346 unmodified lines
347 struct render *render = NULL;348 struct wayland *wayl = NULL;349 struct font *font = NULL;350351 if ((font = font_from_name(&(const char *){font_name}, 1, NULL)) == NULL)351 if ((fdm = fdm_init()) == NULL)352 goto out;353354 if ((wayl = wayl_init(355 fdm, render_options.width, render_options.height,356 output_name)) == NULL)357 goto out;358359 char font_attrs[128];360 snprintf(font_attrs, sizeof(font_attrs), "dpi=%d", wayl_ppi(wayl));361362 if ((font = font_from_name(&(const char *){font_name}, 1, font_attrs)) == NULL)363 goto out;364365 LOG_DBG(366 "font: height: %d, ascent: %d, descent: %d",367 font->height, font->ascent, font->descent);368
18 unmodified lines
387388 if ((render = render_init(font, &render_options)) == NULL)389 goto out;390380 if ((fdm = fdm_init()) == NULL)381 goto out;382391 if ((prompt = prompt_init(L"> ")) == NULL)392 goto out;393394 if ((matches = matches_init(apps, max_matches)) == NULL)395 goto out;396397 matches_update(matches, prompt);398 wayl_configure(wayl, render, prompt, matches, dmenu_mode);399 wayl_refresh(wayl);400391 if ((wayl = wayl_init(392 fdm, render, prompt, matches, render_options.width,393 render_options.height, output_name, dmenu_mode)) == NULL)394 goto out;395401 while (true) {402 wayl_flush(wayl);403 if (!fdm_poll(fdm))404 break;
20 unmodified lines
modified:wayland.c+59 added-30 removed
41 unmodified lines
4243 int width_px;44 int height_px;4546 int x_ppi;47 int y_ppi;4849 int scale;50};5152struct repeat {
41 unmodified lines
94 struct xkb_keymap *xkb_keymap;95 struct xkb_state *xkb_state;96};9795static void refresh(struct wayland *wayl);9698bool99repeat_start(struct repeat *repeat, uint32_t key)100{101 if (repeat->dont_re_repeat)
131 unmodified lines
233 sym, mods, consumed, significant, effective_mods);234235 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 }239240 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 }244245 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 }250251 else if ((sym == XKB_KEY_f && effective_mods == alt) ||252 (sym == XKB_KEY_Right && effective_mods == ctrl)) {253254 if (prompt_cursor_next_word(wayl->prompt))254 refresh(wayl);255 wayl_refresh(wayl);256 }257258 else if ((sym == XKB_KEY_Escape && effective_mods == 0) ||259 (sym == XKB_KEY_g && effective_mods == ctrl)) {
2 unmodified lines
262263 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 }268269 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 }274275 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 }279280 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 }284285 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 }290291 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 }296297 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 }304305 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 }311312 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 }319320 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 }327328 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 }334335 else if (sym == XKB_KEY_Return && effective_mods == 0) {
30 unmodified lines
366 if (!prompt_insert_chars(wayl->prompt, buf, count))367 return;368369 matches_update(wayl->matches, wayl->prompt);369 refresh(wayl);370 wayl_refresh(wayl);371 }372373 if (should_repeat)374 repeat_start(&wayl->repeat, key - 8);
59 unmodified lines
434 .name = seat_handle_name,435};436437static void438output_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}445446static void447output_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}457458static void459output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
35 unmodified lines
495{496 struct monitor *mon = data;497 mon->width_px = width;498 mon->height_px = height;499 output_update_ppi(mon);500}501502static void503xdg_output_handle_done(void *data, struct zxdg_output_v1 *xdg_output)
177 unmodified lines
681 wayl->pending = NULL;682 }683}684673static void674refresh(struct wayland *wayl)685void686wayl_refresh(struct wayland *wayl)687{688 struct buffer *buf = shm_get_buffer(wayl->shm, wayl->width, wayl->height);689690 /* Background + border */
73 unmodified lines
764 return true;765}766767struct wayland *756wayl_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)768wayl_init(struct fdm *fdm, int width, int height, const char *output_name)769{770 struct wayland *wayl = calloc(1, sizeof(*wayl));771772 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;779780 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 lines
818819 tll_foreach(wayl->monitors, it) {820 const struct monitor *mon = &it->item;821812 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);826827 if (output_name != NULL && strcmp(output_name, mon->name) == 0) {828 wayl->monitor = mon;829 break;
65 unmodified lines
895 LOG_ERR("failed to register keyboard repeat timer FD with FDM");896 goto out;897 }898888 refresh(wayl);899 //wayl_refresh(wayl);900 return wayl;901902out:903 wayl_destroy(wayl);904 return NULL;905}906907void908wayl_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}918919void920wayl_destroy(struct wayland *wayl)921{922 if (wayl == NULL)923 return;
49 unmodified lines
973{974 wl_display_flush(wayl->display);975}976977int978wayl_ppi(const struct wayland *wayl)979{980 return wayl->monitor != NULL ? wayl->monitor->x_ppi : 96;981}982983bool984wayl_exit_code(const struct wayland *wayl)985{986 return wayl->exit_code;
7 unmodified lines
modified:wayland.h+7 added-3 removed
6 unmodified lines
7#include "render.h"89struct wayland;10struct 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);12void wayl_destroy(struct wayland *wayl);1314void wayl_configure(15 struct wayland *wayl, struct render *render, struct prompt *prompt,16 struct matches *matches, bool dmenu_mode);1718void wayl_refresh(struct wayland *wayl);19void wayl_flush(struct wayland *wayl);2021int wayl_ppi(const struct wayland *wayl);22bool wayl_exit_code(const struct wayland *wayl);23bool wayl_update_cache(const struct wayland *wayl);