monitor crimes

This commit is contained in:
Reid 2026-04-27 19:58:15 -07:00
parent bf89ee073a
commit 97110919cd
Signed by: reidlab
GPG key ID: DAF5EAF6665839FD
2 changed files with 49 additions and 15 deletions

View file

@ -85,10 +85,13 @@
# monitors, see `modules/desktop/monitors` # monitors, see `modules/desktop/monitors`
monitors.enable = true; monitors.enable = true;
monitors.monitors = [ monitors.monitors = let
{ name = "DP-2"; scale = 1.0; } p1080 = { width = 1920; height = 1080; };
{ name = "DP-3"; scale = 2.0; vrr = true; } p2160 = { width = 3840; height = 2160; };
{ name = "HDMI-A-1"; scale = 1.0; } in [
{ name = "HDMI-A-1"; scale = 1.0; resolution = p1080; position = { x = -p1080.width; y = 0; }; }
{ name = "DP-2"; scale = 1.0; primary = true; resolution = p1080; position = { x = 0; y = 0; }; }
{ name = "DP-3"; scale = 2.0; vrr = true; resolution = p2160; position = { x = p1080.width; y = 0; }; }
]; ];
}; };
software = { software = {

View file

@ -1,33 +1,64 @@
{ lib, config, pkgs, ... }: { lib, config, pkgs, ... }:
with lib; with lib;
with lib.my;
let let
cfg = config.modules.desktop.monitors; cfg = config.modules.desktop.monitors;
in { in {
options.modules.desktop.monitors = { options.modules.desktop.monitors = {
enable = mkEnableOption "manually configure monitor settings, use if manual configuration is needed"; enable = mkEnableOption "manually configure monitor settings, use if manual configuration is needed";
monitors = mkOption { monitors = mkOption {
type = types.listOf types.attrs; type = types.listOf (types.submodule {
description = '' options = {
a list of monitor configurations. each entry should be an attribute set with the following keys: name = mkOption {
- `name`: The name of the monitor to configure type = types.str;
- `scale`: The scale factor to apply to the monitor description = "the monitor name to configure. easily fetchable from `niri msg outputs`";
- `vrr`?: Whether or not the display supports variable refresh rate. Defaults to false example = "eDP-1";
note: the first monitor in the list will be considered the "primary" monitor };
''; scale = mkOpt (types.nullOr types.float) 1.0;
vrr = mkEnableOption "whether or not to enable VRR (variable refresh rate)";
primary = mkEnableOption "whether or not the monitor is the primary monitor";
resolution = mkOpt (types.nullOr (types.submodule {
options = {
width = mkOption { type = types.int; };
height = mkOption { type = types.int; };
};
})) null;
position = mkOpt (types.nullOr (types.submodule {
options = {
x = mkOption { type = types.int; };
y = mkOption { type = types.int; };
};
})) null;
};
});
example = [ example = [
{ name = "eDP-1"; scale = 2.0; } { name = "eDP-1"; scale = 2.0; primary = true; }
{ name = "HDMI-1"; scale = 1.0; } { name = "HDMI-1"; scale = 1.0; vrr = true; }
]; ];
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [
{
assertion = builtins.length (builtins.filter (m: m.primary) cfg.monitors) <= 1;
message = "only one monitor should be marked as primary";
}
];
hm.programs.niri.settings.outputs = builtins.listToAttrs (builtins.map (monitor: { hm.programs.niri.settings.outputs = builtins.listToAttrs (builtins.map (monitor: {
name = monitor.name; name = monitor.name;
value = { value = {
scale = monitor.scale; scale = monitor.scale;
variable-refresh-rate = monitor.vrr or false; variable-refresh-rate = monitor.vrr;
focus-at-startup = monitor.primary;
position = monitor.position;
} // optionalAttrs (monitor.resolution != null) {
mode = {
width = monitor.resolution.width;
height = monitor.resolution.height;
};
}; };
}) cfg.monitors); }) cfg.monitors);
}; };