-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add HiDPI support in GTK. #20988
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
Add HiDPI support in GTK. #20988
Conversation
c72d331
to
8cf7bab
Compare
On gtk3agg/X11, I now get
Removing the instance and param args makes things work. On gtk3cairo the image is crisp, but too large and cropped out of the window. On gtk4agg, _update_device_pixel_ratio still seems never called. |
Oops, sorry, juggling multiple machines to test this, and must have got some things crossed. What versions of GTK3 & GTK4 are you using? |
3.24.30/4.4.0. |
Ah sorry, it's not versions; I just keep forgetting to test with the X11 backend. Agg should work now. I totally forgot, and should have mentioned initially, that I had no idea how to get this working with Cairo. In other Cairo backends, we draw to an image surface, and blit it to the backend's widget. Unlike those backends, here we render directly to the GTK cairo context. I can fake this a bit with some scaling and translation, but the line width, text size, etc. are then smaller than they should be. But I just realized that QtCairo is wrong the same way, so this might be fine as a stopgap in the meantime. |
OK, this should now "work" for Cairo as well in that the canvas is not giant and clipped. However, there is a bug across all Cairo backends with HiDPI not rendering elements at the correct size, for which I will open a separate issue. Also, GTK3Cairo on X11 (but not Wayland) is broken for me and doesn't open any windows. This appears unrelated to this change. |
This mostly works for me now; there's only one single issue left (again, always on X11 and always on environment-variable simulated high-dpi): the initial window size on gtk3 (not on gtk4) is too large (scaled by the dpi factor, I think). |
I think that might be bugginess in GTK. We get |
To be honest that last point is a bit beyond my pay grade (or rather beyond the pay grade of my screen) but the rest looks good to me. |
Well, to be clear, it's the same in GTK4, the |
Hah, actually, I take that back; it is our bug. Grabbing the pixel ratio earlier meant that the DPI was updated before the window itself was created. And the initial window size calculation uses the physical size instead of the logical size. |
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.
Yup, that works :)
It is deprecated since GTK 3.8, and event compression occurs in other ways which don't seem relevant to us.
Otherwise, if the pixel ratio is changed before the window is created, the window will be scaled up an extra time. This occurs on GTK3, but not GTK4, due to some different order of events, but I changed the GTK4 backend to do the same for consistency.
@QuLogic can self merge on rebase and green. |
…988-on-v3.5.x Backport PR #20988 on branch v3.5.x (Add HiDPI support in GTK.)
PR Summary
I had this written for GTK3 some time ago, but was waiting for GTK4 to go in so I could add that in as well. Mostly the same as Qt, but linking to the GTK version of events, etc.
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).