+#include <stdlib.h>
+#include <xcb/xcb_xrm.h>
+
+static long dpi;
+
+static long init_dpi_fallback(void) {
+ return (double)root_screen->height_in_pixels * 25.4 / (double)root_screen->height_in_millimeters;
+}
+
+/*
+ * Initialize the DPI setting.
+ * This will use the 'Xft.dpi' X resource if available and fall back to
+ * guessing the correct value otherwise.
+ */
+void init_dpi(void) {
+ xcb_xrm_database_t *database = NULL;
+ char *resource = NULL;
+
+ if (conn == NULL) {
+ goto init_dpi_end;
+ }
+
+ database = xcb_xrm_database_from_default(conn);
+ if (database == NULL) {
+ ELOG("Failed to open the resource database.\n");
+ goto init_dpi_end;
+ }
+
+ xcb_xrm_resource_get_string(database, "Xft.dpi", NULL, &resource);
+ if (resource == NULL) {
+ DLOG("Resource Xft.dpi not specified, skipping.\n");
+ goto init_dpi_end;
+ }