2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2014 Michael Stapelberg and contributors (see also: LICENSE)
11 extern xcb_screen_t *root_screen;
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.
19 int logical_px(const int logical) {
20 if (root_screen == NULL) {
21 /* Dpi info may not be available when parsing a config without an X
22 * server, such as for config file validation. */
26 const int dpi = (double)root_screen->height_in_pixels * 25.4 /
27 (double)root_screen->height_in_millimeters;
28 /* There are many misconfigurations out there, i.e. systems with screens
29 * whose dpi is in fact higher than 96 dpi, but not significantly higher,
30 * so software was never adapted. We could tell people to reconfigure their
31 * systems to 96 dpi in order to get the behavior they expect/are used to,
32 * but since we can easily detect this case in code, let’s do it for them.
34 if ((dpi / 96.0) < 1.25)
36 return ceil((dpi / 96.0) * logical);