Skip to content

Commit

Permalink
fix dpi calculation for linux & mac
Browse files Browse the repository at this point in the history
DPI = pixels / inch, not mm / pixels
dots = pixels for computer screens
  • Loading branch information
Александров Олег committed Apr 2, 2024
1 parent 3b0c14c commit ee980a5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/system/displays/displays_darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ std::vector<iware::system::display_t> iware::system::displays() {
return enumerate_displays<iware::system::display_t>([](auto display_id) {
const std::uint32_t width = CGDisplayPixelsWide(display_id);
// 25.4 millimeters per inch
const std::uint32_t dpi = 25.4 * CGDisplayScreenSize(display_id).width / width;
const std::uint32_t dpi = width / (CGDisplayScreenSize(display_id).width / 25.4);

auto display_mode = CGDisplayCopyDisplayMode(display_id);
iware::detail::quickscope_wrapper display_mode_deleter{[&]() { CGDisplayModeRelease(display_mode); }};
Expand Down
2 changes: 1 addition & 1 deletion src/system/displays/displays_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ std::vector<iware::system::display_t> iware::system::displays() {
width,
static_cast<std::uint32_t>(DisplayHeight(display, screen_number)),
// 25.4 millimeters per inch
static_cast<std::uint32_t>(25.4 * DisplayWidthMM(display, screen_number) / width),
static_cast<std::uint32_t>(width / (DisplayWidthMM(display, screen_number) / 25.4)),
static_cast<std::uint32_t>(DefaultDepth(display, screen_number)),
static_cast<double>(XRRConfigCurrentRate(screen_config)),
};
Expand Down

0 comments on commit ee980a5

Please sign in to comment.