X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libi3%2Fdpi.c;h=d15e35be78effe198e52e569d85bd2c8025a927e;hb=052e96d3232ef644870fd514b39d2fa2a1ccf22b;hp=a832a689c40600b089ffbfdc2f5dd7421bb34ef5;hpb=f354f534357798eb3ba497b7143132f41ff090f6;p=i3%2Fi3 diff --git a/libi3/dpi.c b/libi3/dpi.c index a832a689..d15e35be 100644 --- a/libi3/dpi.c +++ b/libi3/dpi.c @@ -24,6 +24,7 @@ static long init_dpi_fallback(void) { */ void init_dpi(void) { xcb_xrm_database_t *database = NULL; + char *resource = NULL; if (conn == NULL) { goto init_dpi_end; @@ -35,7 +36,6 @@ void init_dpi(void) { goto init_dpi_end; } - char *resource; xcb_xrm_resource_get_string(database, "Xft.dpi", NULL, &resource); if (resource == NULL) { DLOG("Resource Xft.dpi not specified, skipping.\n"); @@ -43,16 +43,19 @@ void init_dpi(void) { } char *endptr; - dpi = strtol(resource, &endptr, 10); - if (dpi == LONG_MAX || dpi == LONG_MIN || dpi < 0 || *endptr != '\0' || endptr == resource) { + double in_dpi = strtod(resource, &endptr); + if (in_dpi == HUGE_VAL || dpi < 0 || *endptr != '\0' || endptr == resource) { ELOG("Xft.dpi = %s is an invalid number and couldn't be parsed.\n", resource); dpi = 0; goto init_dpi_end; } + dpi = lround(in_dpi); DLOG("Found Xft.dpi = %ld.\n", dpi); init_dpi_end: + free(resource); + if (database != NULL) { xcb_xrm_database_free(database); } @@ -64,6 +67,14 @@ init_dpi_end: } } +/* + * This function returns the value of the DPI setting. + * + */ +long get_dpi_value(void) { + return dpi; +} + /* * Convert a logical amount of pixels (e.g. 2 pixels on a “standard” 96 DPI * screen) to a corresponding amount of physical pixels on a standard or retina