From 4787ebf7ae2ab071389be7ff86cf38edeee7e9f8 Mon Sep 17 00:00:00 2001 From: K900 Date: Mon, 20 Mar 2023 21:22:22 +0300 Subject: nixos/hidpi: remove The single option tries to do too much work, which just ends up confusing people. So: - don't force the console font, the kernel can figure this out as of #210205 - don't force the systemd-boot mode, it's an awkward mode that's not supported on most things and will break flicker-free boot - add a separate option for the xorg cursor scaling trick and move it under the xorg namespace - add a general `fonts.optimizeForVeryHighDPI` option that explicitly says what it does - alias the old option to that - don't set any of those automatically in nixos-generate-config --- nixos/modules/config/fonts/fonts.nix | 53 ++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'nixos/modules/config') diff --git a/nixos/modules/config/fonts/fonts.nix b/nixos/modules/config/fonts/fonts.nix index c0619fa31a3..efbd554582f 100644 --- a/nixos/modules/config/fonts/fonts.nix +++ b/nixos/modules/config/fonts/fonts.nix @@ -3,29 +3,7 @@ with lib; let - # A scalable variant of the X11 "core" cursor - # - # If not running a fancy desktop environment, the cursor is likely set to - # the default `cursor.pcf` bitmap font. This is 17px wide, so it's very - # small and almost invisible on 4K displays. - fontcursormisc_hidpi = pkgs.xorg.fontxfree86type1.overrideAttrs (old: - let - # The scaling constant is 230/96: the scalable `left_ptr` glyph at - # about 23 points is rendered as 17px, on a 96dpi display. - # Note: the XLFD font size is in decipoints. - size = 2.39583 * config.services.xserver.dpi; - sizeString = builtins.head (builtins.split "\\." (toString size)); - in - { - postInstall = '' - alias='cursor -xfree86-cursor-medium-r-normal--0-${sizeString}-0-0-p-0-adobe-fontspecific' - echo "$alias" > $out/lib/X11/fonts/Type1/fonts.alias - ''; - }); - - hasHidpi = - config.hardware.video.hidpi.enable && - config.services.xserver.dpi != null; + cfg = config.fonts; defaultFonts = [ pkgs.dejavu_fonts @@ -36,16 +14,12 @@ let pkgs.noto-fonts-emoji ]; - defaultXFonts = - [ (if hasHidpi then fontcursormisc_hidpi else pkgs.xorg.fontcursormisc) - pkgs.xorg.fontmiscmisc - ]; - in { imports = [ (mkRemovedOptionModule [ "fonts" "enableCoreFonts" ] "Use fonts.fonts = [ pkgs.corefonts ]; instead.") + (mkRenamedOptionModule [ "hardware" "video" "hidpi" "enable" ] [ "fonts" "optimizeForVeryHighDPI" ]) ]; options = { @@ -69,13 +43,32 @@ in ''; }; + optimizeForVeryHighDPI = mkOption { + type = types.bool; + default = false; + description = lib.mdDoc '' + Optimize configuration for very high-density (>200 DPI) displays: + - disable subpixel anti-aliasing + - disable hinting + - automatically upscale the default X11 cursor + ''; + }; }; }; config = mkMerge [ - { fonts.fonts = mkIf config.fonts.enableDefaultFonts defaultFonts; } - { fonts.fonts = mkIf config.services.xserver.enable defaultXFonts; } + { fonts.fonts = mkIf cfg.enableDefaultFonts defaultFonts; } + (mkIf cfg.optimizeForVeryHighDPI { + services.xserver.upscaleDefaultCursor = mkDefault true; + # Conforms to the recommendation in fonts/fontconfig.nix + # for > 200DPI. + fonts.fontconfig = { + antialias = mkDefault false; + hinting.enable = mkDefault false; + subpixel.lcdfilter = mkDefault "none"; + }; + }) ]; } -- cgit 1.4.1