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
Detect High DPI on Linux Desktop #8147
Conversation
Thanks for opening your first pull request here! 💖 Please check out our contributing guidelines. |
@@ -21,7 +21,7 @@ repos: | |||
- id: pretty-format-json | |||
args: | |||
- --autofix | |||
- repo: https://gitlab.com/pycqa/flake8 | |||
- repo: https://github.com/pycqa/flake8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a more generic change. Would you please do a separate pr for such changes.
Atomic prs that limit themself to just one specific topic are a boon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will split it out into its own PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped this part from this PR now. Will check on the unit test failure.
0b9aaf1
to
574bb57
Compare
If higher than normal DPI is configured using `KIVY_DPI` or other means then the density of the screen is higher and this should be reflected in the density. This will make the density calculation on linux the same as Windows and macOS. Unit test change: Use almost equal in density property unit tests Since the density is a floating point number, the tests can fail if the calculated value is slightly rounded.
Use [SDL_GetDisplayDPI](https://wiki.libsdl.org/SDL2/SDL_GetDisplayDPI) to get the display DPI if no high DPI was detected using the method described in the warning for the SDL_GetDisplayDPI function (which is the current method for guessing the DPI). If the X server is configured with the DPI of the display then this GetDisplayDPI method returns the correct DPI on Linux.
574bb57
to
8e75624
Compare
Made the unit test tolerate a bit higher difference, that was what failed:
Changed the tolerance to 1E-2 instead. They pass at 1E-3 here but realistically it is not really important that they have to be this accurate, and would rather be a bit lenient here to avoid confusion. |
Maintainer merge checklist
Component: xxx
label.api-deprecation
orapi-break
label.release-highlight
label to be highlighted in release notes.versionadded
,versionchanged
as needed.Before patch on Linux with high DPI
Scaling is not working unless setting the DPI and density manually using the environment variables
KIVY_DPI
andKIVY_METRICS_DENSITY
.After patch on Linux with high DPI
DPI is correctly set to the same as X11 is configured to.
Implementation
The DPI can be found using this SDL function SDL_GetDisplayDPI.
The warning suggests using another method, which is the one already used in
kivy/core/window/window_sdl2.py
This other method I think only really works for macOS and IOS with retina displays.
So, if we are on a desktop and this method fails, then try to get the DPI using the SDL function and if that does not work we use the default of 96. Which will yield a density of 1.0 when density is calculated on Linux (with 74b866d) as well as the other desktop OSes.