diff options
author | Michele Guerini Rocco <rnhmjoj@users.noreply.github.com> | 2021-08-25 21:07:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-25 21:07:47 +0200 |
commit | 296da7b2f843a385bbc655070c77e28bcf915d61 (patch) | |
tree | 0f3c86c9ba7e85897b9a01165bc17fbcf8cde42c /nixos/modules/config | |
parent | 3f2c99d8a1c668991f4d92bc1815741e72c34ec4 (diff) | |
parent | dd38ae1f2c0ae9eb53a3454b0633c2b29f14a0ef (diff) | |
download | nixpkgs-296da7b2f843a385bbc655070c77e28bcf915d61.tar nixpkgs-296da7b2f843a385bbc655070c77e28bcf915d61.tar.gz nixpkgs-296da7b2f843a385bbc655070c77e28bcf915d61.tar.bz2 nixpkgs-296da7b2f843a385bbc655070c77e28bcf915d61.tar.lz nixpkgs-296da7b2f843a385bbc655070c77e28bcf915d61.tar.xz nixpkgs-296da7b2f843a385bbc655070c77e28bcf915d61.tar.zst nixpkgs-296da7b2f843a385bbc655070c77e28bcf915d61.zip |
Merge pull request #133303 from rnhmjoj/cursor
nixos/hidpi: scale X11 core cursor
Diffstat (limited to 'nixos/modules/config')
-rw-r--r-- | nixos/modules/config/fonts/fonts.nix | 70 |
1 files changed, 50 insertions, 20 deletions
diff --git a/nixos/modules/config/fonts/fonts.nix b/nixos/modules/config/fonts/fonts.nix index 3911196c101..60a0885103d 100644 --- a/nixos/modules/config/fonts/fonts.nix +++ b/nixos/modules/config/fonts/fonts.nix @@ -2,6 +2,52 @@ 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.fontcursormisc.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; + + defaultFonts = + [ pkgs.dejavu_fonts + pkgs.freefont_ttf + pkgs.gyre-fonts # TrueType substitutes for standard PostScript fonts + pkgs.liberation_ttf + pkgs.unifont + pkgs.noto-fonts-emoji + ]; + + defaultXFonts = + [ (if hasHidpi then fontcursormisc_hidpi else pkgs.xorg.fontcursormisc) + pkgs.xorg.fontmiscmisc + ] ++ optionals (config.nixpkgs.config.allowUnfree or false) + [ # these are unfree, and will make usage with xserver fail + pkgs.xorg.fontbhlucidatypewriter100dpi + pkgs.xorg.fontbhlucidatypewriter75dpi + pkgs.xorg.fontbh100dpi + ]; + +in + { imports = [ (mkRemovedOptionModule [ "fonts" "enableCoreFonts" ] "Use fonts.fonts = [ pkgs.corefonts ]; instead.") @@ -32,25 +78,9 @@ with lib; }; - config = { - - fonts.fonts = mkIf config.fonts.enableDefaultFonts - ([ - pkgs.dejavu_fonts - pkgs.freefont_ttf - pkgs.gyre-fonts # TrueType substitutes for standard PostScript fonts - pkgs.liberation_ttf - pkgs.xorg.fontmiscmisc - pkgs.xorg.fontcursormisc - pkgs.unifont - pkgs.noto-fonts-emoji - ] ++ lib.optionals (config.nixpkgs.config.allowUnfree or false) [ - # these are unfree, and will make usage with xserver fail - pkgs.xorg.fontbhlucidatypewriter100dpi - pkgs.xorg.fontbhlucidatypewriter75dpi - pkgs.xorg.fontbh100dpi - ]); - - }; + config = mkMerge [ + { fonts.fonts = mkIf config.fonts.enableDefaultFonts defaultFonts; } + { fonts.fonts = mkIf config.services.xserver.enable defaultXFonts; } + ]; } |