Skip to content

Streamline DPI settings #25892

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 1 commit into from
Aug 20, 2021
Merged

Streamline DPI settings #25892

merged 1 commit into from
Aug 20, 2021

Conversation

abbradar
Copy link
Member

Motivation for this change

Currently we use it to set default X fonts DPI equal to screen DPI. It's needed
to make GTK3 use system DPI: #25023.

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Several questions that arise because of this patch:

  1. Currently we have fonts.fontconfig.dpi and services.xserver.dpi options. Are there any cases where they can differ? Maybe we want to drop one of them to make this uniform?
  2. What option should take priority? I'm not sure what happens if we have one default DPI in fontconfig and one in /etc/X11/Xresources.

Sorry, something went wrong.

@abbradar abbradar added 2.status: work-in-progress This PR isn't done 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels May 18, 2017
@mention-bot
Copy link

@abbradar, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @aszlig and @nbp to be potential reviewers.

@vcunat
Copy link
Member

vcunat commented May 18, 2017

I don't think it's meaningful to have multiple DPI settings. Perhaps have just one nixos option and change the rest into alias names.

@abbradar
Copy link
Member Author

Pushed fixed version -- I cherry-picked from the wrong branch, sorry.

@vcunat My thoughts too. There are also other usecases for DPI value (for example perhaps console fonts). IMHO more generic name of those two is fonts.fontconfig.dpi (at least it's about fonts, not about X server). I'll prepare the patch.

@vcunat
Copy link
Member

vcunat commented May 18, 2017

Hmm, choosing the default console font depending on DPI... that would be possible, maybe even not too magical.

@abbradar
Copy link
Member Author

abbradar commented May 18, 2017

@vcunat I expect something like:

listOfFonts :: [(DPI, FontName)]

snd (last (takeUntil (\(dpi, _) -> dpi > cfg.dpi) listOfFonts))

BTW while reading docs on -dpi option I discovered that it has the highest priority of all DPI settings -- i.e. it overrides DPI settings in xorg.conf and also overrides what the monitor says itself. Perhaps it's not a good idea to set it from fonts.fontconfig.dpi after all; instead let's advise to use it only when DPI is not detected properly.

I'm still going deeper in the rabbit hole of Linux DPI settings and want to write up a small overview when finished...

@abbradar
Copy link
Member Author

abbradar commented May 18, 2017

So, to sum up what I found out:

There are three distinct sources of DPI information on Linux: fontconfig, Xresources (Xft.dpi) and Xrandr. Xrandr information is also exposed via DisplayHeight/DisplayHeightMM. Xresources may be screen-specific. fontconfig is a separate source which is normally used on per-font basis.

  • GTK2 uses Xresources and falls back to DisplayHeight API. I read through the source code a bit and it seems that GTK2 is not only multi-monitor-aware but actually uses monitor settings for the monitor it considers its "main". I'm not yet sure if that's not just always the primary monitor; I'll experiment a bit later;
  • GTK3 used to follow GTK2's route but recently stopped using DisplayHeight as per firefox: Not respecting 'services.xserver.dpi' after moving to GTK3 #25023;
  • Qt 5 uses Xft.dpi and falls back to Xrandr (much like GTK2 but using a differnet API). They mention that they consider DPI forced when Xft.dpi is set. That seems reasonable to me;
  • libXft also uses settings from fontconfig on per-font basis and if nothing is set uses just the same code GTK2 has to calculate DPI using DisplayHeight API;

There are many other places I haven't examined; for example setting DPI in xfce4-appearance-settings magically resizes fonts in all applications -- I'm not yet sure how that works (not via Xresources or Xrandr at least).

Also notice that we already set Xft.dpi from fonts.fontconfig.dpi value globally (for all screens).

Overall it seems to me that we should promote usage of Xrandr/Xresources with this:

  1. Revert GTK 3 patch that stops usage of DisplayHeight API;
  2. Explicitly mention that services.xserver.dpi is only for overriding invalid monitor DPI and encourage to add Monitor sections instead or use xrandr -dpi;
  3. Discourage usage of fonts.fontconfig.dpi as a last resort option; one should set proper DPI per monitor instead.

cc @rbasso as one who may be knowledgeable about DPI -- maybe you have something to add/correct?

@abbradar
Copy link
Member Author

Also cc @ttuegel as the current fontconfig person :D

@ttuegel
Copy link
Member

ttuegel commented May 18, 2017

Currently we have fonts.fontconfig.dpi and services.xserver.dpi options. Are there any cases where they can differ? Maybe we want to drop one of them to make this uniform?

Ouch! We should drop fonts.fontconfig.dpi because that is not a font-specific setting. The Fontconfig files we generate can just use the DPI from services.xserver.dpi if that is set.

@abbradar
Copy link
Member Author

@ttuegel Yeah, after more thought I think we should just merge them (but also recommend people to set proper DPI for their monitors instead and not use that option). I'll prepare the patch a bit later.

@abbradar abbradar force-pushed the xresources branch 2 times, most recently from b9e718a to c724830 Compare May 24, 2017 14:29
@abbradar abbradar changed the title xserver service: add global Xresources file Streamline DPI settings May 24, 2017
@abbradar
Copy link
Member Author

abbradar commented May 24, 2017

I've pushed the second version of the patchset which implements what we've outlined above:

  1. Revert GTK3 patch which breaks DPI autodetection;
  2. Add global Xresources option (for convenience);
  3. Drop DPI settings from fontconfig (rename the option; also don't set dpi options in fontconfig configuration at all -- it should use Xft values by default);
  4. Set Xft.dpi when services.xserver.dpi is set;
  5. Mention in the documentation that one is recommended to avoid services.xserver.dpi if possible (it forces the same value for all monitors).

@abbradar abbradar added 0.kind: enhancement Add something new and removed 2.status: work-in-progress This PR isn't done labels Jun 3, 2017
@abbradar
Copy link
Member Author

abbradar commented Jun 3, 2017

So, any comments on this? I'm not completely sure all changes are a good idea.

@lheckemann
Copy link
Member

I like all the changes — just one thing to add, which is that I think the X resources should be loaded before user sessions to make sure that they apply to the display manager too. I'm not sure if there's a way to do that in one place for all the display managers, considering that (AFAIU) it's the display manager's responsibility to start the X server.

@abbradar
Copy link
Member Author

abbradar commented Jun 7, 2017

@lheckemann Actually I wanted to do it this very way but I don't know if it's even possible :D IIUC this would require some kind of support in a display manager.

@lheckemann
Copy link
Member

I suppose that's just another reason not to recommend the setting, preferring instead Monitor sections. I approve of the changes overall, for what my opinion's worth :)

@abbradar
Copy link
Member Author

abbradar commented Jun 7, 2017

Hm, actually we need to test that DPI works properly with display managers. It should be, but still... I'll do this tomorrow if noone beats me.

@ttuegel
Copy link
Member

ttuegel commented Jun 7, 2017

I'm not sure if there's a way to do that in one place for all the display managers, considering that (AFAIU) it's the display manager's responsibility to start the X server.

I can't speak for other display managers, but SDDM allows to specify a script to setup the X server. At the moment, I think we use the default script shipped by upstream, but we could easily change that. I don't know what other display managers do, but I expect something similar because each distribution has different requirements for starting the server.

I suppose that's just another reason not to recommend the setting, preferring instead Monitor sections.

Is there a way to set individual Monitor sections in NixOS? I was not aware of this. If that is so, I would strongly recommend doing that instead of overriding DPI for the whole server. From the perspective of font rendering, using a DPI that does not match the display is likely to produce really horrible results.

@lheckemann
Copy link
Member

Between services.xserver.monitorSection and services.xserver.config, it is indeed possible to specify arbitrary Monitor sections.

@abbradar
Copy link
Member Author

Argh, sorry, life got into the way and I delayed this greatly. DPI and monitor sections seem to work with display managers. As for X resources -- can we somehow load them in our X wrapper? I haven't immediately found a way to do that.

@lheckemann
Copy link
Member

*bump*

AFAICT, we don't have an X wrapper. I think that it would be nice to get this change merged, even if it doesn't affect the display manager in all cases yet.

@samueldr
Copy link
Member

This will need a release-notes update for the NixOS revision it lands into. If done quickly, and there are no objections, this could land in 18.09 I imagine.

If I understand this correctly; part of the PR is already included in master since November 2017, we're left with the removal of the font-specific DPI hacks, right?

If so, I (personally) think this can be merged 👍 (once release notes written, or arrangements to write them are made).

@mmahut
Copy link
Member

mmahut commented Aug 7, 2019

Any updates on this pull request, please?

@abbradar
Copy link
Member Author

abbradar commented Aug 9, 2019

Ah, completely forgot about this one. I'll do a writeup for the release notes and then it should be ready.

@roosemberth
Copy link
Contributor

@abbradar Could you please rebase your PR and add an entry to the next release notes https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2003.xml ?

@prusnak
Copy link
Member

prusnak commented May 9, 2020

@abbradar Ping?

@ryantm ryantm added 2.status: merge conflict This PR has merge conflicts with the target branch and removed 2.status: merge conflict This PR has merge conflicts with the target branch labels Oct 3, 2020
@stale
Copy link

stale bot commented Jun 7, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 7, 2021
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 7, 2021
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 7, 2021
@github-actions github-actions bot added 8.has: changelog 8.has: documentation This PR adds or changes documentation labels Aug 7, 2021
@Ericson2314
Copy link
Member

This is a good old PR I forgot about and found. Rebased and added release notes.

@ofborg ofborg bot added 10.rebuild-linux: 1-10 and removed 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Aug 7, 2021
@roberth
Copy link
Member

roberth commented Aug 8, 2021

@Ericson2314 there was a conflict in the release notes. Inserting in a random place mitigates those, fwiw.

@Ericson2314
Copy link
Member

OK, let the merge conflict guide me to that random spot :D

Recommend to use services.xserver.dpi option instead. Mention in the
documentation that it's a sledgehammer approach and monitor settings should be
used instead.

Also don't set DPI in fontconfig settings; fontconfig should use Xft settings
by default so let's not override one value in multiple places. For example,
user now can set DPI via ~/.Xresources properly.
@Ericson2314 Ericson2314 merged commit 3efbe38 into NixOS:master Aug 20, 2021
@SomeoneSerge
Copy link
Contributor

I just updated from 21.05 and found that fonts.fontconfig.dpi was removed and that I leapfrogged over the deprecation warning:)
Somehow, fonts.fontconfig.dpi was the only option I found on my laptop to get a consistent dpi across all of gtk, qt, and lightdm system-wide on my laptop (without the need for a dozen of variables like GDK_SCALE or need for per-user Xresources). Using services.xserver.dpi instead gets the correct scale in e.g. alacritty, but scales things down in e.g. firefox.

Meanwhile, I also have DisplaySize set in xrandrHeads, but it doesn't help

ivanbrennan added a commit to ivanbrennan/nixbox that referenced this pull request Jan 17, 2022
The fonts.fontconfig.dpi option was removed, which caused alacritty to
display a huge font size. Add this setting back into Xresources.

There may be more to doing this properly, but this works for now.

NixOS/nixpkgs#25892
alacritty/alacritty#1339
ivanbrennan added a commit to ivanbrennan/nixbox that referenced this pull request Apr 30, 2023
The fonts.fontconfig.dpi option was removed, which caused alacritty to
display a huge font size. Add this setting back into Xresources.

There may be more to doing this properly, but this works for now.

NixOS/nixpkgs#25892
alacritty/alacritty#1339
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: enhancement Add something new 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 9.needs: documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet