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

HighDPI issues on linux #65

Closed
mgerhardy opened this issue Jul 2, 2020 · 11 comments
Closed

HighDPI issues on linux #65

mgerhardy opened this issue Jul 2, 2020 · 11 comments

Comments

@mgerhardy
Copy link

it's not possible to use the profiler on my laptop's screen resolution (3840x2160).

@mgerhardy
Copy link
Author

Screenshot from 2020-07-02 16-26-19

@mgerhardy
Copy link
Author

Screenshot from 2020-07-02 16-27-10

@wolfpld
Copy link
Owner

wolfpld commented Jul 2, 2020

You can set an appropriate dpiScale in profiler/src/main.cpp. Ideally this should be retrieved from the system.

@mgerhardy
Copy link
Author

Shouldn't glfwGetMonitorContentScale help here cross platform? According to the docs it should:

Will give it a try and let you know.

@mgerhardy
Copy link
Author

mgerhardy commented Jul 3, 2020

Something like this - unfortunately I can't test this as I currently only have glfw 3.2 - I first to build a newer version.

diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp
index 2485ead7..73ddedc1 100644
--- a/profiler/src/main.cpp
+++ b/profiler/src/main.cpp
@@ -242,6 +242,14 @@ int main( int argc, char** argv )
     gl3wInit();
     glfwSetWindowRefreshCallback( window, WindowRefreshCallback );
 
+#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3)
+    GLFWmonitor* monitor = glfwGetWindowMonitor(window);
+    if (monitor == nullptr) {
+        monitor = glfwGetPrimaryMonitor();
+    }
+    if (monitor != nullptr) {
+        float xscale, yscale;
+        glfwGetMonitorContentScale(monitor, &xscale, &yscale);
+        dpiScale = xscale > yscale ? xscale : yscale;
+    }
+#else
 #ifdef _WIN32
     typedef UINT(*GDFS)(void);
     GDFS getDpiForSystem = nullptr;
@@ -250,6 +258,7 @@ int main( int argc, char** argv )
         getDpiForSystem = (GDFS)GetProcAddress(dll, "GetDpiForSystem");
     if (getDpiForSystem)
         dpiScale = getDpiForSystem() / 96.f;
+#endif
 #endif
 
     // Setup ImGui binding

@mgerhardy
Copy link
Author

tested the above now - works quite nice now. Not sure which version of glfw you are targeting for. But if 3.3 is the min version - one can also remove the checks and the win32 code.

@mgerhardy
Copy link
Author

I suppose I have to add the glfwGetPrimaryMonitor call, because the window is not yet initialized properly at that point. I think it would be better to move the dpiScale assignment after the window init. Looks like creating the window is not enough here.

@wolfpld
Copy link
Owner

wolfpld commented Jul 3, 2020

glfwGetWindowMonitor doesn't do what you think it does (see docs). You'd need to enumerate available monitors (glfwGetMonitors) to detect on which monitor the window will be displayed, taking into account the possibility that monitor configuration might have changed since last run, and the saved window coordinates could have been adjusted by the window manager (or not at all, placing the window out-of-view, who knows).

Then you have trouble with multiple monitors with different DPI settings, but this problem is already present right now (not on Windows, which scale the window-contents bitmap to match the target monitor DPI). Proper fix would be needed to be done on ImGui side, I believe @ocornut has it in the works.

@mgerhardy
Copy link
Author

But it should at least do the (almost) same as the win32 specific code, no? I know that it doesn't deal with the edge cases.

At least it fixes the problem for me in a way, that renders the profiler's ui readable.

@mgerhardy
Copy link
Author

Or maybe provide a way to override the dpi scale factor with an env var? at least as a workaround...

@wolfpld
Copy link
Owner

wolfpld commented Sep 20, 2020

Implemented as proposed in 5abd4c8.

@wolfpld wolfpld closed this as completed Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants