Skip to content

Commit ce73f9b

Browse files
committed
hm-mod: monitors: support freeform options
The `monitors` definitions can now support variables defined here: <https://wiki.hypr.land/Configuring/Monitors/#monitor-v2> FIXME: There's a problem with using `freeformType` and `mkRenamedOptionModule` in the same submodule type: because any arbitrary attributes are accepted by the `freeformType`, the renamed option warnings will never be triggered, and never shown. However, the old attribute will still automatically be replaced by the new one.
1 parent a6bbdf6 commit ce73f9b

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

hm-module/monitors.nix

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ let
6868
(lib.mkRenamedOptionModule [ "disabled" ] [ "disable" ])
6969
];
7070

71+
# Other attributes may be specified for `monitorv2`, you can find them
72+
# here: <https://wiki.hypr.land/Configuring/Monitors/#monitor-v2>
73+
freeformType = with types; attrsOf (oneOf [ bool number ]);
74+
7175
options = {
7276
output = lib.mkOption {
7377
type = types.singleLineStr;
@@ -271,6 +275,16 @@ in {
271275
The "output" the monitor will have (the connector, not make and model)
272276
is specified in the `output` attribute for the monitor.
273277
It is not the attribute name of the monitor in *this* parent set.
278+
279+
The submodule type for monitor definitions is not exhaustive of all
280+
variables supported by Hyprland. For that reason, the submodule
281+
is also freeform; you may specify arbitrary attributes,
282+
and they will be serialized verbatim to the Hyprland configuration.
283+
284+
For a list of extra variables not exposed as submodule options,
285+
see the [`monitorv2` section] on the Hyprland wiki.
286+
287+
[`monitorv2 section`]: https://wiki.hypr.land/Configuring/Monitors/#monitor-v2
274288
'';
275289
example = lib.literalExpression ''
276290
(with config.wayland.windowManager.hyprland.monitors; {
@@ -286,19 +300,26 @@ in {
286300
};
287301
};
288302

289-
config = {
303+
config = let
304+
monitorDefOptions = lib.attrNames
305+
(removeAttrs (monitorDefType.getSubOptions [ ]) [
306+
"_freeformOptions"
307+
"_module"
308+
]);
309+
in {
290310
wayland.windowManager.hyprland.config.monitorv2 = lib.mapAttrsToList
291-
(_: def: {
292-
inherit (def) output;
293-
disabled = lib.mkIf def.disable def.disable;
294-
mode = def.modeString;
295-
position = def.positionString;
296-
scale = lib.mkIf (def.scale != 1.0) def.scale;
297-
vrr = lib.mkIf (def.vrrMode != null) def.vrrMode;
298-
bitdepth = lib.mkIf (def.bitdepth != 8) def.bitdepth;
299-
transform = let default = transformEnum.mapping."Normal";
300-
in lib.mkIf (def.transform != default) def.transform;
301-
mirror = lib.mkIf (def.mirror != null) def.mirror;
302-
}) cfg;
311+
(_: def:
312+
{
313+
inherit (def) output;
314+
disabled = lib.mkIf def.disable def.disable;
315+
mode = def.modeString;
316+
position = def.positionString;
317+
scale = lib.mkIf (def.scale != 1.0) def.scale;
318+
vrr = lib.mkIf (def.vrrMode != null) def.vrrMode;
319+
bitdepth = lib.mkIf (def.bitdepth != 8) def.bitdepth;
320+
transform = let default = transformEnum.mapping."Normal";
321+
in lib.mkIf (def.transform != default) def.transform;
322+
mirror = lib.mkIf (def.mirror != null) def.mirror;
323+
} // removeAttrs def monitorDefOptions) cfg;
303324
};
304325
}

0 commit comments

Comments
 (0)