summaryrefslogtreecommitdiff
path: root/modules/hyprland/monitor.nix
blob: ef3f227e6f4ec95af7f2350149273ccba213b5e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{ config, lib, ... }:
let
cfg = config.hyprland.monitors;
in
{
	imports = [ ../waybar ];

	options.hyprland.monitors =
		with lib;
	mkOption {
		description = "Hyprland Monitor Configuration";
		type = types.attrsOf (
				types.submodule {
				options = {
				resolution = mkOption {
				description = "Monitor Resolution";
				type = types.strMatching "[:digit:]+x[:digit:]+|preferred";
				default = "preferred";
				};
				position = mkOption {
				description = "Monitor Position";
				type = types.strMatching "-?[:digit:]+x-?[:digit:]+|auto";
				default = "auto";
				};
				scale = mkOption {
				description = "Monitor Scale";
				type = types.numbers.positive;
				default = 1;
				};
				mirror = mkOption {
					description = "Mirror Monitor";
					type = types.submodule {
						options = {
							enable = mkOption {
								description = "Enable Mirroring";
								type = types.bool;
								default = false;
							};
							monitor = mkOption {
								description = "Mirror Monitor Name";
								type = types.str;
								default = "";
							};
						};
					};
					default = { enable = false; };
				};
				transform = mkOption {
				description = "Hyprland Monitor Transform";
				type = types.submodule {
					options = {
						flipped = mkOption {
							description = "Hyprland Flip Monitor";
							type = types.bool;
							default = false;
						};
						rotation = mkOption {
							description = "Hyprland Monitor Rotation";
							type = types.enum [
								0
									90
									180
									270
							];
							default = 0;
						};
					};
				};
				default = {
					flipped = false;
					rotation = 0;
				};
				};
				bar = mkOption {
					description = "Waybar Settings";
					type = types.submodule {
						options = {
							enable = mkOption {
								description = "Enable Waybar for this Monitor";
								type = types.bool;
								default = false;
							};
						};
					};
					default = {
						enable = false;
					};
				};
				};
				}
		);
		default = {
			default = { };
		};
	};

	config = {
		home-manager.users.n8.wayland.windowManager.hyprland.settings.monitor =
			lib.attrsets.mapAttrsToList
			(
			 name: value:
			 "${if name == "default" then "" else name},${value.resolution},"
			 + "${value.position},"
			 + "${toString value.scale},"
			 + "transform,"
			 + "${toString ((value.transform.rotation / 90) + (if value.transform.flipped then 4 else 0))}"
			 + (if value.mirror.enable then ",mirror," + value.mirror.monitor else "")
			)
			cfg;

		bar = builtins.map (m: m.name) (
				builtins.filter (m: m.enable) (
					lib.attrsets.mapAttrsToList (name: value: {
						name = name;
						enable = value.bar.enable;
						}) cfg
					)
				);
	};
}