Skip to content
This repository has been archived by the owner on Oct 4, 2018. It is now read-only.

Commit

Permalink
Use dunst.dpi resource.
Browse files Browse the repository at this point in the history
  • Loading branch information
cliscum committed Dec 27, 2016
1 parent 360985b commit 2ee0924
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CFLAGS += -g --std=gnu99 -pedantic -Wall -Wno-overlength-strings -Os ${STATIC}

pkg_config_packs := dbus-1 x11 freetype2 xext xft xscrnsaver \
"glib-2.0 >= 2.36" gio-2.0 \
pango cairo pangocairo
pango cairo pangocairo xcb xcb-xrm

# check if we need libxdg-basedir
ifeq (,$(findstring STATIC_CONFIG,$(CFLAGS)))
Expand Down
22 changes: 22 additions & 0 deletions x.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <X11/Xatom.h>
#include <pango/pangocairo.h>
#include <cairo-xlib.h>
#include <xcb/xcb.h>
#include <xcb/xcb_xrm.h>

#include "x.h"
#include "utils.h"
Expand Down Expand Up @@ -129,13 +131,33 @@ static color_t x_get_separator_color(color_t fg, color_t bg)
}
}

static void set_dpi(void) {
xcb_connection_t *connection = xcb_connect(getenv("DISPLAY"), NULL);
xcb_xrm_database_t *xDB = xcb_xrm_database_from_default(connection);

char *xrmValue = NULL;
if (0 == xcb_xrm_resource_get_string(xDB, "dunst.dpi", NULL, &xrmValue)) {
int dpi = atoi(xrmValue);
if (dpi > 0) {
PangoFontMap *font_map = pango_cairo_font_map_get_default();
pango_cairo_font_map_set_resolution((PangoCairoFontMap *) font_map, dpi);
}
}

if (xrmValue) {
free(xrmValue);
}
}

static void x_cairo_setup(void)
{
cairo_ctx.surface = cairo_xlib_surface_create(xctx.dpy,
xctx.win, DefaultVisual(xctx.dpy, 0), WIDTH, HEIGHT);

cairo_ctx.context = cairo_create(cairo_ctx.surface);

set_dpi();

cairo_ctx.desc = pango_font_description_from_string(settings.font);

frame_color = x_string_to_color_t(settings.frame_color);
Expand Down

0 comments on commit 2ee0924

Please sign in to comment.