From 727b783f96f0c16e98b8e3124f921a94f8a75fc2 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Wed, 28 Aug 2024 11:48:41 +0200 Subject: [PATCH] land.nix: switch monitor map for independent system configs --- hosts/vali/hermit/hardware/monitors.nix | 12 +++++------- modules/options/system/monitors.nix | 20 +++++--------------- modules/wms/wayland/hypr/land.nix | 21 ++++++++++++++++----- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/hosts/vali/hermit/hardware/monitors.nix b/hosts/vali/hermit/hardware/monitors.nix index 09f3a5a..b65241a 100644 --- a/hosts/vali/hermit/hardware/monitors.nix +++ b/hosts/vali/hermit/hardware/monitors.nix @@ -1,18 +1,16 @@ _: { - modules.system.hardware.monitors = [ - { - name = "Integrated laptop screen"; - device = "eDP-1"; + modules.system.hardware.monitors = { + eDP-1 = { resolution = { x = 1920; y = 1080; }; scale = 1; - refresh_rate = 60; + refreshRate = 60; position = { x = 0; y = 0; }; - } - ]; + }; + }; } diff --git a/modules/options/system/monitors.nix b/modules/options/system/monitors.nix index 5c73292..78d5fe8 100644 --- a/modules/options/system/monitors.nix +++ b/modules/options/system/monitors.nix @@ -1,22 +1,12 @@ {lib, ...}: let inherit (lib) mkOption; - inherit (lib.types) str submodule int ints number listOf; + inherit (lib.types) str submodule int ints number attrsOf listOf; in { - options.modules.system.monitors = mkOption { + options.modules.system.hardware.monitors = mkOption { description = "\n List of monitors to use\n "; - default = []; - type = listOf (submodule { + default = {}; + type = attrsOf (submodule { options = { - name = mkOption { - type = str; - description = "Give your monitor a cute name"; - default = ""; - }; - device = mkOption { - type = str; - description = "The actual device name of the monitor"; - default = "eDP-1"; - }; resolution = mkOption { type = submodule { options = { @@ -38,7 +28,7 @@ in { description = "monitor scale"; default = 1.0; }; - refresh_rate = mkOption { + refreshRate = mkOption { type = int; description = "monitor refresh rate (in Hz)"; default = 60; diff --git a/modules/wms/wayland/hypr/land.nix b/modules/wms/wayland/hypr/land.nix index aede6df..66c13ce 100644 --- a/modules/wms/wayland/hypr/land.nix +++ b/modules/wms/wayland/hypr/land.nix @@ -8,13 +8,13 @@ cfg = config.modules.usrEnv.desktops.hyprland; inherit (config.modules.other.system) username; inherit (config.modules.style) cursor; - inherit (config.modules.hardware) monitors; + inherit (config.modules.system.hardware) monitors; inherit (inputs'.split-monitor-workspaces.packages) split-monitor-workspaces ; - inherit (lib) mkIf mkDefault; + inherit (lib) flatten mkIf mkDefault mapAttrsToList; inherit (builtins) toString; in { config = mkIf cfg.enable { @@ -68,11 +68,22 @@ in { # "Unknown-1,disable" # ]; + # Thanks Poz for inspiration, using an attrset is actually much smarter + # than using a normal list. monitor = - map ( - m: "${m.device},${toString m.resolution.x}x${toString m.resolution.y}@${toString m.refresh_rate},${toString m.position.x}x${toString m.position.y},${toString m.scale},transform,${toString m.transform}" + mapAttrsToList ( + name: m: let + w = toString m.resolution.x; + h = toString m.resolution.y; + refreshRate = toString m.refreshRate; + x = toString m.position.x; + y = toString m.position.y; + scale = toString m.scale; + in "${name},${w}x${h}@${refreshRate},${x}x${y},${scale}" ) - monitors; #TODO: default value + monitors; + + workspace = flatten () # Workspace config workspace = [