winit: `scale_factor` should not make assumptions on X11

My understanding from these docs is that scale_factor should be either defined by a system-level (i.e., not per-app) user preference (like on Windows and Wayland) or by a manufacturer-provided setting (like on most mobile devices). I don’t use macOS, but I think it also fits into one of these categories.

The docs indicate that getting scale factor on X11 systems is just irreducibly complex (though I’m curious why winit can’t just copy the approach of, for example, gtk). This leads to a multi-stage approach to getting the scale_factor, the last resort of which is the calc_dpi_factor function. This issue is specifically with that function.

As far as I understand, that function assumes that 96 dpi is the blessed “standard” which is scale_factor = 1.0, and any deviation from that results in an equivalently scaled scale_factor. I think this behaviour is unexpected and unwelcome.

As a user, I want applications to respect my scale_factor preference I set at a system level, exactly as it does on Windows for example. If the application cannot find that value for whatever reason, I don’t want it just picking its own. As a developer, I don’t want my application to arbitrarily scale itself in ways that no other application does. The WINIT_X11_SCALE_FACTOR environment variable does not help me as a developer (because if we can get a clear signal of scale factor from X11, I want to respect it) or for most users (who don’t want to set environment variables for their apps to render correctly).

If winit cannot find a clear indication of scale_factor from X11, then I strongly think it should just default to 1.0. Any scale factor that isn’t either 1.0 or what the user/manufacturer provided is surprising and will almost certainly be inconsistent with everything else. I think any other application/framework/toolkit attempts to blind reverse-engineer an appropriate scale factor. As a side benefit, this would avoid all issues like this – you don’t need to compensate for every broken xrandr configuration if you’re not basing your hack on it.

I’m happy to contribute to fixing this.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 5
  • Comments: 16 (9 by maintainers)

Most upvoted comments

But that’s the default? That’s literally not having anything set, so why would you be surprised about not having it set?

Perhaps, as an engineer that sounds plausible as a cause. As a user though, it’s complete nonsense. Just because my preference happens to be what is the default means that apps should ignore it? Of course users are going to be surprised if their apps behave differently from what appears in their settings, if you’re not surprised by this it’s because you have an abnormally deep understanding of how these settings work behind the scenes and have internalised that the behaviour is ok because there’s an explanation. No normal user would be ok with this.

Right now it cannot even be opted out

I mean that’s not correct? You can set the environment variable?

You can opt out of scaling altogether, you can’t opt-out of the weird randr-based scaling which I’m suggesting shouldn’t be happening (at least not by default) while leaving in the ability to respond to actual scaling settings.

No they’re not. DEs configurations are not the same as global configurations. If I make a change to my GTK settings I do not want my KDE applications to be affected. Same goes for winit too.

Your opinions are yours, I think this one is far from universally shared. I think the vast majority of people who see their OS has a scaling option in its settings expect that to apply to all well-behaved applications. Just like on any other platform. Why do normal users care what toolkits and libraries were used to build them? As an application developer I want my application to respect what the end user has set in their DE preferences too (anything else seems user-unfriendly). Moreover, my strong suspicion is that most OS maintainers and DE developers also want the system settings app to act as global settings for all well-behaved applications.


That discussion got in the weeds a bit, but the main point remains that winit doing this weird randr-based scaling is not consistent with my experience with other libraries and I suspect is not wanted by the vast majority of end users (both because of the lack of consistency and the lack of control they have over it).

@chrisduerr Your responses are getting more heated. I could continue to respond point-by-point, but I’m not going to any more unless I feel it’s contributing to a productive discussion on the point at hand. Please keep responses cool-headed and focussed on the my main suggestion: to change how winit behaves by default and possibly also some changes to how it can be configured to behave for the sake of better consistency and (in my opinion) less surprising behaviour for both end-users and application developers.

Perhaps, as an engineer that sounds plausible as a cause. As a user though, it’s complete nonsense. Just because my preference happens to be what is the default means that apps should ignore it?

No, that is my opinion as a user. I don’t want bullshit GTK settings to mess with the proper default locations. That is a fucking nightmare to troubleshoot and not something I’d ever want to get involved with. What’s next, someone writes a new toolkit I’ve never heard of, that is the only thing exporting DPI and I’m unable to find where it’s set because I’ve never heard of it before? That’s an absolutely ridiculous approach to take to system configuration.

No normal user would be ok with this.

How many “normal” Linux users are there exactly? 3? Maybe 4? At most.

Your opinions are yours, I think this one is far from universally shared. I think the vast majority of people who see their OS has a scaling option in its settings expect that to apply to all well-behaved applications.

That’s why DEs should set the global Xorg option. It’s up to the DE to make sure its settings are applied properly. That also usually is the case for most settings, I’m not sure about GNOME and DPI scaling. So if a DE developer wants things to apply everywhere, all they have to do is set it globally instead of for their specific toolkit. It’s literally that easy. So someone setting it just for their toolkit clearly doesn’t want it to apply globally.