summary refs log tree commit diff
path: root/nixos/modules/config/fonts/fonts.nix
diff options
context:
space:
mode:
authorK900 <me@0upti.me>2023-03-20 21:22:22 +0300
committerRaito Bezarius <masterancpp@gmail.com>2023-03-21 13:29:57 +0100
commit4787ebf7ae2ab071389be7ff86cf38edeee7e9f8 (patch)
tree157c3e3c685894e000e08592537176bd561e34da /nixos/modules/config/fonts/fonts.nix
parent49fd723a693feb3277cad752dd56f789d071c8cf (diff)
downloadnixpkgs-4787ebf7ae2ab071389be7ff86cf38edeee7e9f8.tar
nixpkgs-4787ebf7ae2ab071389be7ff86cf38edeee7e9f8.tar.gz
nixpkgs-4787ebf7ae2ab071389be7ff86cf38edeee7e9f8.tar.bz2
nixpkgs-4787ebf7ae2ab071389be7ff86cf38edeee7e9f8.tar.lz
nixpkgs-4787ebf7ae2ab071389be7ff86cf38edeee7e9f8.tar.xz
nixpkgs-4787ebf7ae2ab071389be7ff86cf38edeee7e9f8.tar.zst
nixpkgs-4787ebf7ae2ab071389be7ff86cf38edeee7e9f8.zip
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
Diffstat (limited to 'nixos/modules/config/fonts/fonts.nix')
-rw-r--r--nixos/modules/config/fonts/fonts.nix53
1 files changed, 23 insertions, 30 deletions
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";
+      };
+    })
   ];
 
 }