Skip to content

Commit

Permalink
[Wayland] Implement config.dpi support.
Browse files Browse the repository at this point in the history
The correct value of `config.dpi` is required to support physical units
in the themes (e.g. `mm` `in sidebar-v2`).
  • Loading branch information
alebastr authored and lbonn committed Jan 5, 2024
1 parent ecdd2b2 commit 8ea79da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/wayland/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ static void wayland_surface_protocol_enter(void *data,
return;
}

if (config.dpi == 0 || config.dpi == 1) {
// DPI auto-detect requested.
config.dpi = wayland_output_get_dpi(output, output->current.scale, height);
g_debug("Auto-detected DPI: %d", config.dpi);
}

wl_surface_set_buffer_scale(wl_surface, output->current.scale);

if (wayland->scale != output->current.scale) {
Expand Down
16 changes: 16 additions & 0 deletions source/wayland/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,22 @@ static void wayland___create_window(MenuFlags menu_flags) {
TICK_N("pango cairo font setup");

WlState.flags = menu_flags;
// Setup dpi
PangoFontMap *font_map = pango_cairo_font_map_get_default();
if (config.dpi > 1) {
pango_cairo_font_map_set_resolution((PangoCairoFontMap *)font_map,
(double)config.dpi);
} else if (config.dpi == 0 || config.dpi == 1) {
// Should not be reached
g_warning("DPI auto-detect failed, the output is not known yet or does not "
"provide a physical size");
config.dpi =
pango_cairo_font_map_get_resolution((PangoCairoFontMap *)font_map);
} else {
// default pango is 96.
config.dpi =
pango_cairo_font_map_get_resolution((PangoCairoFontMap *)font_map);
}
// Setup font.
// Dummy widget.
box *win = box_create(NULL, "window", ROFI_ORIENTATION_HORIZONTAL);
Expand Down

0 comments on commit 8ea79da

Please sign in to comment.