Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call XCloseDisplay in screenScalingFactor #204

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ float screenScalingFactor()
// todo(anyone) set device pixel ratio for high dpi displays on Windows
float ratio = 1.0;
#ifdef __linux__
Display *disp = XOpenDisplay(nullptr);
char *resourceString = XResourceManagerString(disp);
auto closeDisplay = [](Display * display)
{
if (display)
XCloseDisplay(display);
};
auto display =
std::unique_ptr<Display, decltype(closeDisplay)>(
XOpenDisplay(nullptr), closeDisplay);
char *resourceString = XResourceManagerString(display.get());

if (resourceString)
{
Expand Down Expand Up @@ -68,8 +75,8 @@ float screenScalingFactor()
// We can use either the width or height in the following line. The zero
// values in DisplayHeight and DisplayHeightMM is the screen number. A
// value of zero uses the default screen.
float yDpiRes = (DisplayHeight(disp, 0) * 25.4) /
DisplayHeightMM(disp, 0);
float yDpiRes = (DisplayHeight(display.get(), 0) * 25.4) /
DisplayHeightMM(display.get(), 0);

if (!math::equal(dpiDesktop, 0.0f) && !math::equal(yDpiRes, 0.0f))
ratio = dpiDesktop / yDpiRes;
Expand Down