3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #222236 from K900/bye-dpi

nixos/hidpi: remove
This commit is contained in:
Ryan Lahfa 2023-03-21 15:04:59 +01:00 committed by GitHub
commit 06541976aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 80 deletions

View file

@ -248,10 +248,10 @@ In addition to numerous new and upgraded packages, this release has the followin
[headscale's example configuration](https://github.com/juanfont/headscale/blob/main/config-example.yaml)
can be directly written as attribute-set in Nix within this option.
- `hardware.video.hidpi` now provides defaults that are consistent with `fontconfig`'s documentation:
- antialiasing and font hinting are disabled, as they have no visible effects at high pixel densities;
- subpixel order isn't set: it was irrelevant with the above disabled, and the module *cannot* know the correct
setting for the user's screen.
- The `hardware.video.hidpi.enable` was renamed to `fonts.optimizeForVeryHighDPI` to be consistent with what it actually does.
They disable by default: antialiasing, hinting and LCD filter for subpixel rendering. They can be overridden if you experience problems with font rendering.
On Xorg, the default cursor is upscaled.
Please see the documentation for the new option to decide if you want to keep it enabled.
- `nixos/lib/make-disk-image.nix` can now mutate EFI variables, run user-provided EFI firmware or variable templates. This is now extensively documented in the NixOS manual.

View file

@ -46,13 +46,11 @@ in
font = mkOption {
type = with types; nullOr (either str path);
default = "Lat2-Terminus16";
default = null;
example = "LatArCyrHeb-16";
description = mdDoc ''
The font used for the virtual consoles. Leave empty to use
whatever the {command}`setfont` program considers the
default font.
Can be either a font name or a path to a PSF font file.
The font used for the virtual consoles.
Can be `null`, a font name, or a path to a PSF font file.
Use `null` to let the kernel choose a built-in font.
The default is 8x16, and, as of Linux 5.3, Terminus 32 bold for display

View file

@ -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";
};
})
];
}

View file

@ -1,25 +0,0 @@
{ lib, pkgs, config, ...}:
with lib;
{
options.hardware.video.hidpi.enable = mkEnableOption (lib.mdDoc "Font/DPI configuration optimized for HiDPI displays");
config = mkIf config.hardware.video.hidpi.enable {
console.font = lib.mkDefault "${pkgs.terminus_font}/share/consolefonts/ter-v32n.psf.gz";
# Needed when typing in passwords for full disk encryption
console.earlySetup = mkDefault true;
boot.loader.systemd-boot.consoleMode = mkDefault "1";
# Disable font anti-aliasing, hinting, and sub-pixel rendering by default
# See recommendations in fonts/fontconfig.nix
fonts.fontconfig = {
antialias = mkDefault false;
hinting.enable = mkDefault false;
subpixel.lcdfilter = mkDefault "none";
};
# TODO Find reasonable defaults X11 & wayland
};
}

View file

@ -518,21 +518,6 @@ EOF
}
}
# For lack of a better way to determine it, guess whether we should use a
# bigger font for the console from the display mode on the first
# framebuffer. A way based on the physical size/actual DPI reported by
# the monitor would be nice, but I don't know how to do this without X :)
my $fb_modes_file = "/sys/class/graphics/fb0/modes";
if (-f $fb_modes_file && -r $fb_modes_file) {
my $modes = read_file($fb_modes_file);
$modes =~ m/([0-9]+)x([0-9]+)/;
my $console_width = $1, my $console_height = $2;
if ($console_width > 1920) {
push @attrs, "# high-resolution display";
push @attrs, 'hardware.video.hidpi.enable = lib.mkDefault true;';
}
}
# Generate the hardware configuration file.

View file

@ -95,7 +95,6 @@
./hardware/video/bumblebee.nix
./hardware/video/capture/mwprocapture.nix
./hardware/video/displaylink.nix
./hardware/video/hidpi.nix
./hardware/video/nvidia.nix
./hardware/video/switcheroo-control.nix
./hardware/video/uvcvideo/default.nix

View file

@ -138,6 +138,26 @@ let
concatMapStringsSep "\n" (line: prefix + line) (splitString "\n" str);
indent = prefixStringLines " ";
# 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 * cfg.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
'';
});
in
{
@ -576,6 +596,15 @@ in
Whether to terminate X upon server reset.
'';
};
upscaleDefaultCursor = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Upscale the default X cursor to be more visible on high-density displays.
Requires `config.services.xserver.dpi` to be set.
'';
};
};
};
@ -627,6 +656,10 @@ in
+ "${toString (length primaryHeads)} heads set to primary: "
+ concatMapStringsSep ", " (x: x.output) primaryHeads;
})
{
assertion = cfg.upscaleDefaultCursor -> cfg.dpi != null;
message = "Specify `config.services.xserver.dpi` to upscale the default cursor.";
}
];
environment.etc =
@ -851,6 +884,10 @@ in
'';
fonts.enableDefaultFonts = mkDefault true;
fonts.fonts = [
(if cfg.upscaleDefaultCursor then fontcursormisc_hidpi else pkgs.xorg.fontcursormisc)
pkgs.xorg.fontmiscmisc
];
};