-
-
Notifications
You must be signed in to change notification settings - Fork 790
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
Per-screen dpi override #4096
Comments
I think setting |
That's fair! If WezTerm did implement per-screen dpi overrides (🙏), could it also automatically handle font scaling so that font size at least looks consistent between screens, like it already does between macOS' 72 dpi for low density and 144 dpi for retina? The way you implemented font scaling between those two macOS dpi defaults is perfect, aside from the fact that idiots like me have non-standard 109 ppi monitors 😁 |
Allows specifying the precise dpi to use on a per-screen basis: ```lua return { dpi_by_screen = { ["Built-in Retina Display"] = 144, }, } ``` The screen names are the same as those returned from `wezterm.gui.screens()`. Changing either `dpi` or `dpi_by_screen` in the config will now cause the window to be immediately resized/adjusted to the changed dpi override. Ultimately, I'd like to deprecate `dpi` in favor of `dpi_by_screen`, but can't do that until this functionality is ported to windows, x11 and wayland. refs: #4096
I took a crack at adding a per-screen dpi override on macos; I'll work on porting this to the other environments later. local wezterm = require('wezterm')
local config = {
term = 'wezterm',
dpi_by_screen = {
['Built-in Retina Display'] = 144, -- You can omit this if you don't need to change it
['LG HDR WQHD'] = 109,
},
font = wezterm.font('JetBrains Mono'),
font_size = 16.5,
line_height = 1.2,
}
return config Those changes will show up in a nightly build within about an hour from now. Please try it out and let me know how it goes!
It should work the same; the reason wezterm cares about dpi and uses a font_size expressed in points is expressly so that the size can be consistent across different devices. The size in pixels is calculated based on the size in points and the dpi. macOS, unfortunately, does not expose the underlying dpi for its displays, instead using an abstract scaling value that is either 1 or 2 depending on whether it is "standard" or "retina" density. The scaling is applied to the macOS concept of the standard dpi for a display. The |
Maintain a cache of the positions of the various named screens, and use that to resolve the screen of the current window, and from there we can resolve the correct dpi_by_screen screen. Make dpi and dpi_by_screen config changes generate a resize event with the updated dpi. refs: #4096
Just pulled nightly and Also it seems that when I run PS. What do you think of adding |
Ultimately, I will, but until the Wayland and Windows flavors of |
What event? Please share the configuration you are using |
This is a baby step towards handling dpi_by_screen. I don't want to do the actualy per-screen stuff here; it touches stuff around the edges of SCTK and there is a pending, significant, rewrite of that code needed to upgrade to a more recent version of SCTK + wayland-protocols, and I don't want to waste my effort on the intermediate state. #3996 (comment) refs: #4096
The overrides are now applied at the window layer, which is (mostly!) aware of per-screen overrides. refs: #4096
Note that this also does not respect dpi_by_screen; this is for consistency in behavior and reported values. Once we can produce the correct overridden value in dispatch_pending_event, we can update these functions to return the same data. refs: #4096
^ Rad! 😍
wezterm.on('window-config-reloaded', function(window)
if wezterm.gui.screens().active.name == 'LG HDR WQHD' then
window:set_config_overrides({
font_size = 11
})
end
end) ...But I realize I was wrong about Also I realize my event logic there is faulty, because I'm setting the font size based on Anyway, the reason I'm even looking into this font size per screen thing is because of the font scaling issue I mentioned earlier...
Not sure screenshots alone would do justice to show what happens between multiple physical monitors, so here's a video demo (I apologize in advance for the low quality). ^ You can see there's some kind of font scaling thing happening between the inferred 144 vs 72 dpi defaults on macOS, that's behaving differently when setting dpi_by_screen explicitly. Curious on your thoughts? ❤️ |
Thanks for sharing the video; the audio was a bit low, but I appreciate hearing the explanation and seeing the effects. If setting the dpi to 109 is too big, can you try experimentally dialing it back down until you find a value that makes 16.5 points look equivalent between the screens? I'm curious to discover what the ratio is between the 109 and the actual value that looks the right size. You shouldn't need to vary the font size per-screen; that's the intended purpose of the dpi. So we should focus on what's happening with that. Could you also share the output from |
Absolutely will try those things! Also, if you feel a live pair 🍐 session might be easier (to give me things to try, with you being able to see results in realtime), I'd also be happy to do that (feel free to email me, but no pressure!). Either way, I'll dig into this more tonight hopefully and post my findings. |
Something interesting to note: macOS considers the default DPI for a normal resolution screen to be 72, but every other OS considers it to be 96. I wonder if the discrepancy you're seeing is the ratio of those numbers ( |
Gotcha, thank you for clarifying that!
Really, any dpi higher than
|
Ok, so 72 dpi, which is the default for that display, sounds like it is approx the right dpi to use. Zooming back out to the problem that you were trying to solve, I think the problem statement could be phrased as:
The pixel height calculation in wezterm is: So the two scenarios produced similar pixel sizes:
I'd suggest rearranging the math to compute the "perfect" dpi setting to use So I'd suggest using: dpi_by_screen = {
['LG HDR WQHD'] = 72.66666666666667,
} |
Oh my, this is clever! I'll roll with this for a bit and see how it goes. |
It's such an glaring eye-sore when you see it 🤮 I also found that setting |
Yep, this snippet has been the only real solution for me for me. It's pretty rare that I see it, but it still happens to the odd character 😥 -- This doesn't work well on a dual screen setup, and is hopefully a temporary solution to the font rendering oddities
-- shown in https://github.com/wez/wezterm/issues/4096. Ideally I'll switch to using `dpi_by_screen` at some point,
-- but for now 11pt @ 109dpi seems to be the most stable for font rendering on my 38" ultrawide LG monitor here.
wezterm.on('window-config-reloaded', function(window)
if wezterm.gui.screens().active.name == 'LG HDR WQHD' then
window:set_config_overrides({
dpi = 109,
font_size = 11,
})
end
end) |
What are your thoughts on per-screen config overrides for people to fix font rendering issues on screens with non-standard densities, maybe something like...
At the moment, setting a custom
dpi
affects all screens, which is undesirable when using WezTerm on multiple monitors.Setting a custom
dpi
also affects font scaling, which is why I'm suggesting the ability to configure font_size per screen along with dpi.Maybe the user also wants to set more spacious line_height on a larger screen. This would nicely allow for that as well.
Note: Ideally, this wouldn't only allow for per-screen dpi settings, but it would also change the window's dpi when dragging between screens, without the need to reboot WezTerm. At the moment, it seems setting a custom dpi doesn't take effect until you reboot WezTerm.
The reason for this feature request...
Like #3575 #3900 etc, I'm experiencing random font rendering oddities on my external LG display. From what I can tell, this is due to WezTerm's default dpi not lining up with my external monitor's physical ppi (pixels per inch).
For example, this is what I get with my external monitor at WezTerm's default dpi...
And this is what I get when I explicitly set my config to
dpi = 109
to match my monitor's physical ppi...As you can see, the font rendering is much smoother.
However, there are currently some pretty big cons to configuring an explicit
dpi
setting at the moment...When I set an explicit
dpi
in my config, I then have to reconfigure myfont_size
because the scaling will be off.When I switch to my macOS's built in retina screen, it's all wrong again. So I need some kind of conditional handling to only set custom
dpi
andfont_size
when booting WezTerm on my external monitor. I'm close with this implementation, but you can see in that discussion that there are hot reloading issues becausedpi
cannot be changed at runtime.As mentioned above, setting custom
dpi
affects all screens, so it makes for a worse experience when using WezTerm on multiple monitors / dragging between multiple monitors.For these reasons, I think per-screen config overrides as outlined above could be a pretty elegant solution to font rendering problems like this. Curious on your thoughts?
PS. Thank you @wez for all you do on this rad piece of software 💘
The text was updated successfully, but these errors were encountered: