82 lines
1.9 KiB
Nix
82 lines
1.9 KiB
Nix
{ user }: { lib, pkgs, config, ... }:
|
|
with lib;
|
|
let
|
|
cfg = config.displays;
|
|
|
|
renderDisplaysForHyprland = displays:
|
|
"# === DISPLAY MODULE ===\n"
|
|
+ concatStringsSep "\n" (map displayHyprlandSetting displays);
|
|
|
|
displayHyprlandSetting = display:
|
|
"monitor = " + display.name +
|
|
", " + resToString display.resolution +
|
|
", " + display.position +
|
|
", " + toString display.scaling;
|
|
|
|
resolutionType = types.submodule ({ x, y, freq, ... }:
|
|
{
|
|
options = {
|
|
x = mkOption {
|
|
description = "x";
|
|
type = types.int;
|
|
default = 0;
|
|
};
|
|
y = mkOption {
|
|
description = "y";
|
|
type = types.int;
|
|
default = 0;
|
|
};
|
|
freq = mkOption {
|
|
description = "frequency";
|
|
type = types.int;
|
|
default = 0;
|
|
};
|
|
};
|
|
});
|
|
displayType = types.submodule
|
|
({ ... }: {
|
|
options = {
|
|
name = mkOption {
|
|
description = "name of the display";
|
|
};
|
|
scaling = mkOption {
|
|
type = types.float;
|
|
default = 1.0;
|
|
};
|
|
resolution = mkOption {
|
|
description = "res";
|
|
type = resolutionType;
|
|
default = { };
|
|
};
|
|
position = mkOption {
|
|
description = "XxY";
|
|
default = "auto";
|
|
};
|
|
};
|
|
});
|
|
|
|
resToString = res:
|
|
if res.x == 0 || res.y == 0 || res.freq == 0
|
|
then "preferred"
|
|
else "${toString res.x}x${toString res.y}@${toString res.freq}";
|
|
in
|
|
{
|
|
options.displays =
|
|
{
|
|
enable = mkEnableOption "manage displays";
|
|
displays = mkOption {
|
|
type = types.listOf displayType;
|
|
default = [ ];
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
home-manager.users.${user}.imports = [
|
|
{
|
|
wayland.windowManager.hyprland.extraConfig = mkIf (cfg.displays != [ ])
|
|
(renderDisplaysForHyprland cfg.displays);
|
|
}
|
|
];
|
|
};
|
|
}
|
|
|