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

Detect High DPI on Linux Desktop #8147

Merged
merged 2 commits into from Mar 10, 2023
Merged

Conversation

jotoft
Copy link
Contributor

@jotoft jotoft commented Feb 26, 2023

Maintainer merge checklist

  • Title is descriptive/clear for inclusion in release notes.
  • Applied a Component: xxx label.
  • Applied the api-deprecation or api-break label.
  • Applied the release-highlight label to be highlighted in release notes.
  • Added to the milestone version it was merged into.
  • Unittests are included in PR.
  • Properly documented, including 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 and KIVY_METRICS_DENSITY.
image

After patch on Linux with high DPI

DPI is correctly set to the same as X11 is configured to.
image

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.

@welcome
Copy link

welcome bot commented Feb 26, 2023

Thanks for opening your first pull request here! 💖 Please check out our contributing guidelines.

@akshayaurora akshayaurora added Component: graphics kivy/graphics Component: core-providers kivy/core Priority: High Should be fixed ASAP SDL2 SDL2 provider Platform: Linux Notes: Release-highlight Highlight this PR in the release notes. labels Mar 3, 2023
@akshayaurora akshayaurora added this to the 2.2.0 milestone Mar 3, 2023
@@ -21,7 +21,7 @@ repos:
- id: pretty-format-json
args:
- --autofix
- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

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.
@jotoft
Copy link
Contributor Author

jotoft commented Mar 6, 2023

Made the unit test tolerate a bit higher difference, that was what failed:

 FAILED kivy/tests/test_properties.py::test_numeric_string_with_units_check[True] - AssertionError: 9903.6552734375 != 9903.655700683594 within 1e-05 delta (0.00042724609375 difference)
FAILED kivy/tests/test_properties.py::test_numeric_string_with_units_check[False] - AssertionError: 9903.6552734375 != 9903.655700683594 within 1e-05 delta (0.00042724609375 difference)
= 2 failed, 848 passed, 22 skipped, 1 xfailed, 1 warning in 213.37s (0:03:33) ==
Error: Process completed with exit code 1.

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.

@jotoft jotoft requested a review from akshayaurora March 9, 2023 20:29
@akshayaurora akshayaurora merged commit f0921c2 into kivy:master Mar 10, 2023
34 checks passed
@misl6 misl6 removed Notes: Release-highlight Highlight this PR in the release notes. Component: graphics kivy/graphics labels Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants