Merge pull request #133303 from rnhmjoj/cursor

nixos/hidpi: scale X11 core cursor

authored by

Michele Guerini Rocco and committed by
GitHub
296da7b2 3f2c99d8

+50 -20
+50 -20
nixos/modules/config/fonts/fonts.nix
··· 2 2 3 3 with lib; 4 4 5 + let 6 + # A scalable variant of the X11 "core" cursor 7 + # 8 + # If not running a fancy desktop environment, the cursor is likely set to 9 + # the default `cursor.pcf` bitmap font. This is 17px wide, so it's very 10 + # small and almost invisible on 4K displays. 11 + fontcursormisc_hidpi = pkgs.xorg.fontcursormisc.overrideAttrs (old: 12 + let 13 + # The scaling constant is 230/96: the scalable `left_ptr` glyph at 14 + # about 23 points is rendered as 17px, on a 96dpi display. 15 + # Note: the XLFD font size is in decipoints. 16 + size = 2.39583 * config.services.xserver.dpi; 17 + sizeString = builtins.head (builtins.split "\\." (toString size)); 18 + in 19 + { 20 + postInstall = '' 21 + alias='cursor -xfree86-cursor-medium-r-normal--0-${sizeString}-0-0-p-0-adobe-fontspecific' 22 + echo "$alias" > $out/lib/X11/fonts/Type1/fonts.alias 23 + ''; 24 + }); 25 + 26 + hasHidpi = 27 + config.hardware.video.hidpi.enable && 28 + config.services.xserver.dpi != null; 29 + 30 + defaultFonts = 31 + [ pkgs.dejavu_fonts 32 + pkgs.freefont_ttf 33 + pkgs.gyre-fonts # TrueType substitutes for standard PostScript fonts 34 + pkgs.liberation_ttf 35 + pkgs.unifont 36 + pkgs.noto-fonts-emoji 37 + ]; 38 + 39 + defaultXFonts = 40 + [ (if hasHidpi then fontcursormisc_hidpi else pkgs.xorg.fontcursormisc) 41 + pkgs.xorg.fontmiscmisc 42 + ] ++ optionals (config.nixpkgs.config.allowUnfree or false) 43 + [ # these are unfree, and will make usage with xserver fail 44 + pkgs.xorg.fontbhlucidatypewriter100dpi 45 + pkgs.xorg.fontbhlucidatypewriter75dpi 46 + pkgs.xorg.fontbh100dpi 47 + ]; 48 + 49 + in 50 + 5 51 { 6 52 imports = [ 7 53 (mkRemovedOptionModule [ "fonts" "enableCoreFonts" ] "Use fonts.fonts = [ pkgs.corefonts ]; instead.") ··· 32 78 33 79 }; 34 80 35 - config = { 36 - 37 - fonts.fonts = mkIf config.fonts.enableDefaultFonts 38 - ([ 39 - pkgs.dejavu_fonts 40 - pkgs.freefont_ttf 41 - pkgs.gyre-fonts # TrueType substitutes for standard PostScript fonts 42 - pkgs.liberation_ttf 43 - pkgs.xorg.fontmiscmisc 44 - pkgs.xorg.fontcursormisc 45 - pkgs.unifont 46 - pkgs.noto-fonts-emoji 47 - ] ++ lib.optionals (config.nixpkgs.config.allowUnfree or false) [ 48 - # these are unfree, and will make usage with xserver fail 49 - pkgs.xorg.fontbhlucidatypewriter100dpi 50 - pkgs.xorg.fontbhlucidatypewriter75dpi 51 - pkgs.xorg.fontbh100dpi 52 - ]); 53 - 54 - }; 81 + config = mkMerge [ 82 + { fonts.fonts = mkIf config.fonts.enableDefaultFonts defaultFonts; } 83 + { fonts.fonts = mkIf config.services.xserver.enable defaultXFonts; } 84 + ]; 55 85 56 86 }