]> git.sur5r.net Git - i3/i3/blob - libi3/dpi.c
Merge branch 'master' into next
[i3/i3] / libi3 / dpi.c
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2014 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  */
8 #include "libi3.h"
9 #include <math.h>
10
11 extern xcb_screen_t *root_screen;
12
13 /*
14  * Convert a logical amount of pixels (e.g. 2 pixels on a “standard” 96 DPI
15  * screen) to a corresponding amount of physical pixels on a standard or retina
16  * screen, e.g. 5 pixels on a 227 DPI MacBook Pro 13" Retina screen.
17  *
18  */
19 int logical_px(const int logical) {
20     const int dpi = (double)root_screen->height_in_pixels * 25.4 /
21                     (double)root_screen->height_in_millimeters;
22     /* There are many misconfigurations out there, i.e. systems with screens
23      * whose dpi is in fact higher than 96 dpi, but not significantly higher,
24      * so software was never adapted. We could tell people to reconfigure their
25      * systems to 96 dpi in order to get the behavior they expect/are used to,
26      * but since we can easily detect this case in code, let’s do it for them.
27      */
28     if ((dpi / 96.0) < 1.25)
29         return logical;
30     return ceil((dpi / 96.0) * logical);
31 }