Skip to content

Support fractional HiDPI in GTK4 backend #30344

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

Merged
merged 2 commits into from
Jul 24, 2025

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 23, 2025

PR summary

Since GTK 4.12, fractional HiDPI is handled, but with a separate property on the backing surface due to it being a different type.

PR checklist

scale = surface.get_scale()
else:
scale = self.get_scale_factor()
if scale is not None and self._set_device_pixel_ratio(scale):
Copy link
Member

Choose a reason for hiding this comment

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

When can scale be None? I'd expect that this is rather a RuntimeError and should generally not happen.

Copy link
Member

Choose a reason for hiding this comment

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

I suspect there is some funnyness with hidden / minimized / offscreen / not drawn yet windows in the _GTK_GE_4_12 branch where there may not be a defined scale yet (because they have not been put on the screen yet).

Copy link
Member

Choose a reason for hiding this comment

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

Would it be better in that case to fall back to self.get_scale_factor() rather than doing nothing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to avoid issues if native or surface were not set yet, but it seems like this function only ends up being called after the widget is realized, so the window surface should always exist. The only other caller is the resize event, but that can obviously only happen with a window to resize...

So I guess I can just drop all the conditions, as I can't so far get it to fail.

Since GTK 4.12, fractional HiDPI is handled, but with a separate
property on the backing surface due to it being a different type.
@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Jul 24, 2025
@QuLogic
Copy link
Member Author

QuLogic commented Jul 24, 2025

Also pushed a fix for these warnings from the GTK4 examples:

matplotlib/galleries/examples/user_interfaces/embedding_in_gtk4_sgskip.py:42: DeprecationWarning: Gtk.Widget.show is deprecated
  win.show()

matplotlib/galleries/examples/user_interfaces/embedding_in_gtk4_panzoom_sgskip.py:47: DeprecationWarning: Gtk.Widget.show is deprecated
  win.show()

@tacaswell tacaswell added this to the v3.10.4 milestone Jul 24, 2025
@tacaswell tacaswell merged commit 3444f0f into matplotlib:main Jul 24, 2025
39 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jul 24, 2025
@QuLogic QuLogic deleted the gtk4-fractional branch July 24, 2025 18:37
ksunden added a commit that referenced this pull request Jul 25, 2025
…344-on-v3.10.x

Backport PR #30344 on branch v3.10.x (Support fractional HiDPI in GTK4 backend)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: examples files in galleries/examples GUI: gtk
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy