nix-git/modules/gnome-fractional-scaling.nix

83 lines
3.8 KiB
Nix
Raw Normal View History

2023-09-18 21:49:26 +02:00
{ config, pkgs, lib, ... }:
2024-02-01 20:58:53 +01:00
let
version = "45.3";
in
2023-09-06 19:29:51 +02:00
{
# https://wiki.archlinux.org/title/HiDPI#Wayland
# Results in blurry font in non-Wayland applications :/
2023-09-07 13:47:44 +02:00
# https://wiki.archlinux.org/title/HiDPI#Xorg
2024-02-12 17:19:44 +01:00
# https://devicetests.com/set-different-scaling-multi-monitors-gnome
# "scale-monitor-framebuffer": This allows GNOME to scale each monitors framebuffer independently, which is necessary for per-monitor scaling.
# "x11-randr-fractional-scaling": This allows fractional scaling, which gives you finer control over the scaling factor.
# TODO open issue: Fractional scaling can't be enabled with multiple monitors.
# https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/2076
# https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/2365
# -> https://bugs.launchpad.net/ubuntu/+source/gnome-control-center/+bug/2008355
2023-09-06 19:29:51 +02:00
programs.dconf.enable = true;
2023-09-07 13:47:44 +02:00
# Overlays.
# https://nixos.wiki/wiki/Overlays#In_NixOS
2023-09-07 21:48:23 +02:00
# https://discourse.nixos.org/t/use-specific-pkg-version-in-overlay/32741/3
2023-09-18 21:49:26 +02:00
# If on X11, then use patched version of mutter.
nixpkgs.overlays = lib.mkIf (! config.services.xserver.displayManager.gdm.wayland) [
2023-09-07 13:47:44 +02:00
(
2023-09-07 13:54:37 +02:00
# Patched version of mutter 44.2.
2023-09-07 13:47:44 +02:00
# Outdated example: https://nixos.wiki/wiki/Overlays#Overriding_a_package_inside_a_scope
#
# On the AUR, they apply only one patch, not three.
# And they pick the patch that corresponds to the mutter version.
# https://aur.archlinux.org/packages/mutter-x11-scaling
#
# New patch URL:
# -> https://salsa.debian.org/gnome-team/mutter/-/blob/ubuntu/master/debian/patches/ubuntu/x11-Add-support-for-fractional-scaling-using-Randr.patch
# For release 44.2:
# -> https://salsa.debian.org/gnome-team/mutter/-/tags?sort=updated_desc&search=ubuntu%2F
# -> https://salsa.debian.org/gnome-team/mutter/-/tags/ubuntu%2F44.2-3ubuntu1
# -> https://salsa.debian.org/gnome-team/mutter/-/raw/ubuntu/44.2-3ubuntu1/debian/patches/ubuntu/x11-Add-support-for-fractional-scaling-using-Randr.patch
2024-02-01 20:58:53 +01:00
# For release 45.3:
# -> https://salsa.debian.org/gnome-team/mutter/-/tags?sort=updated_desc&search=ubuntu%2F
# -> https://salsa.debian.org/gnome-team/mutter/-/tags/ubuntu%2F45.3-1ubuntu1
# -> https://salsa.debian.org/gnome-team/mutter/-/raw/ubuntu/45.3-1ubuntu1/debian/patches/ubuntu/x11-Add-support-for-fractional-scaling-using-Randr.patch
2023-09-07 13:47:44 +02:00
# Elements of nixpkgs must be taken from final and prev.
final: prev: {
# Elements of pkgs.gnome must be taken from gfinal and gprev.
gnome = prev.gnome.overrideScope' (gfinal: gprev: {
2023-09-07 21:48:23 +02:00
mutter = gprev.mutter.overrideAttrs (oldAttrs:
2024-02-01 20:58:53 +01:00
if oldAttrs.version == version then
2023-09-07 21:48:23 +02:00
{
patches = (oldAttrs.patches or []) ++ [
(prev.fetchpatch {
2024-02-01 20:58:53 +01:00
url = "https://salsa.debian.org/gnome-team/mutter/-/raw/ubuntu/${version}-1ubuntu1/debian/patches/ubuntu/x11-Add-support-for-fractional-scaling-using-Randr.patch";
2023-09-07 21:48:23 +02:00
# Determining the hash: https://github.com/NixOS/nixpkgs/issues/191128#issuecomment-1246030431
2024-02-01 20:58:53 +01:00
hash = "sha256-snEgCuTsTEo0wQ5XsjEM53K2j7l4ZQ3t9FT3+Yfoti0=";
2023-09-07 21:48:23 +02:00
})
];
}
2024-02-01 20:58:53 +01:00
else throw "Mutter version mismatch. Please update patch. ${oldAttrs.version}"
2023-09-07 21:48:23 +02:00
);
2023-09-07 13:47:44 +02:00
});
}
)
];
2023-09-06 19:29:51 +02:00
home-manager.users.yoda = { osConfig, config, pkgs, ... }: {
dconf.settings = {
"org/gnome/mutter" = {
2024-02-12 17:19:44 +01:00
experimental-features = (
if (osConfig.services.xserver.displayManager.gdm.wayland)
# Wayland
then ["scale-monitor-framebuffer"]
# X11
else ["scale-monitor-framebuffer" "x11-randr-fractional-scaling"]
);
2023-09-06 19:29:51 +02:00
};
};
};
}